chipiron.environments.chess_env.board package

Submodules

chipiron.environments.chess_env.board.board_chi module

Module that contains the BoardChi class that wraps the chess.Board class from the chess package

class chipiron.environments.chess_env.board.board_chi.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

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
class chipiron.environments.chess_env.board.board_chi.LegalMoveKeyGenerator(chess_board: Board, sort_legal_moves: bool)[source]

Bases: LegalMoveKeyGeneratorP

all_generated_keys: list[int] | None
chess_board: Board
copy(copied_chess_board: Board | None = None) LegalMoveKeyGenerator[source]
copy_with_reset() LegalMoveKeyGenerator[source]
property fen: str
generated_moves: dict[int, chess.Move]
get_all() list[int][source]
more_than_one_move() bool[source]
reset() None[source]

chipiron.environments.chess_env.board.board_modification module

Module that contains the BoardModification class

class chipiron.environments.chess_env.board.board_modification.BoardModification(removals_: set[chipiron.environments.chess_env.board.board_modification.PieceInSquare] = <factory>, appearances_: set[chipiron.environments.chess_env.board.board_modification.PieceInSquare] = <factory>)[source]

Bases: object

Represents a modification to a chessboard resulting from a move.

add_appearance(appearance: PieceInSquare) None[source]

Adds a piece appearance to the board modification.

Parameters:

appearance – The PieceInSquare object representing the appearance to add.

add_removal(removal: PieceInSquare) None[source]

Adds a piece removal to the board modification.

Parameters:

removal – The PieceInSquare object representing the removal to add.

property appearances: Iterator[PieceInSquare]
appearances_: set[chipiron.environments.chess_env.board.board_modification.PieceInSquare]
property removals: Iterator[PieceInSquare]
removals_: set[chipiron.environments.chess_env.board.board_modification.PieceInSquare]
class chipiron.environments.chess_env.board.board_modification.BoardModificationP(*args, **kwargs)[source]

Bases: Protocol

Represents a modification to a chessboard resulting from a move.

property appearances: Iterator[PieceInSquare]
property removals: Iterator[PieceInSquare]
class chipiron.environments.chess_env.board.board_modification.BoardModificationRust(removals_: set[tuple[int, int, int]] = <factory>, appearances_: set[tuple[int, int, int]] = <factory>)[source]

Bases: object

Represents a modification to a chessboard resulting from a move.

property appearances: Iterator[PieceInSquare]
appearances_: set[tuple[int, int, int]]
property removals: Iterator[PieceInSquare]
removals_: set[tuple[int, int, int]]
class chipiron.environments.chess_env.board.board_modification.PieceInSquare(square: int, piece: int, color: bool)[source]

Bases: object

Represents a piece on a chessboard square.

color: bool
piece: int
square: int
class chipiron.environments.chess_env.board.board_modification.PieceRustIterator(items_: set[tuple[int, int, int]] = <factory>)[source]

Bases: object

items_: set[tuple[int, int, int]]
chipiron.environments.chess_env.board.board_modification.compute_modifications(previous_pawns: int, previous_kings: int, previous_queens: int, previous_rooks: int, previous_bishops: int, previous_knights: int, previous_occupied_white: int, previous_occupied_black: int, new_pawns: int, new_kings: int, new_queens: int, new_rooks: int, new_bishops: int, new_knights: int, new_occupied_white: int, new_occupied_black: int) BoardModification[source]

chipiron.environments.chess_env.board.board_tools module

Module to convert an ascii board to a FEN string.

chipiron.environments.chess_env.board.board_tools.convert_line(line: AnyStr, index: int) str[source]

Convert a line of the ascii board to a FEN string.

Parameters:
  • line (AnyStr) – The line of the ascii board.

  • index (int) – The starting index of the line.

Returns:

The converted FEN string.

Return type:

str

chipiron.environments.chess_env.board.board_tools.convert_to_fen(ascii_board: AnyStr) str[source]

Convert an ascii board to a FEN string.

Parameters:

ascii_board (AnyStr) – The ascii board.

Returns:

The converted FEN string.

Return type:

str

chipiron.environments.chess_env.board.factory module

Module to create a chess board.

class chipiron.environments.chess_env.board.factory.BoardFactory(*args, **kwargs)[source]

Bases: Protocol

chipiron.environments.chess_env.board.factory.create_board(use_rust_boards: bool = False, use_board_modification: bool = False, sort_legal_moves: bool = False, fen_with_history: FenPlusHistory | None = None) IBoard[source]
chipiron.environments.chess_env.board.factory.create_board_chi(fen_with_history: FenPlusHistory | None = None, use_board_modification: bool = False, sort_legal_moves: bool = False) BoardChi[source]

Create a chipiron chess board.

Parameters:
  • use_board_modification (bool) – whether to use the board modification

  • fen_with_history (FenPlusMoves | None) – The BoardWithHistory that contains a fen and the subsequent moves. The FEN (Forsyth-Edwards Notation) string representing the board position. If None, the starting position is used.

Returns:

The created chess board.

Return type:

BoardChi

chipiron.environments.chess_env.board.factory.create_board_chi_from_pychess_board(chess_board: Board, use_board_modification: bool = False, sort_legal_moves: bool = False) BoardChi[source]
chipiron.environments.chess_env.board.factory.create_board_factory(use_rust_boards: bool = False, use_board_modification: bool = False, sort_legal_moves: bool = False) BoardFactory[source]
chipiron.environments.chess_env.board.factory.create_rust_board(fen_with_history: FenPlusHistory | None = None, use_board_modification: bool = False, sort_legal_moves: bool = False) RustyBoardChi[source]

Create a rust chess board.

Parameters:
  • use_board_modification (bool) – whether to use the board modification

  • board_with_history (FenPlusMoves | None) – The BoardWithHistory that contains a fen and the subsequent moves. The FEN (Forsyth-Edwards Notation) string representing the board position. If None, the starting position is used.

Returns:

The created chess board.

Return type:

RustyBoardChi

chipiron.environments.chess_env.board.iboard module

class chipiron.environments.chess_env.board.iboard.IBoard(*args, **kwargs)[source]

Bases: Protocol

property bishops: int
property black: int
property castling_rights: int
copy(stack: bool, deep_copy_legal_moves: bool = True) Self[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

dump(file: Any) None[source]
property ep_square: int | None
property fast_representation: tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int, int, int]

Returns a fast representation of the board.

This method computes and returns a string representation of the board that can be quickly generated and used for various purposes.

Returns:

A string representation of the board.

Return type:

str

fast_representation_: tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int, int, int]
property fast_representation_without_counters: tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int]

Returns a fast representation of the board.

This method computes and returns a string representation of the board that can be quickly generated and used for various purposes.

Returns:

A string representation of the board.

Return type:

str

property fen: str
property fullmove_number: int
get_move_key_from_uci(move_uci: str) int[source]
get_uci_from_move_key(move_key: int) str[source]
property halfmove_clock: int
has_kingside_castling_rights(color: bool) bool[source]
has_queenside_castling_rights(color: bool) bool[source]
into_fen_plus_history() FenPlusHistory[source]
is_attacked(a_color: bool) bool[source]
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: LegalMoveKeyGeneratorP
legal_moves_: LegalMoveKeyGeneratorP
property move_history_stack: list[str]
number_of_pieces_on_the_board() int[source]
property occupied: int
occupied_color(color: bool) int[source]
property pawns: int
piece_map() dict[int, tuple[int, bool]][source]
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]
property promoted: int
property queens: int
result(claim_draw: bool = False) str[source]
property rooks: int
tell_result() None[source]
termination() Termination | None[source]
property turn: bool

Get the current turn color.

Returns:

The color of the current turn.

Return type:

chess.Color

property white: int
class chipiron.environments.chess_env.board.iboard.LegalMoveKeyGeneratorP(*args, **kwargs)[source]

Bases: Protocol

all_generated_keys: list[int] | None
property fen: str
generated_moves: dict[int, chess.Move] | list[MyMove] | None
get_all() list[int][source]
more_than_one_move() bool[source]
chipiron.environments.chess_env.board.iboard.compute_key(pawns: int, knights: int, bishops: int, rooks: int, queens: int, kings: int, turn: bool, castling_rights: int, ep_square: int | None, white: int, black: int, promoted: int, fullmove_number: int, halfmove_clock: int) tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int, int, int][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. It is faster than calling the fen. :returns: A unique key representing the current state of the chess board. :rtype: str

chipiron.environments.chess_env.board.rusty_board module

class chipiron.environments.chess_env.board.rusty_board.LegalMoveKeyGeneratorRust(sort_legal_moves: bool, chess_rust_binding: MyChess, generated_moves: list[MyMove] | None = None)[source]

Bases: LegalMoveKeyGeneratorP

all_generated_keys: list[int] | None
chess_rust_binding: MyChess
copy(copied_chess_rust_binding: MyChess | None = None) LegalMoveKeyGeneratorRust[source]
copy_with_reset(generated_moves: list[MyMove] | None = None) LegalMoveKeyGeneratorRust[source]
property fen: str
generated_moves: list[MyMove] | None
get_all() list[int][source]
more_than_one_move() bool[source]
reset(generated_moves: list[MyMove]) None[source]
class chipiron.environments.chess_env.board.rusty_board.RustyBoardChi(chess_: MyChess, compute_board_modification: bool, rep_to_count: ~collections.Counter[tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int]], fast_representation_: tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int, int, int], pawns_: int, kings_: int, queens_: int, rooks_: int, bishops_: int, knights_: int, white_: int, black_: int, turn_: bool, ep_square_: int | None, promoted_: int, castling_rights_: int, legal_moves_: ~chipiron.environments.chess_env.board.rusty_board.LegalMoveKeyGeneratorRust, move_stack: list[str] = <factory>)[source]

Bases: IBoard

Rusty Board Chipiron object that describes the current board. it wraps the chess Board from the chess package so it can have more in it but im not sure its really necessary.i keep it for potential usefulness

This is the Rust version for speedy execution It is based on the binding library shakmaty_python_binding to use the rust library shakmaty

property bishops: int
bishops_: int
property black: int
black_: int
property castling_rights: int
castling_rights_: int
chess_: MyChess
compute_board_modification: bool
convert(appearances: set[tuple[int, int, int]], removals: set[tuple[int, int, int]]) BoardModificationRust[source]
copy(stack: bool, deep_copy_legal_moves: bool = True) Self[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:

RustyBoardChi

dump(f: Any) None[source]
property ep_square: int | None
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_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 kingside 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
kings_: int
property knights: int
knights_: int
property legal_moves: LegalMoveKeyGeneratorRust
legal_moves_: LegalMoveKeyGeneratorRust
property move_history_stack: list[str]
move_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
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() dict[int, tuple[int, bool]][source]
play_min(move: MyMove) None[source]
play_min_2(move: MyMove) None[source]
play_min_3(move: MyMove) BoardModificationRust[source]
play_move(move: MyMove) 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_old(move: MyMove) BoardModification | 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
promoted_: int
property queens: int
queens_: int
rep_to_count: Counter[tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int]]
result(claim_draw: bool = False) str[source]
property rooks: int
rooks_: int
tell_result() None[source]
termination() None[source]
property turn: bool

Get the current turn color.

Returns:

The color of the current turn.

Return type:

chess.Color

turn_: bool
property white: int
white_: int

chipiron.environments.chess_env.board.starting_position module

Module defining the starting position arguments for the chess board.

class chipiron.environments.chess_env.board.starting_position.FenStartingPositionArgs(type: ~typing.Literal[<StartingPositionArgsType.fen: 'fen'>], fen: str)[source]

Bases: object

Dataclass representing the starting position arguments specified by FEN.

fen: str
get_fen() str[source]
type: fen: 'fen'>]
class chipiron.environments.chess_env.board.starting_position.FileStartingPositionArgs(type: ~typing.Literal[<StartingPositionArgsType.fromFile: 'from_file'>], file_name: str)[source]

Bases: StartingPositionArgs

Dataclass representing the starting position arguments specified by a file.

file_name: str
get_fen() str[source]
type: fromFile: 'from_file'>]
class chipiron.environments.chess_env.board.starting_position.StartingPositionArgs(*args, **kwargs)[source]

Bases: Protocol

Dataclass representing the base class for starting position arguments.

get_fen() str[source]
type: StartingPositionArgsType
class chipiron.environments.chess_env.board.starting_position.StartingPositionArgsType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Enum class representing the type of starting position arguments.

fen = 'fen'
fromFile = 'from_file'

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.test_universal_behavior.test_universal_behavior() None[source]

chipiron.environments.chess_env.board.utils module

class chipiron.environments.chess_env.board.utils.FenPlusHistory(current_fen: Annotated[str, 'a string representing a fen'], historical_moves: list[typing.Annotated[str, 'a string representing a move uci']] = <factory>, historical_boards: list[chess._BoardState] = <factory>)[source]

Bases: object

current_fen: str
current_turn() bool[source]
historical_boards: list[chess._BoardState]
historical_moves: list[str]
class chipiron.environments.chess_env.board.utils.FenPlusMoveHistory(current_fen: Annotated[str, 'a string representing a fen'], historical_moves: list[typing.Annotated[str, 'a string representing a move uci']] = <factory>)[source]

Bases: object

current_fen: str
historical_moves: list[str]
class chipiron.environments.chess_env.board.utils.FenPlusMoves(original_fen: Annotated[str, 'a string representing a fen'], subsequent_moves: list[chess.Move] = <factory>)[source]

Bases: object

original_fen: str
subsequent_moves: list[chess.Move]
chipiron.environments.chess_env.board.utils.bitboard_rotate(bitboard: int) int[source]

Rotates the square 180.

chipiron.environments.chess_env.board.utils.square_rotate(square: int) int[source]

Rotates the square 180.

Module contents

init file for board module

class chipiron.environments.chess_env.board.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

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
class chipiron.environments.chess_env.board.BoardFactory(*args, **kwargs)[source]

Bases: Protocol

class chipiron.environments.chess_env.board.BoardModification(removals_: set[chipiron.environments.chess_env.board.board_modification.PieceInSquare] = <factory>, appearances_: set[chipiron.environments.chess_env.board.board_modification.PieceInSquare] = <factory>)[source]

Bases: object

Represents a modification to a chessboard resulting from a move.

add_appearance(appearance: PieceInSquare) None[source]

Adds a piece appearance to the board modification.

Parameters:

appearance – The PieceInSquare object representing the appearance to add.

add_removal(removal: PieceInSquare) None[source]

Adds a piece removal to the board modification.

Parameters:

removal – The PieceInSquare object representing the removal to add.

property appearances: Iterator[PieceInSquare]
appearances_: set[chipiron.environments.chess_env.board.board_modification.PieceInSquare]
property removals: Iterator[PieceInSquare]
removals_: set[chipiron.environments.chess_env.board.board_modification.PieceInSquare]
class chipiron.environments.chess_env.board.BoardModificationP(*args, **kwargs)[source]

Bases: Protocol

Represents a modification to a chessboard resulting from a move.

property appearances: Iterator[PieceInSquare]
property removals: Iterator[PieceInSquare]
class chipiron.environments.chess_env.board.IBoard(*args, **kwargs)[source]

Bases: Protocol

property bishops: int
property black: int
property castling_rights: int
copy(stack: bool, deep_copy_legal_moves: bool = True) Self[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

dump(file: Any) None[source]
property ep_square: int | None
property fast_representation: tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int, int, int]

Returns a fast representation of the board.

This method computes and returns a string representation of the board that can be quickly generated and used for various purposes.

Returns:

A string representation of the board.

Return type:

str

fast_representation_: tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int, int, int]
property fast_representation_without_counters: tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int]

Returns a fast representation of the board.

This method computes and returns a string representation of the board that can be quickly generated and used for various purposes.

Returns:

A string representation of the board.

Return type:

str

property fen: str
property fullmove_number: int
get_move_key_from_uci(move_uci: str) int[source]
get_uci_from_move_key(move_key: int) str[source]
property halfmove_clock: int
has_kingside_castling_rights(color: bool) bool[source]
has_queenside_castling_rights(color: bool) bool[source]
into_fen_plus_history() FenPlusHistory[source]
is_attacked(a_color: bool) bool[source]
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: LegalMoveKeyGeneratorP
legal_moves_: LegalMoveKeyGeneratorP
property move_history_stack: list[str]
number_of_pieces_on_the_board() int[source]
property occupied: int
occupied_color(color: bool) int[source]
property pawns: int
piece_map() dict[int, tuple[int, bool]][source]
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]
property promoted: int
property queens: int
result(claim_draw: bool = False) str[source]
property rooks: int
tell_result() None[source]
termination() Termination | None[source]
property turn: bool

Get the current turn color.

Returns:

The color of the current turn.

Return type:

chess.Color

property white: int
class chipiron.environments.chess_env.board.RustyBoardChi(chess_: MyChess, compute_board_modification: bool, rep_to_count: ~collections.Counter[tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int]], fast_representation_: tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int, int, int], pawns_: int, kings_: int, queens_: int, rooks_: int, bishops_: int, knights_: int, white_: int, black_: int, turn_: bool, ep_square_: int | None, promoted_: int, castling_rights_: int, legal_moves_: ~chipiron.environments.chess_env.board.rusty_board.LegalMoveKeyGeneratorRust, move_stack: list[str] = <factory>)[source]

Bases: IBoard

Rusty Board Chipiron object that describes the current board. it wraps the chess Board from the chess package so it can have more in it but im not sure its really necessary.i keep it for potential usefulness

This is the Rust version for speedy execution It is based on the binding library shakmaty_python_binding to use the rust library shakmaty

property bishops: int
bishops_: int
property black: int
black_: int
property castling_rights: int
castling_rights_: int
chess_: MyChess
compute_board_modification: bool
convert(appearances: set[tuple[int, int, int]], removals: set[tuple[int, int, int]]) BoardModificationRust[source]
copy(stack: bool, deep_copy_legal_moves: bool = True) Self[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:

RustyBoardChi

dump(f: Any) None[source]
property ep_square: int | None
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_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 kingside 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
kings_: int
property knights: int
knights_: int
property legal_moves: LegalMoveKeyGeneratorRust
legal_moves_: LegalMoveKeyGeneratorRust
property move_history_stack: list[str]
move_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
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() dict[int, tuple[int, bool]][source]
play_min(move: MyMove) None[source]
play_min_2(move: MyMove) None[source]
play_min_3(move: MyMove) BoardModificationRust[source]
play_move(move: MyMove) 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_old(move: MyMove) BoardModification | 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
promoted_: int
property queens: int
queens_: int
rep_to_count: Counter[tuple[int, int, int, int, int, int, bool, int, int | None, int, int, int]]
result(claim_draw: bool = False) str[source]
property rooks: int
rooks_: int
tell_result() None[source]
termination() None[source]
property turn: bool

Get the current turn color.

Returns:

The color of the current turn.

Return type:

chess.Color

turn_: bool
property white: int
white_: int
chipiron.environments.chess_env.board.create_board(use_rust_boards: bool = False, use_board_modification: bool = False, sort_legal_moves: bool = False, fen_with_history: FenPlusHistory | None = None) IBoard[source]
chipiron.environments.chess_env.board.create_board_chi(fen_with_history: FenPlusHistory | None = None, use_board_modification: bool = False, sort_legal_moves: bool = False) BoardChi[source]

Create a chipiron chess board.

Parameters:
  • use_board_modification (bool) – whether to use the board modification

  • fen_with_history (FenPlusMoves | None) – The BoardWithHistory that contains a fen and the subsequent moves. The FEN (Forsyth-Edwards Notation) string representing the board position. If None, the starting position is used.

Returns:

The created chess board.

Return type:

BoardChi

chipiron.environments.chess_env.board.create_board_factory(use_rust_boards: bool = False, use_board_modification: bool = False, sort_legal_moves: bool = False) BoardFactory[source]