added base classes for mcts and strategy
This commit is contained in:
@@ -12,6 +12,7 @@ from lib.engine_wrapper import MinimalEngine, MOVE
|
||||
from typing import Any
|
||||
import logging
|
||||
|
||||
from engines import engine
|
||||
|
||||
# Use this logger variable to print messages to the console or log files.
|
||||
# logger.info("message") will always print "message" to the console or log file.
|
||||
@@ -93,3 +94,22 @@ class ComboEngine(ExampleEngine):
|
||||
possible_moves.sort(key=str)
|
||||
move = possible_moves[0]
|
||||
return PlayResult(move, None, draw_offered=draw_offered)
|
||||
|
||||
|
||||
class ProbStockfish(MinimalEngine):
|
||||
def search(self, board: chess.Board, time_limit: chess.engine.Limit, ponder: bool, draw_offered: bool,
|
||||
root_moves: MOVE) -> chess.engine.PlayResult:
|
||||
moves = {}
|
||||
untried_moves = list(board.legal_moves)
|
||||
for move in untried_moves:
|
||||
mean, std = engine.simulate_stockfish_prob(board.copy(), move, 10, 2)
|
||||
moves[move] = (mean, std)
|
||||
if mean == 100_000 and std == 0:
|
||||
return chess.engine.PlayResult(move, None)
|
||||
|
||||
return self.get_best_move(moves)
|
||||
|
||||
def get_best_move(self, moves: dict) -> chess.engine.PlayResult:
|
||||
best_avg = max(moves.items(), key=lambda m: m[1][0])
|
||||
next_move = best_avg[0]
|
||||
return chess.engine.PlayResult(next_move, None)
|
||||
|
||||
Reference in New Issue
Block a user