From 1613e7fe0cc700f44353af0433f9c90f568f8e94 Mon Sep 17 00:00:00 2001 From: Joseph Lou Date: Thu, 8 Jun 2023 21:41:37 -0700 Subject: [PATCH] Release v2.0.0 --- Changelog.md | 8 +++++ README.md | 11 ++----- pyproject.toml | 2 +- src/alicechess/__init__.py | 8 ++--- src/alicechess/__main__.py | 4 +-- src/alicechess/__version__.py | 2 +- ...ves_calculator.py => _moves_calculator.py} | 6 ++-- src/alicechess/bots.py | 15 ++++++--- src/alicechess/game.py | 11 +++++-- src/alicechess/game_state.py | 12 +++---- src/alicechess/pieces/__init__.py | 31 +++++++++---------- src/alicechess/pieces/king.py | 5 ++- src/alicechess/pieces/pawn.py | 5 ++- src/alicechess/pieces/piece.py | 4 +-- src/alicechess/player.py | 16 +++++----- src/alicechess/position.py | 2 +- src/alicechess/test.py | 11 ------- src/alicechess/window.py | 14 ++++++--- 18 files changed, 84 insertions(+), 83 deletions(-) rename src/alicechess/{moves_calculator.py => _moves_calculator.py} (98%) delete mode 100644 src/alicechess/test.py diff --git a/Changelog.md b/Changelog.md index 570dccf..693f374 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,13 @@ # Changelog +## v2.0.0 + +_2023-06-08 21:42_ + +- Removed test file (wasn't supposed to be published) +- Added `__all__` tuples to each file +- Added absolute imports (previous version wasn't event working) + ## v1.0.1 _2023-06-08 21:15_ diff --git a/README.md b/README.md index 26eb42e..14eb018 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This project allows you to play Alice Chess, a variant of chess. -## Installastion +## Installation The package may be installed through `pip`: @@ -91,17 +91,10 @@ methods for making a move and promoting a pawn. This class (not an instance) can then be passed into the `Game` constructor to start a game. See the [API Documentation][docs] for more information. -## Advanced Usage - -The only dependency for this project is `Pillow` to use the images in the -interactive window. As such, you could technically clone the repository and run -it without the window with only the Python builtins. Not sure why you would want -to do that, but that is another alternative option to installing through `pip`. +[docs]: https://github.com/josephlou5/alicechess/blob/main/Documentation.md ## Credit Thank you to Artyom Lisitsyn for inspiring me to pursue this project and to Trung Phan for being my chess consultant and answering all my questions on rules and technicalities. - -[docs]: https://github.com/josephlou5/alicechess/blob/main/Documentation.md diff --git a/pyproject.toml b/pyproject.toml index 3179e92..9d05288 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ line_length = 79 [tool.poetry] name = "alicechess" -version = "1.0.1" +version = "2.0.0" description = "A Python package to play Alice Chess" authors = ["Joseph Lou "] license = "MIT License" diff --git a/src/alicechess/__init__.py b/src/alicechess/__init__.py index cae42e2..57bc1ad 100644 --- a/src/alicechess/__init__.py +++ b/src/alicechess/__init__.py @@ -2,7 +2,7 @@ Alice Chess. """ -from game import Game -from game_state import GameState -from player import HumanPlayer, Player -from utils import Color, PieceType, PromoteType +from alicechess.game import Game +from alicechess.game_state import GameState +from alicechess.player import HumanPlayer, Player +from alicechess.utils import Color, PieceType, PromoteType diff --git a/src/alicechess/__main__.py b/src/alicechess/__main__.py index c44cb1e..88a99b4 100644 --- a/src/alicechess/__main__.py +++ b/src/alicechess/__main__.py @@ -4,8 +4,8 @@ # ====================================================================== -from game import Game -from player import HumanPlayer +from alicechess.game import Game +from alicechess.player import HumanPlayer # ====================================================================== diff --git a/src/alicechess/__version__.py b/src/alicechess/__version__.py index ad48fcd..f65de0f 100644 --- a/src/alicechess/__version__.py +++ b/src/alicechess/__version__.py @@ -2,4 +2,4 @@ Version for `alicechess` package. """ -__version__ = "1.0.1" +__version__ = "2.0.0" diff --git a/src/alicechess/moves_calculator.py b/src/alicechess/_moves_calculator.py similarity index 98% rename from src/alicechess/moves_calculator.py rename to src/alicechess/_moves_calculator.py index 7fe0eb5..2013f20 100644 --- a/src/alicechess/moves_calculator.py +++ b/src/alicechess/_moves_calculator.py @@ -7,9 +7,9 @@ from functools import partial from typing import Dict, Iterator, List, Optional, Sequence, Tuple -from pieces import King, Pawn, Piece, Rook -from position import BoardPosition, Position -from utils import Color, PieceType, check_brc, check_brc_bool +from alicechess.pieces import King, Pawn, Piece, Rook +from alicechess.position import BoardPosition, Position +from alicechess.utils import Color, PieceType, check_brc, check_brc_bool # ============================================================================= diff --git a/src/alicechess/bots.py b/src/alicechess/bots.py index 27fed5e..fd126b5 100644 --- a/src/alicechess/bots.py +++ b/src/alicechess/bots.py @@ -7,10 +7,17 @@ import random from typing import Dict -from game_state import GameState -from player import Player -from position import Move -from utils import PieceType, PromoteType +from alicechess.game_state import GameState +from alicechess.player import Player +from alicechess.position import Move +from alicechess.utils import PieceType, PromoteType + +# ============================================================================= + +__all__ = ( + "RandomPlayer", + "PrioritizedRandomPlayer", +) # ============================================================================= diff --git a/src/alicechess/game.py b/src/alicechess/game.py index 402f043..97e166a 100644 --- a/src/alicechess/game.py +++ b/src/alicechess/game.py @@ -6,8 +6,12 @@ from typing import Type -from game_state import GameState -from player import AnyPlayer, _PlayerBase +from alicechess.game_state import GameState +from alicechess.player import AnyPlayer, _PlayerBase + +# ============================================================================= + +__all__ = ("Game",) # ============================================================================= @@ -49,7 +53,8 @@ def start_window(self, **kwargs): """ # import here so that games that don't use the window don't need # to be run in a virtual environment (requires Pillow) - from window import Window # pylint: disable=import-outside-toplevel + # pylint: disable=import-outside-toplevel + from alicechess.window import Window game_state = self.new() window = Window(game_state, **kwargs) diff --git a/src/alicechess/game_state.py b/src/alicechess/game_state.py index 02188ee..07263d2 100644 --- a/src/alicechess/game_state.py +++ b/src/alicechess/game_state.py @@ -8,12 +8,12 @@ from itertools import count, zip_longest from typing import Dict, Iterable, Iterator, Optional, Self, Type -import pieces -from moves_calculator import BoardDict, MovesCalculator -from pieces import Piece, make_promoted -from player import AnyPlayer -from position import Move, PieceMove, PieceMoved, Position -from utils import Color, EndGameState, PieceType, PromoteType +from alicechess import pieces +from alicechess._moves_calculator import BoardDict, MovesCalculator +from alicechess.pieces import Piece, make_promoted +from alicechess.player import AnyPlayer +from alicechess.position import Move, PieceMove, PieceMoved, Position +from alicechess.utils import Color, EndGameState, PieceType, PromoteType # ============================================================================= diff --git a/src/alicechess/pieces/__init__.py b/src/alicechess/pieces/__init__.py index f916bdc..7cfd21d 100644 --- a/src/alicechess/pieces/__init__.py +++ b/src/alicechess/pieces/__init__.py @@ -6,13 +6,10 @@ import typing as _t -from utils import Color as _Color -from utils import PieceType as _PieceType -from utils import PromoteType as _PromoteType - -from .king import King -from .pawn import Pawn -from .piece import Piece +from alicechess.pieces.king import King +from alicechess.pieces.pawn import Pawn +from alicechess.pieces.piece import Piece +from alicechess.utils import Color, PieceType, PromoteType # ============================================================================= @@ -40,7 +37,7 @@ class Subclass(Piece): def _check_start_position(self) -> bool: if self._pos.bn != 0: return False - if self._color is _Color.WHITE: + if self._color is Color.WHITE: row = rows[0] else: row = rows[1] @@ -58,22 +55,22 @@ def _check_start_position(self) -> bool: # queen is always on the left for this particular board setup -Queen = _make_simple_piece(_PieceType.QUEEN, (7, 0), (3,)) -Rook = _make_simple_piece(_PieceType.ROOK, (7, 0), (0, 7)) -Knight = _make_simple_piece(_PieceType.KNIGHT, (7, 0), (1, 6)) -Bishop = _make_simple_piece(_PieceType.BISHOP, (7, 0), (2, 5)) +Queen = _make_simple_piece(PieceType.QUEEN, (7, 0), (3,)) +Rook = _make_simple_piece(PieceType.ROOK, (7, 0), (0, 7)) +Knight = _make_simple_piece(PieceType.KNIGHT, (7, 0), (1, 6)) +Bishop = _make_simple_piece(PieceType.BISHOP, (7, 0), (2, 5)) # ============================================================================= def make_promoted( - pawn: Pawn, promote_type: _PromoteType + pawn: Pawn, promote_type: PromoteType ) -> _t.Union[Queen, Rook, Knight, Bishop]: PROMOTE_CLASSES = { - _PromoteType.QUEEN: Queen, - _PromoteType.ROOK: Rook, - _PromoteType.KNIGHT: Knight, - _PromoteType.BISHOP: Bishop, + PromoteType.QUEEN: Queen, + PromoteType.ROOK: Rook, + PromoteType.KNIGHT: Knight, + PromoteType.BISHOP: Bishop, } return PROMOTE_CLASSES[promote_type]( pawn.id, pawn.color, pawn.pos, has_moved=pawn.has_moved diff --git a/src/alicechess/pieces/king.py b/src/alicechess/pieces/king.py index 45dcb7a..775d53c 100644 --- a/src/alicechess/pieces/king.py +++ b/src/alicechess/pieces/king.py @@ -4,9 +4,8 @@ # ============================================================================= -from utils import Color, PieceType - -from .piece import Piece +from alicechess.pieces.piece import Piece +from alicechess.utils import Color, PieceType # ============================================================================= diff --git a/src/alicechess/pieces/pawn.py b/src/alicechess/pieces/pawn.py index e6632d7..764248b 100644 --- a/src/alicechess/pieces/pawn.py +++ b/src/alicechess/pieces/pawn.py @@ -4,9 +4,8 @@ # ============================================================================= -from utils import Color, PieceType - -from .piece import Piece +from alicechess.pieces.piece import Piece +from alicechess.utils import Color, PieceType # ============================================================================= diff --git a/src/alicechess/pieces/piece.py b/src/alicechess/pieces/piece.py index 82092a4..3b9555f 100644 --- a/src/alicechess/pieces/piece.py +++ b/src/alicechess/pieces/piece.py @@ -6,8 +6,8 @@ from typing import Iterator, Optional, Set -from position import BoardPosition, PieceMove, Position -from utils import Color, PieceType, check_brc +from alicechess.position import BoardPosition, PieceMove, Position +from alicechess.utils import Color, PieceType, check_brc # ============================================================================= diff --git a/src/alicechess/player.py b/src/alicechess/player.py index bfd4c45..6d446de 100644 --- a/src/alicechess/player.py +++ b/src/alicechess/player.py @@ -4,10 +4,10 @@ # ============================================================================= -import typing as _t +from typing import Union -import utils as _utils -from position import Move as _Move +from alicechess.position import Move +from alicechess.utils import Color, PromoteType # ============================================================================= @@ -24,12 +24,12 @@ class _PlayerBase: is_human = False - def __init__(self, color: _utils.Color): + def __init__(self, color: Color): """Initializes a player.""" self._color = color @property - def color(self) -> _utils.Color: + def color(self) -> Color: """The player color.""" return self._color @@ -48,7 +48,7 @@ class Player(_PlayerBase): Called when this player can promote a pawn. """ - def make_move(self, game_state: "GameState") -> _Move: + def make_move(self, game_state: "GameState") -> Move: """Called when this player should make their next move. Args: @@ -61,7 +61,7 @@ def make_move(self, game_state: "GameState") -> _Move: f"{self.__class__.__name__}: method `make_move()` not implemented" ) - def promote(self, game_state: "GameState") -> _utils.PromoteType: + def promote(self, game_state: "GameState") -> PromoteType: """Called when this player can promote a pawn. The move being made is accessible through `game_state.move`. @@ -85,4 +85,4 @@ class HumanPlayer(_PlayerBase): # ============================================================================= -AnyPlayer = _t.Union[Player, HumanPlayer] +AnyPlayer = Union[Player, HumanPlayer] diff --git a/src/alicechess/position.py b/src/alicechess/position.py index 33cf2a9..fa1aab3 100644 --- a/src/alicechess/position.py +++ b/src/alicechess/position.py @@ -7,7 +7,7 @@ from functools import total_ordering from typing import Iterable, Optional, Self, Tuple -from utils import check_brc +from alicechess.utils import check_brc # ============================================================================= diff --git a/src/alicechess/test.py b/src/alicechess/test.py deleted file mode 100644 index b26eb14..0000000 --- a/src/alicechess/test.py +++ /dev/null @@ -1,11 +0,0 @@ -from game_state import GameState -from player import HumanPlayer - -# incorrect checkmate - fixed -fen = "rn3b1r/ppp1pp1p/8/6Q1/8/8/PPP1PPPP/R1B1KBNR/8/8/8/8/k2P4/2N5/8/3q4 b - - 8 39" - -# testing -# fen = "k7/1N6/8/8/8/8/8/7K/8/8/8/8/8/8/8/8 b - - 0 0" -# fen = "k7/7R/8/8/8/8/8/1R5K/8/8/8/8/8/8/8/8 b - - 0 0" - -GameState.from_fen(fen, white=HumanPlayer, black=HumanPlayer).debug() diff --git a/src/alicechess/window.py b/src/alicechess/window.py index 58b23d7..4c9d0ac 100644 --- a/src/alicechess/window.py +++ b/src/alicechess/window.py @@ -21,10 +21,14 @@ """ ) from ex -from game_state import GameState -from pieces import Piece -from position import BoardPosition, Position -from utils import Color, PieceType, PromoteType, check_brc_bool +from alicechess.game_state import GameState +from alicechess.pieces import Piece +from alicechess.position import BoardPosition, Position +from alicechess.utils import Color, PieceType, PromoteType, check_brc_bool + +# ============================================================================= + +__all__ = ("Window",) # ============================================================================= @@ -63,7 +67,7 @@ FONTS = ("SF Pro",) # Images -PICTURE_FOLDER = Path("pictures") +PICTURE_FOLDER = Path(__file__).parent / "pictures" PICTURE_EXT = ".png" # =============================================================================