chipiron.environments.chess_env package
Subpackages
- chipiron.environments.chess_env.board package
- Submodules
- chipiron.environments.chess_env.board.board_chi module
BoardChiBoardChi.__str__()BoardChi.bishopsBoardChi.blackBoardChi.castling_rightsBoardChi.chess_boardBoardChi.compute_board_modificationBoardChi.compute_key_old()BoardChi.copy()BoardChi.ep_squareBoardChi.fast_representation_BoardChi.fenBoardChi.fullmove_numberBoardChi.halfmove_clockBoardChi.has_castling_rights()BoardChi.has_kingside_castling_rights()BoardChi.has_queenside_castling_rights()BoardChi.into_fen_plus_history()BoardChi.is_attacked()BoardChi.is_game_over()BoardChi.is_zeroing()BoardChi.kingsBoardChi.knightsBoardChi.legal_movesBoardChi.legal_moves_BoardChi.move_history_stackBoardChi.number_of_pieces_on_the_board()BoardChi.occupiedBoardChi.occupied_color()BoardChi.pawnsBoardChi.piece_at()BoardChi.piece_map()BoardChi.play_mon()BoardChi.play_move()BoardChi.play_move_key()BoardChi.play_move_uci()BoardChi.ply()BoardChi.print_chess_board()BoardChi.promotedBoardChi.push_and_return_modification()BoardChi.queensBoardChi.result()BoardChi.rewind_one_move()BoardChi.rooksBoardChi.sort_legal_movesBoardChi.tell_result()BoardChi.termination()BoardChi.turnBoardChi.white
LegalMoveKeyGeneratorLegalMoveKeyGenerator.all_generated_keysLegalMoveKeyGenerator.chess_boardLegalMoveKeyGenerator.copy()LegalMoveKeyGenerator.copy_with_reset()LegalMoveKeyGenerator.fenLegalMoveKeyGenerator.generated_movesLegalMoveKeyGenerator.get_all()LegalMoveKeyGenerator.more_than_one_move()LegalMoveKeyGenerator.reset()LegalMoveKeyGenerator.sort_legal_moves
- chipiron.environments.chess_env.board.board_modification module
- chipiron.environments.chess_env.board.board_tools module
- chipiron.environments.chess_env.board.factory module
- chipiron.environments.chess_env.board.iboard module
IBoardIBoard.bishopsIBoard.blackIBoard.castling_rightsIBoard.copy()IBoard.dump()IBoard.ep_squareIBoard.fast_representationIBoard.fast_representation_IBoard.fast_representation_without_countersIBoard.fenIBoard.fullmove_numberIBoard.get_move_key_from_uci()IBoard.get_uci_from_move_key()IBoard.halfmove_clockIBoard.has_kingside_castling_rights()IBoard.has_queenside_castling_rights()IBoard.into_fen_plus_history()IBoard.is_attacked()IBoard.is_game_over()IBoard.is_zeroing()IBoard.kingsIBoard.knightsIBoard.legal_movesIBoard.legal_moves_IBoard.move_history_stackIBoard.number_of_pieces_on_the_board()IBoard.occupiedIBoard.occupied_color()IBoard.pawnsIBoard.piece_map()IBoard.play_move_key()IBoard.play_move_uci()IBoard.ply()IBoard.print_chess_board()IBoard.promotedIBoard.queensIBoard.result()IBoard.rooksIBoard.tell_result()IBoard.termination()IBoard.turnIBoard.white
LegalMoveKeyGeneratorPcompute_key()
- chipiron.environments.chess_env.board.rusty_board module
LegalMoveKeyGeneratorRustLegalMoveKeyGeneratorRust.all_generated_keysLegalMoveKeyGeneratorRust.chess_rust_bindingLegalMoveKeyGeneratorRust.copy()LegalMoveKeyGeneratorRust.copy_with_reset()LegalMoveKeyGeneratorRust.fenLegalMoveKeyGeneratorRust.generated_movesLegalMoveKeyGeneratorRust.get_all()LegalMoveKeyGeneratorRust.more_than_one_move()LegalMoveKeyGeneratorRust.reset()LegalMoveKeyGeneratorRust.set_legal_moves()
RustyBoardChiRustyBoardChi.__str__()RustyBoardChi.bishopsRustyBoardChi.bishops_RustyBoardChi.blackRustyBoardChi.black_RustyBoardChi.castling_rightsRustyBoardChi.castling_rights_RustyBoardChi.chess_RustyBoardChi.compute_board_modificationRustyBoardChi.convert()RustyBoardChi.copy()RustyBoardChi.dump()RustyBoardChi.ep_squareRustyBoardChi.ep_square_RustyBoardChi.fast_representation_RustyBoardChi.fenRustyBoardChi.fullmove_numberRustyBoardChi.halfmove_clockRustyBoardChi.has_kingside_castling_rights()RustyBoardChi.has_queenside_castling_rights()RustyBoardChi.into_fen_plus_history()RustyBoardChi.is_attacked()RustyBoardChi.is_game_over()RustyBoardChi.is_zeroing()RustyBoardChi.kingsRustyBoardChi.kings_RustyBoardChi.knightsRustyBoardChi.knights_RustyBoardChi.legal_movesRustyBoardChi.legal_moves_RustyBoardChi.move_history_stackRustyBoardChi.move_stackRustyBoardChi.number_of_pieces_on_the_board()RustyBoardChi.occupiedRustyBoardChi.occupied_color()RustyBoardChi.pawnsRustyBoardChi.pawns_RustyBoardChi.piece_at()RustyBoardChi.piece_map()RustyBoardChi.play_min_2()RustyBoardChi.play_min_3()RustyBoardChi.play_move()RustyBoardChi.play_move_key()RustyBoardChi.play_move_uci()RustyBoardChi.ply()RustyBoardChi.print_chess_board()RustyBoardChi.promotedRustyBoardChi.promoted_RustyBoardChi.queensRustyBoardChi.queens_RustyBoardChi.rep_to_countRustyBoardChi.result()RustyBoardChi.rooksRustyBoardChi.rooks_RustyBoardChi.tell_result()RustyBoardChi.termination()RustyBoardChi.turnRustyBoardChi.turn_RustyBoardChi.whiteRustyBoardChi.white_
- chipiron.environments.chess_env.board.starting_position module
- chipiron.environments.chess_env.board.test_board module
- chipiron.environments.chess_env.board.test_modifications module
- chipiron.environments.chess_env.board.test_universal_behavior module
- chipiron.environments.chess_env.board.utils module
- Module contents
BoardChiBoardChi.__str__()BoardChi.bishopsBoardChi.blackBoardChi.castling_rightsBoardChi.chess_boardBoardChi.compute_board_modificationBoardChi.compute_key_old()BoardChi.copy()BoardChi.ep_squareBoardChi.fast_representation_BoardChi.fenBoardChi.fullmove_numberBoardChi.halfmove_clockBoardChi.has_castling_rights()BoardChi.has_kingside_castling_rights()BoardChi.has_queenside_castling_rights()BoardChi.into_fen_plus_history()BoardChi.is_attacked()BoardChi.is_game_over()BoardChi.is_zeroing()BoardChi.kingsBoardChi.knightsBoardChi.legal_movesBoardChi.legal_moves_BoardChi.move_history_stackBoardChi.number_of_pieces_on_the_board()BoardChi.occupiedBoardChi.occupied_color()BoardChi.pawnsBoardChi.piece_at()BoardChi.piece_map()BoardChi.play_mon()BoardChi.play_move()BoardChi.play_move_key()BoardChi.play_move_uci()BoardChi.ply()BoardChi.print_chess_board()BoardChi.promotedBoardChi.push_and_return_modification()BoardChi.queensBoardChi.result()BoardChi.rewind_one_move()BoardChi.rooksBoardChi.sort_legal_movesBoardChi.tell_result()BoardChi.termination()BoardChi.turnBoardChi.white
BoardFactoryBoardModificationBoardModificationPIBoardIBoard.bishopsIBoard.blackIBoard.castling_rightsIBoard.copy()IBoard.dump()IBoard.ep_squareIBoard.fast_representationIBoard.fast_representation_IBoard.fast_representation_without_countersIBoard.fenIBoard.fullmove_numberIBoard.get_move_key_from_uci()IBoard.get_uci_from_move_key()IBoard.halfmove_clockIBoard.has_kingside_castling_rights()IBoard.has_queenside_castling_rights()IBoard.into_fen_plus_history()IBoard.is_attacked()IBoard.is_game_over()IBoard.is_zeroing()IBoard.kingsIBoard.knightsIBoard.legal_movesIBoard.legal_moves_IBoard.move_history_stackIBoard.number_of_pieces_on_the_board()IBoard.occupiedIBoard.occupied_color()IBoard.pawnsIBoard.piece_map()IBoard.play_move_key()IBoard.play_move_uci()IBoard.ply()IBoard.print_chess_board()IBoard.promotedIBoard.queensIBoard.result()IBoard.rooksIBoard.tell_result()IBoard.termination()IBoard.turnIBoard.white
RustyBoardChiRustyBoardChi.__str__()RustyBoardChi.bishopsRustyBoardChi.bishops_RustyBoardChi.blackRustyBoardChi.black_RustyBoardChi.castling_rightsRustyBoardChi.castling_rights_RustyBoardChi.chess_RustyBoardChi.compute_board_modificationRustyBoardChi.convert()RustyBoardChi.copy()RustyBoardChi.dump()RustyBoardChi.ep_squareRustyBoardChi.ep_square_RustyBoardChi.fast_representation_RustyBoardChi.fenRustyBoardChi.fullmove_numberRustyBoardChi.halfmove_clockRustyBoardChi.has_kingside_castling_rights()RustyBoardChi.has_queenside_castling_rights()RustyBoardChi.into_fen_plus_history()RustyBoardChi.is_attacked()RustyBoardChi.is_game_over()RustyBoardChi.is_zeroing()RustyBoardChi.kingsRustyBoardChi.kings_RustyBoardChi.knightsRustyBoardChi.knights_RustyBoardChi.legal_movesRustyBoardChi.legal_moves_RustyBoardChi.move_history_stackRustyBoardChi.move_stackRustyBoardChi.number_of_pieces_on_the_board()RustyBoardChi.occupiedRustyBoardChi.occupied_color()RustyBoardChi.pawnsRustyBoardChi.pawns_RustyBoardChi.piece_at()RustyBoardChi.piece_map()RustyBoardChi.play_min_2()RustyBoardChi.play_min_3()RustyBoardChi.play_move()RustyBoardChi.play_move_key()RustyBoardChi.play_move_uci()RustyBoardChi.ply()RustyBoardChi.print_chess_board()RustyBoardChi.promotedRustyBoardChi.promoted_RustyBoardChi.queensRustyBoardChi.queens_RustyBoardChi.rep_to_countRustyBoardChi.result()RustyBoardChi.rooksRustyBoardChi.rooks_RustyBoardChi.tell_result()RustyBoardChi.termination()RustyBoardChi.turnRustyBoardChi.turn_RustyBoardChi.whiteRustyBoardChi.white_
create_board()create_board_chi()create_board_factory()
- chipiron.environments.chess_env.move package
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.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:
objectRepresents 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_modifications: BoardModification
- move: Move
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:
IBoardBoard 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:
- 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
- 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
- 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
- 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
- property rooks: int
- sort_legal_moves: bool
- property turn: bool
Get the current turn color.
- Returns:
The color of the current turn.
- Return type:
chess.Color
- property white: int