chipiron.games package

Subpackages

Module contents

Module for managing games.

class chipiron.games.GamePlayingStatus(_status: PlayingStatus = PlayingStatus.PLAY)[source]

Bases: object

Object 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

pause() None[source]

Set the playing status to ‘PAUSE’.

play() None[source]

Set the playing status to ‘PLAY’.

property status: PlayingStatus

Get the current playing status of the game.

Returns:

The current playing status.

Return type:

PlayingStatus

class chipiron.games.MatchManager(player_one_id: str, player_two_id: str, game_manager_factory: GameManagerFactory, game_args_factory: GameArgsFactory, match_results_factory: MatchResultsFactory, output_folder_path: str | PathLike[str] | None = None)[source]

Bases: object

Object in charge of playing one match

Parameters:
  • player_one_id (str) – The ID of player one.

  • player_two_id (str) – The ID of player two.

  • game_manager_factory (GameManagerFactory) – The factory for creating game managers.

  • game_args_factory (GameArgsFactory) – The factory for creating game arguments.

  • match_results_factory (MatchResultsFactory) – The factory for creating match results.

  • output_folder_path (path | None, optional) – The path to the output folder. Defaults to None.

play_one_game(player_color_to_factory_args: dict[bool, chipiron.players.player_args.PlayerFactoryArgs], args_game: GameArgs, game_number: int, game_seed: int) GameReport[source]

Plays one game and returns the game report.

Parameters:
  • player_color_to_factory_args (dict[chess.Color, PlayerFactoryArgs]) – A dictionary mapping player colors to their factory arguments.

  • args_game (GameArgs) – The arguments for the game.

  • game_number (int) – The number of the game.

  • game_seed (seed) – The seed for the game.

Returns:

The report of the game.

Return type:

GameReport

play_one_match() MatchReport[source]

Plays one match and returns the match report.

This method plays a single match, which consists of multiple games. It generates game arguments, plays each game, updates the match results, and saves the match report to a file.

Returns:

The report of the match, including the move history and match results.

Return type:

MatchReport

print_info() None[source]

Prints the information about the players in the match.

This method prints the IDs of player one and player two.

Parameters:

None

Returns:

None

print_stats_to_file(match_results: IMatchResults) None[source]

Prints the match statistics to a file.

Parameters:

match_results (IMatchResults) – The match results object containing the statistics.

save_match_report_to_file(match_report: MatchReport) None[source]

Save the match report to a file.

Parameters:

match_report (MatchReport) – The match report to be saved.

subscribe(subscriber: Queue[IsDataclass]) None[source]

Subscribe a subscriber to receive updates from the match manager.

Parameters:

subscriber (queue.Queue[IsDataclass]) – The subscriber to be added to the list of subscribers.

class chipiron.games.ObservableGamePlayingStatus(game_playing_status: GamePlayingStatus)[source]

Bases: object

An 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

notify() None[source]

Notifies the subscribers with the current game status.

pause() None[source]

Pauses the game and notifies the subscribers.

play() None[source]

Plays the game and notifies the subscribers.

property status: PlayingStatus

Gets the current playing status.

Returns:

The current playing status.

Return type:

PlayingStatus

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.