chipiron.environments.chess_env package

Subpackages

Submodules

chipiron.environments.chess_env.move_factory module

class chipiron.environments.chess_env.move_factory.MoveFactory(*args, **kwargs)[source]

Bases: Protocol

chipiron.environments.chess_env.move_factory.create_move(move_uci: str, board: IBoard | None = None) Move[source]
chipiron.environments.chess_env.move_factory.create_move_factory(use_rust_boards: bool) MoveFactory[source]
chipiron.environments.chess_env.move_factory.create_rust_move(move_uci: str, board: RustyBoardChi | None = None) MyMove[source]
chipiron.environments.chess_env.move_factory.create_rust_move_test(move_uci: str, board: IBoard | None = None) Move[source]
chipiron.environments.chess_env.move_factory.create_rust_move_test_2(move_uci: str, board: IBoard | None = None) MyMove[source]

chipiron.environments.chess_env.transition module

Module to define the transition between two boards

class chipiron.environments.chess_env.transition.BoardTransition(board: BoardChi, move: Move, next_board: BoardChi, board_modifications: BoardModification)[source]

Bases: object

Represents a transition from one chess board state to another.

Variables:
  • board (BoardChi) – The initial chess board state.

  • move (chess.Move) – The move that was made to transition to the next board state.

  • next_board (BoardChi) – The resulting chess board state after the move.

  • board_modifications (BoardModification) – The modifications made to the board during the transition.

board: BoardChi
board_modifications: BoardModification
move: Move
next_board: BoardChi

Module contents

init file for chess environment

class chipiron.environments.chess_env.BoardChi(chess_board: Board, compute_board_modification: bool, fast_representation_: tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int, int, int], legal_moves_: LegalMoveKeyGenerator)[source]

Bases: IBoard

Board Chipiron object that describes the current board. it wraps the chess Board from the chess package so it can have more in it

__str__() str[source]

Returns a string representation of the board.

Returns:

A string representation of the board.

Return type:

str

property bishops: int
property black: int
property castling_rights: int
chess_board: Board
compute_board_modification: bool
compute_key_old() str[source]

Computes and returns a unique key representing the current state of the chess board.

The key is computed by concatenating various attributes of the board, including the positions of pawns, knights, bishops, rooks, queens, and kings, as well as the current turn, castling rights, en passant square, halfmove clock, occupied squares for each color, promoted pieces, and the fullmove number.

Returns:

A unique key representing the current state of the chess board.

Return type:

str

copy(stack: bool, deep_copy_legal_moves: bool = True) BoardChi[source]

Create a copy of the current board.

Parameters:

stack (bool) – Whether to copy the move stack as well.

Returns:

A new instance of the BoardChi class with the copied board.

Return type:

BoardChi

property ep_square: int | None
fast_representation_: tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int, int, int]
property fen: str

Returns the Forsyth-Edwards Notation (FEN) representation of the chess board.

Returns:

The FEN string representing the current state of the board.

property fullmove_number: int
property halfmove_clock: int
has_castling_rights(color: bool) bool[source]

Check if the specified color has castling rights.

Parameters:

color (chess.Color) – The color to check for castling rights.

Returns:

True if the color has castling rights, False otherwise.

Return type:

bool

has_kingside_castling_rights(color: bool) bool[source]

Check if the specified color has kingside castling rights.

Parameters:

color (chess.Color) – The color to check for kingside castling rights.

Returns:

True if the specified color has kingside castling rights, False otherwise.

Return type:

bool

has_queenside_castling_rights(color: bool) bool[source]

Check if the specified color has queenside castling rights.

Parameters:

color (chess.Color) – The color to check for queenside castling rights.

Returns:

True if the specified color has queenside castling rights, False otherwise.

Return type:

bool

into_fen_plus_history() FenPlusHistory[source]
is_attacked(a_color: bool) bool[source]

Check if any piece of the color a_color is attacked.

Parameters:

a_color (chess.Color) – The color of the pieces to check.

Returns:

True if any piece of the specified color is attacked, False otherwise.

Return type:

bool

is_game_over() bool[source]

Check if the game is over.

Returns:

True if the game is over, False otherwise.

Return type:

bool

is_zeroing(move: int) bool[source]
property kings: int
property knights: int
property legal_moves: LegalMoveKeyGenerator

Returns a generator that yields all the legal moves for the current board state.

Returns:

A generator that yields legal moves.

Return type:

chess.LegalMoveGenerator

legal_moves_: LegalMoveKeyGenerator
property move_history_stack: list[str]
number_of_pieces_on_the_board() int[source]

Returns the number of pieces currently on the board.

Returns:

The number of pieces on the board.

Return type:

int

property occupied: int
occupied_color(color: bool) int[source]
property pawns: int
piece_at(square: int) Piece | None[source]

Returns the piece at the specified square on the chess board.

Parameters:

square (chess.Square) – The square on the chess board.

Returns:

The piece at the specified square, or None if there is no piece.

Return type:

chess.Piece | None

piece_map(mask: int = 18446744073709551615) dict[int, tuple[int, bool]][source]
play_mon(move: Move) None[source]
play_move(move: Move, use_compute_modification_function: bool = False) BoardModificationP | None[source]

Plays a move on the board and returns the board modification.

Parameters:

move – The move to play.

Returns:

The board modification resulting from the move or None.

play_move_key(move: int) BoardModificationP | None[source]
play_move_uci(move_uci: str) BoardModificationP | None[source]
ply() int[source]

Returns the number of half-moves (plies) that have been played on the board.

Returns:

The number of half-moves played on the board.

Return type:

int

print_chess_board() str[source]

Prints the current state of the chess board.

This method prints the current state of the chess board, including the position of all the pieces. It also prints the FEN (Forsyth–Edwards Notation) representation of the board.

Returns:

None

property promoted: int
push_and_return_modification(move: Move) BoardModification | None[source]

Mostly reuse the push function of the chess library but records the modifications to the bitboard so that we can do the same with other parallel representations such as tensor in pytorch

Parameters:

move – The move to push.

Returns:

The board modification resulting from the move, or None if the move is a null move.

property queens: int
result(claim_draw: bool = False) str[source]
rewind_one_move() None[source]

Rewinds the board state to the previous move.

property rooks: int
tell_result() None[source]
termination() Termination[source]
property turn: bool

Get the current turn color.

Returns:

The color of the current turn.

Return type:

chess.Color

property white: int