chipiron.games.game package
Submodules
chipiron.games.game.final_game_result module
Module for the FinalGameResult enum and the GameReport dataclass.
- class chipiron.games.game.final_game_result.FinalGameResult(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
str,EnumEnum representing the final result of a game.
- DRAW = 'draw'
- WIN_FOR_BLACK = 'win_for_black'
- WIN_FOR_WHITE = 'win_for_white'
- class chipiron.games.game.final_game_result.GameReport(final_game_result: FinalGameResult, move_history: list[str], fen_history: list[str])[source]
Bases:
objectDataclass representing a game report.
- fen_history: list[str]
- final_game_result: FinalGameResult
- move_history: list[str]
chipiron.games.game.game module
Module for the Game class.
- class chipiron.games.game.game.Game(board: IBoard, playing_status: GamePlayingStatus, seed_: int = 0)[source]
Bases:
objectClass representing a game of chess.
Note
A Game and a Board can look similar as a Board can (but not necessarily) include a record of previous moves. Board should be more lightweight than Game. Boards are more specific to a special position (but can include history) while Game is more related to the entire game and the process generating it. Game needs the original FEN, all the moves, the seed to generate and maybe more.
- property fen_history: list[str]
Gets the history of fen.
- Returns:
The history of fen.
- Return type:
list[fen]
- is_paused() bool[source]
Checks if the game is paused.
- Returns:
True if the game is paused, False otherwise.
- Return type:
bool
- is_play() bool[source]
Checks if the game is being played.
- Returns:
True if the game is being played, False otherwise.
- Return type:
bool
- property move_history: list[str]
Gets the history of move.
- Returns:
The history of move.
- Return type:
list[chess.Move]
- play_move(move: int) None[source]
Plays a move on the chess board.
- Parameters:
move (chess.Move) – The move to be played.
- Raises:
AssertionError – If the move is not valid or the game status is not play.
- property playing_status: GamePlayingStatus
Gets or sets the playing status of the game.
- Returns:
The playing status of the game.
- Return type:
- class chipiron.games.game.game.ObservableGame(game: Game)[source]
Bases:
objectRepresents an observable version of the Game object.
- property fen_history: list[str]
Gets the history of fen.
- Returns:
The history of fen.
- Return type:
list[fen]
- is_paused() bool[source]
Checks if the game is paused.
- Returns:
True if the game is paused, False otherwise.
- Return type:
bool
- is_play() bool[source]
Checks if the game is being played.
- Returns:
True if the game is being played, False otherwise.
- Return type:
bool
- mailboxes_display: list[queue.Queue[chipiron.utils.dataclass.IsDataclass]]
- move_functions: list[chipiron.players.factory_higher_level.MoveFunction]
- property move_history: list[str]
Gets the history of move.
- Returns:
The history of move.
- Return type:
list[chess.Move]
- play_move(move: int) None[source]
Plays a move on the chess board.
- Parameters:
move (chess.Move) – The move to be played.
- property playing_status: GamePlayingStatus
Gets the playing status of the game.
- Returns:
The playing status of the game.
- Return type:
- register_display(mailbox: Queue[IsDataclass]) None[source]
Registers a mailbox for displaying the board.
- Parameters:
mailbox (queue.Queue[IsDataclass]) – The mailbox for board to be displayed.
- register_player(move_function: MoveFunction) None[source]
Registers a player to compute a move.
- Parameters:
move_function (MoveFunction) – The function to be called to compute a move.
chipiron.games.game.game_args module
Module that contains the GameArgs class.
- class chipiron.games.game.game_args.GameArgs(starting_position: FenStartingPositionArgs | FileStartingPositionArgs, max_half_moves: int | None = None, each_player_has_its_own_thread: bool = False)[source]
Bases:
objectRepresents the arguments for a game.
- Variables:
starting_position (AllStartingPositionArgs) – The starting position of the game.
max_half_moves (int | None, optional) – The maximum number of half moves allowed in the game. Defaults to None.
each_player_has_its_own_thread (bool, optional) – Whether each player has its own thread. Defaults to False.
- each_player_has_its_own_thread: bool = False
- max_half_moves: int | None = None
- starting_position: FenStartingPositionArgs | FileStartingPositionArgs
chipiron.games.game.game_args_factory module
Module for the GameArgsFactory class
This module defines the GameArgsFactory class, which is responsible for creating game arguments and managing game settings.
- class chipiron.games.game.game_args_factory.GameArgsFactory(args_match: match.MatchSettingsArgs, args_player_one: PlayerArgs, args_player_two: PlayerArgs, seed_: int | None, args_game: GameArgs)[source]
Bases:
objectThe GameArgsFactory creates the players and decides the rules. So far quite simple This class is supposed to be dependent on Match-related classes (contrarily to the GameArgsFactory)
- args_match: match.MatchSettingsArgs
- args_player_one: PlayerArgs
- args_player_two: PlayerArgs
- game_number: int
- generate_game_args(game_number: int) tuple[dict[bool, chipiron.players.player_args.PlayerFactoryArgs], chipiron.games.game.game_args.GameArgs, Optional[int]][source]
Generate game arguments for a specific game number.
- Parameters:
game_number (int) – The number of the game.
- Returns:
A tuple containing the player color to factory arguments mapping, game arguments, and the merged seed.
- Return type:
tuple[dict[chess.Color, players.PlayerFactoryArgs], GameArgs, seed | None]
- is_match_finished() bool[source]
Check if the match is finished.
- Returns:
True if the match is finished, False otherwise.
- Return type:
bool
- seed_: int | None
chipiron.games.game.game_manager module
Module in charge of managing the game. It is the main class that will be used to play a game.
- class chipiron.games.game.game_manager.GameManager(game: ObservableGame, syzygy: SyzygyTable[Any] | None, display_board_evaluator: IGameBoardEvaluator, output_folder_path: str | PathLike[str] | None, args: GameArgs, player_color_to_id: dict[bool, str], main_thread_mailbox: Queue[IsDataclass], players: list[chipiron.players.player_thread.PlayerProcess | chipiron.players.game_player.GamePlayer], move_factory: MoveFactory, progress_collector: PlayerProgressCollectorP)[source]
Bases:
objectObject in charge of playing one game
- display_board_evaluator: IGameBoardEvaluator
- external_eval() tuple[float | None, float][source]
Evaluates the game board using the display board evaluator.
- Returns:
A tuple containing the evaluation scores.
- Return type:
tuple[float, float]
- game: ObservableGame
- game_continue_conditions() bool[source]
Checks the conditions for continuing the game.
- Returns:
True if the game should continue, False otherwise.
- Return type:
bool
- main_thread_mailbox: Queue[IsDataclass]
- move_factory: MoveFactory
- output_folder_path: str | PathLike[str] | None
- play_one_game() GameReport[source]
Play one game.
- Returns:
The report of the game.
- Return type:
- play_one_move(move: int) None[source]
Play one move in the game.
- Parameters:
move (chess.Move) – The move to be played.
- player_color_to_id: dict[bool, str]
- players: list[chipiron.players.player_thread.PlayerProcess | chipiron.players.game_player.GamePlayer]
- print_to_file(game_report: GameReport, idx: int = 0) None[source]
Print the moves of the game to a yaml file and a more human-readable text file.
- Parameters:
game_report (GameReport) – a game report to be printed
idx (int) – The index to include in the file name (default is 0).
- Returns:
None
- processing_mail(message: IsDataclass) None[source]
Process the incoming mail message.
- Parameters:
message (IsDataclass) – The incoming mail message.
- Returns:
None
- progress_collector: PlayerProgressCollectorP
- rewind_one_move() None[source]
Rewinds the game by one move.
This method rewinds the game by one move, undoing the last move made. If the game has a Syzygy tablebase loaded and the current board position is in the tablebase, it prints the theoretically finished value for white.
- Returns:
None
- simple_results() FinalGameResult[source]
Determines the final result of the game based on the current state of the board.
- Returns:
The final result of the game.
- Return type:
- syzygy: SyzygyTable[Any] | None
- tell_results() None[source]
Prints the results of the game based on the current state of the board.
The method checks various conditions on the board and prints the corresponding result. It also checks for specific conditions like syzygy, fivefold repetition, seventy-five moves, insufficient material, stalemate, and checkmate.
- Returns:
None
- terminate_processes() None[source]
Terminates all player processes and stops the associated threads.
This method iterates over the list of players and terminates any player processes found. If a player process is found, it is terminated and the associated thread is stopped.
Note: - This method assumes that the players attribute is a list of PlayerProcess or GamePlayer objects.
Returns: None
chipiron.games.game.game_manager_factory module
Module for the GameManagerFactory class.
- class chipiron.games.game.game_manager_factory.GameManagerFactory(syzygy_table: ~chipiron.players.boardevaluators.table_base.syzygy_table.SyzygyTable[~typing.Any] | None, output_folder_path: str | ~os.PathLike[str] | None, main_thread_mailbox: ~queue.Queue[~chipiron.utils.dataclass.IsDataclass], game_manager_board_evaluator: ~chipiron.players.boardevaluators.board_evaluator.IGameBoardEvaluator, board_factory: ~chipiron.environments.chess_env.board.factory.BoardFactory, move_factory: ~chipiron.environments.chess_env.move_factory.MoveFactory, implementation_args: ~chipiron.scripts.chipiron_args.ImplementationArgs, universal_behavior: bool, subscribers: list[queue.Queue[chipiron.utils.dataclass.IsDataclass]] = <factory>)[source]
Bases:
objectThe GameManagerFactory creates GameManager once the players and rules have been decided. Calling create ask for the creation of a GameManager depending on args and players. This class is supposed to be independent of Match-related classes (contrarily to the GameArgsFactory)
Args: syzygy_table (SyzygyTable | None): The syzygy table used for endgame tablebase lookups. game_manager_board_evaluator (IGameBoardEvaluator): The game board evaluator used for evaluating game positions. output_folder_path (path | None): The path to the output folder where game data will be saved. main_thread_mailbox (queue.Queue[IsDataclass]): The mailbox used for communication between processes.
- board_factory: BoardFactory
- create(args_game_manager: GameArgs, player_color_to_factory_args: dict[bool, chipiron.players.player_args.PlayerFactoryArgs], game_seed: int) GameManager[source]
Create a GameManager with the given arguments
- Parameters:
args_game_manager (GameArgs) – the arguments of the game manager
player_color_to_factory_args (dict[chess.Color, PlayerFactoryArgs]) – the arguments of the players
game_seed (int) – the seed of the game
- Returns:
the created GameManager
- game_manager_board_evaluator: IGameBoardEvaluator
- implementation_args: ImplementationArgs
- main_thread_mailbox: Queue[IsDataclass]
- move_factory: MoveFactory
- output_folder_path: str | PathLike[str] | None
- subscribe(subscriber: Queue[IsDataclass]) None[source]
Subscribe to the GameManagerFactory to get the PlayersColorToPlayerMessage As well as subscribing to the game_manager_board_evaluator to get the EvaluationMessage
- Parameters:
subscriber – the subscriber queue
- subscribers: list[queue.Queue[chipiron.utils.dataclass.IsDataclass]]
- syzygy_table: SyzygyTable[Any] | None
- universal_behavior: bool
chipiron.games.game.game_playing_status module
Module containing the class GamePlaying
- class chipiron.games.game.game_playing_status.GamePlayingStatus(_status: PlayingStatus = PlayingStatus.PLAY)[source]
Bases:
objectObject containing the playing status of a game and the board.
- is_paused() bool[source]
Check if the game is currently paused.
- Returns:
True if the game is paused, False otherwise.
- Return type:
bool
- is_play() bool[source]
Check if the game is currently playing.
- Returns:
True if the game is playing, False otherwise.
- Return type:
bool
- property status: PlayingStatus
Get the current playing status of the game.
- Returns:
The current playing status.
- Return type:
chipiron.games.game.observable_game_playing_status module
Module that defines an observable version of GamePlayingStatus
- class chipiron.games.game.observable_game_playing_status.ObservableGamePlayingStatus(game_playing_status: GamePlayingStatus)[source]
Bases:
objectAn observable version of GamePlayingStatus that notifies subscribers. Players and GUI can then decide what to do with this information.
- is_paused() bool[source]
Checks if the game is currently paused.
- Returns:
True if the game is paused, False otherwise.
- Return type:
bool
- is_play() bool[source]
Checks if the game is currently being played.
- Returns:
True if the game is being played, False otherwise.
- Return type:
bool
- property status: PlayingStatus
Gets the current playing status.
- Returns:
The current playing status.
- Return type:
- subscribe(mailboxes: list[queue.Queue[chipiron.utils.communication.gui_messages.game_status_message.GameStatusMessage]]) None[source]
Subscribes the given mailboxes to receive game status updates.
- Parameters:
mailboxes (list[queue.Queue[GameStatusMessage]]) – The mailboxes to subscribe.
chipiron.games.game.progress_collector module
Module collecting the progress of computing moves by each player
- class chipiron.games.game.progress_collector.PlayerProgressCollector(progress_white_: int | None = None, progress_black_: int | None = None)[source]
Bases:
objectObject in charge of collecting the progress of computing moves by each player
- property progress_black: int | None
- progress_black_: int | None = None
- property progress_white: int | None
- progress_white_: int | None = None
- class chipiron.games.game.progress_collector.PlayerProgressCollectorObservable(progress_collector: ~chipiron.games.game.progress_collector.PlayerProgressCollector = <factory>, subscribers: list[queue.Queue[chipiron.utils.dataclass.IsDataclass]] = <factory>)[source]
Bases:
objectObject in charge of collecting the progress of computing moves by each player
- progress_collector: PlayerProgressCollector
- subscribers: list[queue.Queue[chipiron.utils.dataclass.IsDataclass]]
chipiron.games.game.test_game module
Module contents
This module contains the game logic and the game arguments.
The game module provides the following classes: - ObservableGame: A class that represents an observable game. - Game: A class that represents a game. - GameArgs: A class that represents the game arguments. - GameArgsFactory: A class that provides a factory for creating game arguments.
The module also defines the __all__ list, which specifies the names that should be imported when using the from game import * syntax.
- Example usage:
from game import ObservableGame, Game, GameArgs, GameArgsFactory
- class chipiron.games.game.Game(board: IBoard, playing_status: GamePlayingStatus, seed_: int = 0)[source]
Bases:
objectClass representing a game of chess.
Note
A Game and a Board can look similar as a Board can (but not necessarily) include a record of previous moves. Board should be more lightweight than Game. Boards are more specific to a special position (but can include history) while Game is more related to the entire game and the process generating it. Game needs the original FEN, all the moves, the seed to generate and maybe more.
- property fen_history: list[str]
Gets the history of fen.
- Returns:
The history of fen.
- Return type:
list[fen]
- is_paused() bool[source]
Checks if the game is paused.
- Returns:
True if the game is paused, False otherwise.
- Return type:
bool
- is_play() bool[source]
Checks if the game is being played.
- Returns:
True if the game is being played, False otherwise.
- Return type:
bool
- property move_history: list[str]
Gets the history of move.
- Returns:
The history of move.
- Return type:
list[chess.Move]
- play_move(move: int) None[source]
Plays a move on the chess board.
- Parameters:
move (chess.Move) – The move to be played.
- Raises:
AssertionError – If the move is not valid or the game status is not play.
- property playing_status: GamePlayingStatus
Gets or sets the playing status of the game.
- Returns:
The playing status of the game.
- Return type:
- class chipiron.games.game.GameArgs(starting_position: FenStartingPositionArgs | FileStartingPositionArgs, max_half_moves: int | None = None, each_player_has_its_own_thread: bool = False)[source]
Bases:
objectRepresents the arguments for a game.
- Variables:
starting_position (AllStartingPositionArgs) – The starting position of the game.
max_half_moves (int | None, optional) – The maximum number of half moves allowed in the game. Defaults to None.
each_player_has_its_own_thread (bool, optional) – Whether each player has its own thread. Defaults to False.
- each_player_has_its_own_thread: bool = False
- max_half_moves: int | None = None
- starting_position: FenStartingPositionArgs | FileStartingPositionArgs
- class chipiron.games.game.GameArgsFactory(args_match: match.MatchSettingsArgs, args_player_one: PlayerArgs, args_player_two: PlayerArgs, seed_: int | None, args_game: GameArgs)[source]
Bases:
objectThe GameArgsFactory creates the players and decides the rules. So far quite simple This class is supposed to be dependent on Match-related classes (contrarily to the GameArgsFactory)
- args_match: match.MatchSettingsArgs
- args_player_one: PlayerArgs
- args_player_two: PlayerArgs
- game_number: int
- generate_game_args(game_number: int) tuple[dict[bool, chipiron.players.player_args.PlayerFactoryArgs], chipiron.games.game.game_args.GameArgs, Optional[int]][source]
Generate game arguments for a specific game number.
- Parameters:
game_number (int) – The number of the game.
- Returns:
A tuple containing the player color to factory arguments mapping, game arguments, and the merged seed.
- Return type:
tuple[dict[chess.Color, players.PlayerFactoryArgs], GameArgs, seed | None]
- is_match_finished() bool[source]
Check if the match is finished.
- Returns:
True if the match is finished, False otherwise.
- Return type:
bool
- seed_: int | None
- class chipiron.games.game.ObservableGame(game: Game)[source]
Bases:
objectRepresents an observable version of the Game object.
- property fen_history: list[str]
Gets the history of fen.
- Returns:
The history of fen.
- Return type:
list[fen]
- is_paused() bool[source]
Checks if the game is paused.
- Returns:
True if the game is paused, False otherwise.
- Return type:
bool
- is_play() bool[source]
Checks if the game is being played.
- Returns:
True if the game is being played, False otherwise.
- Return type:
bool
- mailboxes_display: list[queue.Queue[chipiron.utils.dataclass.IsDataclass]]
- move_functions: list[chipiron.players.factory_higher_level.MoveFunction]
- property move_history: list[str]
Gets the history of move.
- Returns:
The history of move.
- Return type:
list[chess.Move]
- play_move(move: int) None[source]
Plays a move on the chess board.
- Parameters:
move (chess.Move) – The move to be played.
- property playing_status: GamePlayingStatus
Gets the playing status of the game.
- Returns:
The playing status of the game.
- Return type:
- register_display(mailbox: Queue[IsDataclass]) None[source]
Registers a mailbox for displaying the board.
- Parameters:
mailbox (queue.Queue[IsDataclass]) – The mailbox for board to be displayed.
- register_player(move_function: MoveFunction) None[source]
Registers a player to compute a move.
- Parameters:
move_function (MoveFunction) – The function to be called to compute a move.