From c69b5426532ad2e5d563fc6e212bbcd9c5e8e42f Mon Sep 17 00:00:00 2001 From: dreistein Date: Sat, 27 Jan 2024 21:36:46 +0100 Subject: [PATCH] Refactor `chesspp` module with pyproject --- main.py | 9 ++++----- pyproject.toml | 13 +++++++++++++ {chesspp => src}/__init__.py | 0 src/chesspp/__init__.py | 0 {chesspp => src/chesspp}/classic_mcts.py | 6 ++++-- {chesspp => src/chesspp}/engine.py | 3 ++- {chesspp => src/chesspp}/eval.py | 0 {chesspp => src/chesspp}/i_mcts.py | 2 +- {chesspp => src/chesspp}/i_strategy.py | 0 {chesspp => src/chesspp}/lichess-engine.py | 3 ++- {chesspp => src/chesspp}/simulation.py | 2 +- {chesspp => src/chesspp}/util.py | 0 12 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 pyproject.toml rename {chesspp => src}/__init__.py (100%) create mode 100644 src/chesspp/__init__.py rename {chesspp => src/chesspp}/classic_mcts.py (98%) rename {chesspp => src/chesspp}/engine.py (97%) rename {chesspp => src/chesspp}/eval.py (100%) rename {chesspp => src/chesspp}/i_mcts.py (96%) rename {chesspp => src/chesspp}/i_strategy.py (100%) rename {chesspp => src/chesspp}/lichess-engine.py (96%) rename {chesspp => src/chesspp}/simulation.py (98%) rename {chesspp => src/chesspp}/util.py (100%) diff --git a/main.py b/main.py index 2b85e3b..2c69204 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,10 @@ import chess import chess.engine import chess.pgn -from chesspp.classic_mcts import ClassicMcts -from chesspp import engine -from chesspp import eval -from chesspp import util -from chesspp import simulation +from src.chesspp.classic_mcts import ClassicMcts +from src.chesspp import engine +from src.chesspp import util +from src.chesspp import simulation, eval def test_simulate(): diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..bb9e713 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[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", +] +requires-python = ">= 3.10" diff --git a/chesspp/__init__.py b/src/__init__.py similarity index 100% rename from chesspp/__init__.py rename to src/__init__.py diff --git a/src/chesspp/__init__.py b/src/chesspp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/chesspp/classic_mcts.py b/src/chesspp/classic_mcts.py similarity index 98% rename from chesspp/classic_mcts.py rename to src/chesspp/classic_mcts.py index 70d8e4a..46ff5f3 100644 --- a/chesspp/classic_mcts.py +++ b/src/chesspp/classic_mcts.py @@ -1,10 +1,12 @@ import chess import random -import eval -import util import numpy as np +from chesspp import eval +from chesspp import util + + class ClassicMcts: def __init__(self, board: chess.Board, color: chess.Color, parent=None, move: chess.Move | None = None, diff --git a/chesspp/engine.py b/src/chesspp/engine.py similarity index 97% rename from chesspp/engine.py rename to src/chesspp/engine.py index 0c09956..42e42f9 100644 --- a/chesspp/engine.py +++ b/src/chesspp/engine.py @@ -1,9 +1,10 @@ from abc import ABC, abstractmethod import chess import chess.engine -from classic_mcts import ClassicMcts import random +from chesspp.classic_mcts import ClassicMcts + class Engine(ABC): color: chess.Color diff --git a/chesspp/eval.py b/src/chesspp/eval.py similarity index 100% rename from chesspp/eval.py rename to src/chesspp/eval.py diff --git a/chesspp/i_mcts.py b/src/chesspp/i_mcts.py similarity index 96% rename from chesspp/i_mcts.py rename to src/chesspp/i_mcts.py index 99d1dcb..4293744 100644 --- a/chesspp/i_mcts.py +++ b/src/chesspp/i_mcts.py @@ -1,7 +1,7 @@ import chess from abc import ABC, abstractmethod -from i_strategy import IStrategy from typing import Dict +from chesspp.i_strategy import IStrategy class IMcts(ABC): diff --git a/chesspp/i_strategy.py b/src/chesspp/i_strategy.py similarity index 100% rename from chesspp/i_strategy.py rename to src/chesspp/i_strategy.py diff --git a/chesspp/lichess-engine.py b/src/chesspp/lichess-engine.py similarity index 96% rename from chesspp/lichess-engine.py rename to src/chesspp/lichess-engine.py index d5dbffd..e2d3b93 100644 --- a/chesspp/lichess-engine.py +++ b/src/chesspp/lichess-engine.py @@ -1,6 +1,7 @@ from lichess_bot.lib.engine_wrapper import MinimalEngine, MOVE import chess.engine -import engine + +from chesspp import engine class ProbStockfish(MinimalEngine): diff --git a/chesspp/simulation.py b/src/chesspp/simulation.py similarity index 98% rename from chesspp/simulation.py rename to src/chesspp/simulation.py index 61d7b75..0deb8b0 100644 --- a/chesspp/simulation.py +++ b/src/chesspp/simulation.py @@ -6,7 +6,7 @@ from typing import Tuple, List from enum import Enum from dataclasses import dataclass -from engine import Engine +from chesspp.engine import Engine class Winner(Enum): diff --git a/chesspp/util.py b/src/chesspp/util.py similarity index 100% rename from chesspp/util.py rename to src/chesspp/util.py