chipiron.displays package

Submodules

chipiron.displays.gui module

This module is the execution point of the chess GUI application.

It provides the MainWindow class, which creates a surface for the chessboard and handles user interactions.

class chipiron.displays.gui.MainWindow(gui_mailbox: Queue[IsDataclass], main_thread_mailbox: Queue[IsDataclass], board_factory: BoardFactory)[source]

Bases: QWidget

Create a surface for the chessboard and handle user interactions.

This class provides the main window for the chess GUI application. It handles user interactions such as clicking on chess pieces, making moves, and controlling the game status.

playing_status

The current playing status of the game.

Type:

PlayingStatus

gui_mailbox

The mailbox for receiving messages from the GUI thread.

Type:

queue.Queue[IsDataclass]

main_thread_mailbox

The mailbox for sending messages to the main thread.

Type:

queue.Queue[IsDataclass]

back_button_clicked() None[source]

Handle the event when the back button is clicked.

This method prints a message and puts a BackMessage object into the main thread mailbox.

choice_promote()[source]

Displays a dialog box with buttons for promoting a chess piece.

The dialog box allows the user to choose between promoting the pawn to a queen, rook, bishop, or knight. Each button is connected to a corresponding method for handling the promotion.

Returns:

None

display_move_history() None[source]

Display the move history in a table widget.

This method calculates the number of rounds based on the number of half moves in the move stack. It then sets the number of rows in the table widget to the number of rounds. The table widget’s horizontal header labels are set to ‘White’ and ‘Black’. The move history is then iterated over and each move is added to the table widget.

Returns:

None

draw_board() None[source]

Draw a chessboard with the starting position and then redraw it for every new move.

Returns:

None

extract_message_from_player(player: PlayerFactoryArgs) str[source]

Extracts a message from a player to be shown in the GUI.

Parameters:

player (PlayerFactoryArgs) – The factory arguments for the player.

Returns:

The extracted message.

Return type:

str

mousePressEvent(event)[source]

Handle left mouse clicks and enable moving chess pieces by clicking on a chess piece and then the target square.

Moves must be made according to the rules of chess because illegal moves are suppressed.

pause_button_clicked() None[source]

Handles the click event of the pause button.

Prints ‘pause_button_clicked’ and sends a GameStatusMessage with the status set to PlayingStatus.PAUSE to the main thread mailbox.

play_button_clicked() None[source]

Handle the event when the play button is clicked.

This method prints a message indicating that the play button has been clicked, and sends a GameStatusMessage with the status set to PlayingStatus.PLAY to the main thread mailbox.

process_message() None[source]

Process a message received by the GUI.

Draw a chessboard with the starting position and then redraw it for every new move.

This method is responsible for handling different types of messages received by the GUI and taking appropriate actions based on the message type.

Supported message types: - BoardMessage: Updates the board and redraws it. - EvaluationMessage: Updates the evaluation values. - PlayersColorToPlayerMessage: Updates the mapping of player colors to player information. - MatchResultsMessage: Updates the match results. - GameStatusMessage: Updates the game play status. - Other: Raises a ValueError indicating an unknown message type.

Returns: None

promote_bishop()[source]

Promotes the current piece to a bishop.

This method creates a move object to promote the current piece to a bishop and closes the dialog window.

Returns:

None

promote_knight()[source]

Promotes a pawn to a knight.

This method is called when a pawn is promoted to a knight in the GUI. It creates a move object representing the promotion and closes the GUI.

Returns: None

promote_queen()[source]

Promotes the selected piece to a queen.

This method creates a move object to promote the selected piece to a queen by appending ‘q’ to the UCI notation of the piece’s destination square. It then closes the dialog window.

Returns:

None

promote_rook()[source]

Promotes a pawn to a rook.

This method is called when a pawn reaches the opposite end of the board and needs to be promoted to a rook. It creates a move object representing the promotion and closes the dialog window.

Returns:

None

send_move_to_main_thread(move_uci: str) None[source]

Sends a move to the main thread for processing.

Parameters:

move (chess.Move) – The move to be sent.

Returns:

None

staticMetaObject = PySide6.QtCore.QMetaObject("MainWindow" inherits "QWidget": Methods:   #34 type=Slot, signature=mousePressEvent(QWidget*), parameters=QWidget* )
stopppy() None[source]

Stops the execution of the GUI.

This method closes the GUI window and sends a kill message to the main thread.

Returns:

None

update_evaluation(evaluation_stock: float, evaluation_chipiron: float, evaluation_white: float, evaluation_black: float) None[source]

Update the evaluation values displayed on the GUI.

Parameters:
  • evaluation_stock (float) – The evaluation value for the stock.

  • evaluation_chipiron (float) – The evaluation value for the chipiron.

  • evaluation_white (float) – The evaluation value for the white.

  • evaluation_black (float) – The evaluation value for the black.

Returns:

None

update_game_play_status(play_status: PlayingStatus) None[source]

Update the game play status.

Parameters:

play_status (PlayingStatus) – The new playing status.

update_match_stats(match_result: MatchResults) None[source]

Update the match statistics and display them on the GUI.

Parameters:

match_result (MatchResults) – The result of the match.

Returns:

None

update_players_color_to_id(players_color_to_player: dict[bool, chipiron.players.player_args.PlayerFactoryArgs]) None[source]

Update the player buttons with the corresponding player names.

Parameters:

players_color_to_player (dict[chess.Color, str]) – A dictionary mapping chess.Color to player names.

Returns:

None

chipiron.displays.gui_replay_games module

This module is the execution point of the chess GUI application.

class chipiron.displays.gui_replay_games.MainWindow(chess_board: BoardChi)[source]

Bases: QWidget

Create a surface for the chessboard.

drawBoard() Any[source]

Draw a chessboard with the starting position and then redraw it for every new move.

keyPressEvent(event: QKeyEvent) None[source]

Handle key press events.

Parameters:

event (QKeyEvent) – The key event object.

staticMetaObject = PySide6.QtCore.QMetaObject("MainWindow" inherits "QWidget": Methods:   #34 type=Slot, signature=keyPressEvent(QWidget*), parameters=QWidget* )

Module contents

init file for displays module

class chipiron.displays.MainWindow(gui_mailbox: Queue[IsDataclass], main_thread_mailbox: Queue[IsDataclass], board_factory: BoardFactory)[source]

Bases: QWidget

Create a surface for the chessboard and handle user interactions.

This class provides the main window for the chess GUI application. It handles user interactions such as clicking on chess pieces, making moves, and controlling the game status.

playing_status

The current playing status of the game.

Type:

PlayingStatus

gui_mailbox

The mailbox for receiving messages from the GUI thread.

Type:

queue.Queue[IsDataclass]

main_thread_mailbox

The mailbox for sending messages to the main thread.

Type:

queue.Queue[IsDataclass]

back_button_clicked() None[source]

Handle the event when the back button is clicked.

This method prints a message and puts a BackMessage object into the main thread mailbox.

choice_promote()[source]

Displays a dialog box with buttons for promoting a chess piece.

The dialog box allows the user to choose between promoting the pawn to a queen, rook, bishop, or knight. Each button is connected to a corresponding method for handling the promotion.

Returns:

None

display_move_history() None[source]

Display the move history in a table widget.

This method calculates the number of rounds based on the number of half moves in the move stack. It then sets the number of rows in the table widget to the number of rounds. The table widget’s horizontal header labels are set to ‘White’ and ‘Black’. The move history is then iterated over and each move is added to the table widget.

Returns:

None

draw_board() None[source]

Draw a chessboard with the starting position and then redraw it for every new move.

Returns:

None

extract_message_from_player(player: PlayerFactoryArgs) str[source]

Extracts a message from a player to be shown in the GUI.

Parameters:

player (PlayerFactoryArgs) – The factory arguments for the player.

Returns:

The extracted message.

Return type:

str

mousePressEvent(event)[source]

Handle left mouse clicks and enable moving chess pieces by clicking on a chess piece and then the target square.

Moves must be made according to the rules of chess because illegal moves are suppressed.

pause_button_clicked() None[source]

Handles the click event of the pause button.

Prints ‘pause_button_clicked’ and sends a GameStatusMessage with the status set to PlayingStatus.PAUSE to the main thread mailbox.

pause_button_clicked_last_time: float | None
play_button_clicked() None[source]

Handle the event when the play button is clicked.

This method prints a message indicating that the play button has been clicked, and sends a GameStatusMessage with the status set to PlayingStatus.PLAY to the main thread mailbox.

play_button_clicked_last_time: float | None
process_message() None[source]

Process a message received by the GUI.

Draw a chessboard with the starting position and then redraw it for every new move.

This method is responsible for handling different types of messages received by the GUI and taking appropriate actions based on the message type.

Supported message types: - BoardMessage: Updates the board and redraws it. - EvaluationMessage: Updates the evaluation values. - PlayersColorToPlayerMessage: Updates the mapping of player colors to player information. - MatchResultsMessage: Updates the match results. - GameStatusMessage: Updates the game play status. - Other: Raises a ValueError indicating an unknown message type.

Returns: None

promote_bishop()[source]

Promotes the current piece to a bishop.

This method creates a move object to promote the current piece to a bishop and closes the dialog window.

Returns:

None

promote_knight()[source]

Promotes a pawn to a knight.

This method is called when a pawn is promoted to a knight in the GUI. It creates a move object representing the promotion and closes the GUI.

Returns: None

promote_queen()[source]

Promotes the selected piece to a queen.

This method creates a move object to promote the selected piece to a queen by appending ‘q’ to the UCI notation of the piece’s destination square. It then closes the dialog window.

Returns:

None

promote_rook()[source]

Promotes a pawn to a rook.

This method is called when a pawn reaches the opposite end of the board and needs to be promoted to a rook. It creates a move object representing the promotion and closes the dialog window.

Returns:

None

send_move_to_main_thread(move_uci: str) None[source]

Sends a move to the main thread for processing.

Parameters:

move (chess.Move) – The move to be sent.

Returns:

None

staticMetaObject = PySide6.QtCore.QMetaObject("MainWindow" inherits "QWidget": Methods:   #34 type=Slot, signature=mousePressEvent(QWidget*), parameters=QWidget* )
stopppy() None[source]

Stops the execution of the GUI.

This method closes the GUI window and sends a kill message to the main thread.

Returns:

None

update_evaluation(evaluation_stock: float, evaluation_chipiron: float, evaluation_white: float, evaluation_black: float) None[source]

Update the evaluation values displayed on the GUI.

Parameters:
  • evaluation_stock (float) – The evaluation value for the stock.

  • evaluation_chipiron (float) – The evaluation value for the chipiron.

  • evaluation_white (float) – The evaluation value for the white.

  • evaluation_black (float) – The evaluation value for the black.

Returns:

None

update_game_play_status(play_status: PlayingStatus) None[source]

Update the game play status.

Parameters:

play_status (PlayingStatus) – The new playing status.

update_match_stats(match_result: MatchResults) None[source]

Update the match statistics and display them on the GUI.

Parameters:

match_result (MatchResults) – The result of the match.

Returns:

None

update_players_color_to_id(players_color_to_player: dict[bool, chipiron.players.player_args.PlayerFactoryArgs]) None[source]

Update the player buttons with the corresponding player names.

Parameters:

players_color_to_player (dict[chess.Color, str]) – A dictionary mapping chess.Color to player names.

Returns:

None