Implemented strategy evaluation for moves and improved scoring for BayesMcts

This commit is contained in:
2024-01-29 17:47:00 +01:00
parent c5536e08de
commit d43899ecda
11 changed files with 68 additions and 36 deletions

View File

@@ -1,15 +1,21 @@
import os
import chess
from chesspp.i_strategy import IStrategy
from chesspp.eval import score_stockfish
import chess.engine
_DIR = os.path.abspath(os.path.dirname(__file__))
class StockFishStrategy(IStrategy):
def __init__(self):
self._stockfish = None
def __del__(self):
if self._stockfish is not None:
self._stockfish.quit()
@property
def stockfish(self) -> chess.engine.SimpleEngine:
if self._stockfish is None:
@@ -22,6 +28,7 @@ class StockFishStrategy(IStrategy):
self._stockfish = stockfish
def pick_next_move(self, board: chess.Board) -> chess.Move | None:
move = self.stockfish.play(board, chess.engine.Limit(depth=4)).move
print("stockfish picked:", move)
return move
return self.stockfish.play(board, chess.engine.Limit(depth=4)).move
def analyze_board(self, board: chess.Board) -> int:
return score_stockfish(board, self.stockfish)