chipiron.players.boardevaluators package
Subpackages
- chipiron.players.boardevaluators.board_evaluation package
- chipiron.players.boardevaluators.datasets package
- chipiron.players.boardevaluators.neural_networks package
- Subpackages
- chipiron.players.boardevaluators.neural_networks.input_converters package
- Submodules
- chipiron.players.boardevaluators.neural_networks.input_converters.ModelInputRepresentationType module
- chipiron.players.boardevaluators.neural_networks.input_converters.board_representation module
- chipiron.players.boardevaluators.neural_networks.input_converters.board_to_input module
- chipiron.players.boardevaluators.neural_networks.input_converters.board_to_transformer_input module
- chipiron.players.boardevaluators.neural_networks.input_converters.factory module
- chipiron.players.boardevaluators.neural_networks.input_converters.rep_364 module
- chipiron.players.boardevaluators.neural_networks.input_converters.rep_364_bug module
- chipiron.players.boardevaluators.neural_networks.input_converters.representation_364_bti module
- chipiron.players.boardevaluators.neural_networks.input_converters.representation_factory_factory module
- chipiron.players.boardevaluators.neural_networks.input_converters.test_representation module
- Module contents
- chipiron.players.boardevaluators.neural_networks.models package
- chipiron.players.boardevaluators.neural_networks.output_converters package
- chipiron.players.boardevaluators.neural_networks.input_converters package
- Submodules
- chipiron.players.boardevaluators.neural_networks.NNModelType module
- chipiron.players.boardevaluators.neural_networks.NNModelTypeArgs module
- chipiron.players.boardevaluators.neural_networks.board_to_tensor module
- chipiron.players.boardevaluators.neural_networks.factory module
NeuralNetModelsAndArchitecturecreate_nn()create_nn_board_eval_from_architecture_args()create_nn_board_eval_from_folder_path_and_existing_model()create_nn_board_eval_from_nn_and_architecture_args()create_nn_board_eval_from_nn_parameters_file_and_existing_model()create_nn_from_folder_path_and_existing_model()create_nn_from_param_path_and_architecture_args()get_architecture_args_from_file()get_architecture_args_from_folder()get_nn_architecture_file_path_from()get_nn_param_file_path_from()
- chipiron.players.boardevaluators.neural_networks.neural_net_board_eval_args module
- chipiron.players.boardevaluators.neural_networks.nn_board_evaluator module
- Module contents
- Subpackages
- chipiron.players.boardevaluators.table_base package
- Submodules
- chipiron.players.boardevaluators.table_base.factory module
- chipiron.players.boardevaluators.table_base.syzygy_python module
- chipiron.players.boardevaluators.table_base.syzygy_rust module
- chipiron.players.boardevaluators.table_base.syzygy_table module
- chipiron.players.boardevaluators.table_base.syzygy_thread module
- Module contents
Submodules
chipiron.players.boardevaluators.basic_evaluation module
Module for the basic evaluation of a chess board.
- class chipiron.players.boardevaluators.basic_evaluation.BasicEvaluation(*args, **kwargs)[source]
Bases:
BoardEvaluatorA basic board evaluator that calculates the value of the board for the white player.
- Parameters:
BoardEvaluator (type) – The base class for board evaluators.
- Variables:
None –
- chipiron.players.boardevaluators.basic_evaluation.add_pawns_value_black(board: IBoard) float[source]
Calculate the value to be added for black pawns based on their position.
This function calculates the value to be added for black pawns based on their position on the board. The value is determined by giving more value to the pawns that are advanced.
- Parameters:
board (BoardChi) – The chess board.
- Returns:
The value to be added for black pawns.
- Return type:
float
- chipiron.players.boardevaluators.basic_evaluation.add_pawns_value_white(board: IBoard) float[source]
Calculate the additional value for white pawns based on their advancement.
- Parameters:
board (BoardChi) – The chess board.
- Returns:
The additional value for white pawns.
- Return type:
float
- chipiron.players.boardevaluators.basic_evaluation.sigmoid(x: float) float[source]
Calculate the sigmoid function of a given input.
- Parameters:
x (float) – The input value.
- Returns:
The result of the sigmoid function.
- Return type:
float
- chipiron.players.boardevaluators.basic_evaluation.value_base(board: IBoard, color: bool) int[source]
Calculate the base value of the given board for the specified color.
- Parameters:
board (BoardChi) – The chess board.
color (chess.Color) – The color for which to calculate the value.
- Returns:
The base value of the board for the specified color.
- Return type:
int
- chipiron.players.boardevaluators.basic_evaluation.value_player_to_move(board: IBoard) float[source]
Calculate the value of the player to move.
This function calculates the value of the player to move based on the difference in piece values between the two players on the board.
- Parameters:
board (BoardChi) – The chess board.
- Returns:
The value of the player to move.
- Return type:
float
- chipiron.players.boardevaluators.basic_evaluation.value_white(board: IBoard) float[source]
Calculate the value of the white pieces on the board.
This function calculates the value of the white pieces on the board by subtracting the value of the black pieces from the value of the white pieces.
- Parameters:
board (BoardChi) – The chess board.
- Returns:
The value of the white pieces on the board.
- Return type:
float
chipiron.players.boardevaluators.board_evaluator module
Module representing the board evaluators.
- class chipiron.players.boardevaluators.board_evaluator.BoardEvaluator(*args, **kwargs)[source]
Bases:
ProtocolProtocol representing a board evaluator.
- class chipiron.players.boardevaluators.board_evaluator.GameBoardEvaluator(board_evaluator_stock: BoardEvaluator | None, board_evaluator_chi: BoardEvaluator)[source]
Bases:
objectThis class is a collection of evaluators that display their analysis during the game. They are not players, just external analysis and display.
- add_evaluation(player_color: bool, evaluation: FloatyBoardEvaluation | ForcedOutcome) None[source]
Adds an evaluation value for a player.
- board_evaluator_chi: BoardEvaluator
- board_evaluator_stock: BoardEvaluator | None
- class chipiron.players.boardevaluators.board_evaluator.IGameBoardEvaluator(*args, **kwargs)[source]
Bases:
ProtocolProtocol representing a game board evaluator.
- add_evaluation(player_color: bool, evaluation: FloatyBoardEvaluation | ForcedOutcome) None[source]
Adds an evaluation value for a player.
- class chipiron.players.boardevaluators.board_evaluator.ObservableBoardEvaluator(game_board_evaluator: GameBoardEvaluator)[source]
Bases:
objectThis class represents an observable board evaluator.
- add_evaluation(player_color: bool, evaluation: FloatyBoardEvaluation | ForcedOutcome) None[source]
Adds an evaluation value for a player.
- evaluate(board: IBoard) tuple[float | None, float][source]
Evaluates a board and returns the evaluation values for stock and chi.
- evaluation_chi: Any
- evaluation_player_black: Any
- evaluation_player_white: Any
- evaluation_stock: Any
- game_board_evaluator: GameBoardEvaluator
- mailboxes: list[queue.Queue[chipiron.utils.dataclass.IsDataclass]]
- subscribe(mailbox: Queue[IsDataclass]) None[source]
Subscribe to the ObservableBoardEvaluator to get the EvaluationMessage.
- Parameters:
mailbox – The mailbox queue.
chipiron.players.boardevaluators.factory module
Module for creating board evaluators.
- class chipiron.players.boardevaluators.factory.BasicEvaluationArgs[source]
Bases:
objectA class representing the arguments for basic evaluation.
This class provides a way to store and access the arguments needed for basic evaluation.
- Variables:
None –
- ``None``
- class chipiron.players.boardevaluators.factory.BoardEvalArgsWrapper(board_evaluator: NeuralNetBoardEvalArgs | StockfishBoardEvalArgs | TableBaseArgs | BasicEvaluationArgs)[source]
Bases:
objectA wrapper class for the BoardEvalArgs object.
This class provides a convenient way to access the board_evaluator attribute of the BoardEvalArgs object.
- Variables:
board_evaluator (BoardEvalArgs) – The BoardEvalArgs object to be wrapped.
- board_evaluator: NeuralNetBoardEvalArgs | StockfishBoardEvalArgs | TableBaseArgs | BasicEvaluationArgs
- class chipiron.players.boardevaluators.factory.TableBaseArgs[source]
Bases:
objectA class representing the arguments for the TableBase class.
This class provides a template for the arguments that can be passed to the TableBase class. It serves as a base class for defining specific argument classes for different implementations of the TableBase class.
- Variables:
None –
- ``None``
- chipiron.players.boardevaluators.factory.create_board_evaluator(args_board_evaluator: NeuralNetBoardEvalArgs | StockfishBoardEvalArgs | TableBaseArgs | BasicEvaluationArgs) BoardEvaluator[source]
Create a board evaluator based on the given arguments.
- Parameters:
args_board_evaluator (BoardEvalArgs) – The arguments for the board evaluator.
- Returns:
The created board evaluator.
- Return type:
- Raises:
SystemExit – If the given arguments do not match any supported board evaluator.
- chipiron.players.boardevaluators.factory.create_game_board_evaluator(gui: bool, can_stockfish: bool) IGameBoardEvaluator[source]
Create a game board evaluator based on the given GUI flag.
- Parameters:
gui (bool) – A flag indicating whether the GUI is enabled or not.
- Returns:
An instance of the game board evaluator.
- Return type:
- chipiron.players.boardevaluators.factory.create_game_board_evaluator_not_observable(can_stockfish: bool) GameBoardEvaluator[source]
Create a game board evaluator that is not observable.
This function creates a game board evaluator that consists of two board evaluators: - board_evaluator_stock: A board evaluator created using the StockfishBoardEvalArgs. - board_evaluator_chi: A board evaluator created using the board evaluator configuration specified in the ‘base_chipiron_board_eval.yaml’ file.
- Returns:
The created game board evaluator.
- Return type:
chipiron.players.boardevaluators.over_event module
Module for handling game over events.
- class chipiron.players.boardevaluators.over_event.HowOver(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumRepresents the possible outcomes of a game.
- Variables:
WIN (int) – Indicates a win.
DRAW (int) – Indicates a draw.
DO_NOT_KNOW_OVER (int) – Indicates that the outcome is unknown.
- DO_NOT_KNOW_OVER = 3
- DRAW = 2
- WIN = 1
- class chipiron.players.boardevaluators.over_event.OverEvent(how_over: HowOver = HowOver.DO_NOT_KNOW_OVER, who_is_winner: Winner = Winner.NO_KNOWN_WINNER, termination: Termination | None = None)[source]
Bases:
objectRepresents an event that indicates the end of a game.
- Variables:
- Raises:
AssertionError – If the how_over attribute is not a valid value from the HowOver enum.
AssertionError – If the who_is_winner attribute is not a valid value from the Winner enum.
Exception – If the winner is not properly defined.
- becomes_over(how_over: HowOver, termination: Termination | None, who_is_winner: Winner = Winner.NO_KNOWN_WINNER) None[source]
Sets the how_over and who_is_winner attributes.
- get_over_tag() OverTags[source]
Returns a tag string used in databases.
- Returns:
The tag string representing the game outcome.
- Return type:
- Raises:
Exception – If the winner is not properly defined.
- is_draw() bool[source]
Checks if the game ended with a draw.
- Returns:
True if the game ended with a draw, False otherwise.
- Return type:
bool
- is_over() bool[source]
Checks if the game is over.
- Returns:
True if the game is over, False otherwise.
- Return type:
bool
- is_win() bool[source]
Checks if the game ended with a win.
- Returns:
True if the game ended with a win, False otherwise.
- Return type:
bool
- is_winner(player: bool) bool[source]
Checks if the specified player is the winner.
- Parameters:
player (chess.Color) – The player to check.
- Returns:
True if the specified player is the winner, False otherwise.
- Return type:
bool
- Raises:
AssertionError – If the player argument is not a valid value from the chess.Color enum.
- termination: Termination | None
- class chipiron.players.boardevaluators.over_event.OverTags(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
str,EnumRepresents the possible tags for game over events.
- Variables:
TAG_WIN_WHITE (str) – Tag indicating a win for the white player.
TAG_WIN_BLACK (str) – Tag indicating a win for the black player.
TAG_DRAW (str) – Tag indicating a draw.
TAG_DO_NOT_KNOW (str) – Tag indicating an unknown outcome.
- TAG_DO_NOT_KNOW = '?'
- TAG_DRAW = 'Draw'
- TAG_WIN_BLACK = 'Win-Bl'
- TAG_WIN_WHITE = 'Win-Wh'
- class chipiron.players.boardevaluators.over_event.Winner(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumRepresents the winner of a chess game.
- Parameters:
Enum – The base class for enumeration types.
- Variables:
- BLACK = False
- NO_KNOWN_WINNER = None
- WHITE = True
- is_black() bool[source]
Check if the winner is black.
- Returns:
True if the winner is black, False otherwise.
- Return type:
bool
chipiron.players.boardevaluators.stockfish_board_evaluator module
Module where we define the Stockfish Board Evaluator
- class chipiron.players.boardevaluators.stockfish_board_evaluator.StockfishBoardEvalArgs(depth: int = 20, time_limit: float = 0.1)[source]
Bases:
objectRepresents the arguments for the Stockfish board evaluator.
- Variables:
depth (int) – The depth of the search algorithm.
time_limit (float) – The time limit for the search algorithm.
- depth: int = 20
- time_limit: float = 0.1
- class chipiron.players.boardevaluators.stockfish_board_evaluator.StockfishBoardEvaluator(args: StockfishBoardEvalArgs)[source]
Bases:
objectA board evaluator powered by stockfish
- engine: SimpleEngine | None
chipiron.players.boardevaluators.test_over_event module
Module for testing the OverEvent class.
Module contents
This module provides board evaluators for the chipiron game.
The board evaluators are used to evaluate the current state of the game board and assign a value to it.
- class chipiron.players.boardevaluators.BoardEvaluator(*args, **kwargs)[source]
Bases:
ProtocolProtocol representing a board evaluator.
- class chipiron.players.boardevaluators.MasterBoardEvaluator(board_evaluator: BoardEvaluator, syzygy: SyzygyTable[Any] | None, value_over_enum: Type[ValueWhiteWhenOverSymmetricUnitInterval] | Type[ValueWhiteWhenOverEntireRealAxis])[source]
Bases:
objectThe MasterBoardEvaluator class is responsible for evaluating the value of nodes in a tree structure. It uses a board evaluator and a syzygy evaluator to calculate the value of the nodes.
- board_evaluator: BoardEvaluator
- check_obvious_over_events(board: IBoard) tuple[chipiron.players.boardevaluators.over_event.OverEvent | None, float | None][source]
Checks if the given board is in an obvious game-over state and returns the corresponding OverEvent and evaluation.
- Parameters:
board (boards.IBoard) – The board to evaluate for game-over conditions.
- Raises:
ValueError – If the board result string is not recognized.
- Returns:
A tuple containing the OverEvent (if the game is over or can be determined from Syzygy tables, otherwise None) and the evaluation score from White’s perspective. The evaluation is especially useful when training models.
- Return type:
tuple[OverEvent | None, float]
- syzygy_evaluator: SyzygyTable[Any] | None
- syzygy_value_white(board: IBoard) float | None[source]
Calculates the value for the white player of a given board using the syzygy evaluator. If the syzygy evaluator is not available or the board is not in the syzygy table, None is returned.
- value_over_enum: Type[ValueWhiteWhenOverSymmetricUnitInterval] | Type[ValueWhiteWhenOverEntireRealAxis]