From 92d06bd2a072f1eacda9094350aca4ac2edbbae5 Mon Sep 17 00:00:00 2001 From: luk3k Date: Wed, 31 Jan 2024 23:32:45 +0100 Subject: [PATCH] configured lichess bot to use our bayesian mcts with Stockfish strategy --- lichess_bot/lib/strategies.py | 29 +++++++++++++++++++++++------ pyproject.toml | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 pyproject.toml diff --git a/lichess_bot/lib/strategies.py b/lichess_bot/lib/strategies.py index 86b5ea9..5c815b3 100644 --- a/lichess_bot/lib/strategies.py +++ b/lichess_bot/lib/strategies.py @@ -13,7 +13,8 @@ from typing import Any import logging import chesspp -from chesspp.engine import ClassicMctsEngine, BayesMctsEngine +from chesspp.engine import ClassicMctsEngine, Engine +from chesspp.engine_factory import EngineFactory, EngineEnum, StrategyEnum # 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. @@ -128,11 +129,27 @@ class MctsEngine(MinimalEngine): class MyBayesMctsEngine(MinimalEngine): + def __init__(self, commands: COMMANDS_TYPE, options: OPTIONS_TYPE, stderr: Optional[int], + draw_or_resign: Configuration, name: Optional[str] = None, **popen_args: str) -> None: + """ + Initialize the values of the engine that all homemade engines inherit. + + :param options: The options to send to the engine. + :param draw_or_resign: Options on whether the bot should resign or offer draws. + """ + super().__init__(commands, options, stderr, draw_or_resign, name, **popen_args) + self._engine = None + + def get_engine(self, color: chess.Color) -> chess.engine: + if self._engine is None: + self._engine = EngineFactory.create_engine(EngineEnum.BayesianMcts, StrategyEnum.Stockfish, color, + "/home/luke/projects/pp-project/chess-engine-pp/stockfish/stockfish-ubuntu-x86-64-avx2", + "", 1500, 4) + + return self._engine + def search(self, board: chess.Board, time_limit: chess.engine.Limit, ponder: bool, draw_offered: bool, root_moves: MOVE) -> chess.engine.PlayResult: - my_engine = BayesMctsEngine(board.turn) - r = my_engine.play(board.copy(), chesspp.engine.Limit(0.5)) - print("Color:", board.turn) - print("engine play result: ", r) - print("Engine name", my_engine) + my_engine = self.get_engine(board.turn) + r = my_engine.play(board.copy(), chesspp.engine.Limit(2)) return r diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..361f818 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,20 @@ +[build-system] +requires = ["setuptools >= 61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "chess-pp" +version = "0.1" +dependencies = [ + "chess==1.10.0", + "numpy==1.26.3", + "stockfish==3.28.0", + "torch==2.1.2", + "pytest==8.0.0", + "aiohttp==3.9.2", + "scipy==1.12.0" +] +requires-python = ">= 3.10" + +[tool.setuptools] +py-modules = ["chesspp"]