chipiron.players.move_selector package

Subpackages

Submodules

chipiron.players.move_selector.factory module

This module provides a factory function for creating the main move selector based on the given arguments.

chipiron.players.move_selector.factory.create_main_move_selector(move_selector_instance_or_args: TreeAndValuePlayerArgs | CommandLineHumanPlayerArgs | GuiHumanPlayerArgs | Random | StockfishPlayer, syzygy: SyzygyTable[Any] | None, random_generator: Random, queue_progress_player: Queue[IsDataclass] | None) MoveSelector[source]

Create the main move selector based on the given arguments.

Parameters:
  • move_selector_instance_or_args (AllMoveSelectorArgs) – The arguments or instance of the move selector.

  • syzygy (SyzygyTable | None) – The syzygy table.

  • random_generator (random.Random) – The random number generator.

Returns:

The main move selector.

Return type:

move_selector.MoveSelector

Raises:

ValueError – If the given move selector instance or arguments are invalid.

chipiron.players.move_selector.human module

This module contains the implementation of the CommandLineHumanMoveSelector class, which allows a human player

to select moves through the command line interface.

class chipiron.players.move_selector.human.CommandLineHumanMoveSelector[source]

Bases: object

A move selector that allows a human player to select moves through the command line interface.

select_move(board: IBoard, move_seed: int) MoveRecommendation[source]

Selects a move based on user input through the command line interface.

Parameters:
  • board (boards.BoardChi) – The current state of the chess board.

  • move_seed (seed) – The seed used for move selection.

Returns:

The selected move recommendation.

Return type:

MoveRecommendation

Raises:

AssertionError – If the selected move is not a legal move.

class chipiron.players.move_selector.human.CommandLineHumanPlayerArgs(type: ~typing.Literal[<MoveSelectorTypes.CommandLineHuman: 'CommandLineHuman'>])[source]

Bases: object

Represents the arguments for a human player that selects moves through the command line interface.

type: CommandLineHuman: 'CommandLineHuman'>]
class chipiron.players.move_selector.human.GuiHumanPlayerArgs(type: ~typing.Literal[<MoveSelectorTypes.GuiHuman: 'GuiHuman'>])[source]

Bases: object

Represents the arguments for a human player that selects moves through the GUI.

type: GuiHuman: 'GuiHuman'>]

chipiron.players.move_selector.move_selector module

This module defines the MoveSelector class and related data structures for selecting moves in a chess game.

class chipiron.players.move_selector.move_selector.MoveRecommendation(move: str, evaluation: FloatyBoardEvaluation | ForcedOutcome | None = None)[source]

Bases: object

Represents a recommended move to play along with an optional evaluation score.

evaluation: FloatyBoardEvaluation | ForcedOutcome | None = None
move: str
class chipiron.players.move_selector.move_selector.MoveSelector(*args, **kwargs)[source]

Bases: Protocol

Protocol for move selectors in a chess game.

Move selectors are responsible for selecting the best move to play given a chess board and a move seed.

select_move(board: IBoard, move_seed: int) MoveRecommendation[source]

Selects the best move to play given a chess board and a move seed.

Parameters:
  • board – The current chess board.

  • move_seed – The seed for move selection.

Returns:

The recommended move to play along with an optional evaluation score.

chipiron.players.move_selector.move_selector_args module

This module defines the MoveSelectorArgs protocol for specifying arguments for MoveSelector construction.

class chipiron.players.move_selector.move_selector_args.MoveSelectorArgs(*args, **kwargs)[source]

Bases: Protocol

Protocol for arguments for MoveSelector construction

is_human() bool[source]
type: MoveSelectorTypes

chipiron.players.move_selector.move_selector_types module

This module defines an enumeration class for Move Selector Types.

The MoveSelectorTypes class is a subclass of the str class and the Enum class. It represents different types of move selectors that can be used in a game.

chipiron.players.move_selector.move_selector_types.Random

Represents a random move selector.

chipiron.players.move_selector.move_selector_types.TreeAndValue

Represents a move selector based on tree and value.

chipiron.players.move_selector.move_selector_types.Stockfish

Represents a move selector using the Stockfish engine.

chipiron.players.move_selector.move_selector_types.CommandLineHuman

Represents a move selector for a human player using the command line.

chipiron.players.move_selector.move_selector_types.GuiHuman

Represents a move selector for a human player using a graphical user interface.

class chipiron.players.move_selector.move_selector_types.MoveSelectorTypes(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Enumeration class representing different types of move selectors.

CommandLineHuman = 'CommandLineHuman'
GuiHuman = 'GuiHuman'
Random = 'Random'
Stockfish = 'Stockfish'
TreeAndValue = 'TreeAndValue'
is_human() bool[source]

chipiron.players.move_selector.random module

This module provides a random move selector for a chess game.

The Random class in this module implements a move selector that randomly selects a legal move from the given chess board. It uses a random number generator to make the selection.

Example usage:

random_selector = create_random(random_generator) move = random_selector.select_move(board, move_seed)

class chipiron.players.move_selector.random.Random(type: ~typing.Literal[<MoveSelectorTypes.Random: 'Random'>], random_generator: ~random.Random = <factory>)[source]

Bases: object

Random move selector class.

This class implements a move selector that randomly selects a legal move from the given chess board.

type

The type of move selector (for serialization).

Type:

Literal[MoveSelectorTypes.Random]

random_generator

The random number generator used for making the selection.

Type:

random.Random

random_generator: Random
select_move(board: IBoard, move_seed: int) MoveRecommendation[source]

Selects a random move from the given chess board.

Parameters:
  • board (boards.BoardChi) – The chess board.

  • move_seed (seed) – The seed for the random number generator.

Returns:

The selected move recommendation.

Return type:

MoveRecommendation

type: Random: 'Random'>]
chipiron.players.move_selector.random.create_random(random_generator: Random) Random[source]

Creates a random move selector.

Parameters:

random_generator (random.Random) – The random number generator to use.

Returns:

The created random move selector.

Return type:

Random

chipiron.players.move_selector.stockfish module

This module contains the implementation of the StockfishPlayer class, which is a move selector that uses the Stockfish chess engine to recommend moves.

The StockfishPlayer class is a dataclass that represents a player that selects moves using the Stockfish engine. It has the following attributes: - type: A literal value representing the type of move selector (in this case, MoveSelectorTypes.Stockfish). - depth: An integer representing the depth to which Stockfish should search for moves (default is 20). - time_limit: A float representing the time limit (in seconds) for Stockfish to search for moves (default is 0.1). - engine: An instance of the Stockfish engine.

The StockfishPlayer class has the following methods: - select_move: Selects a move based on the given board state and move seed. Returns a MoveRecommendation object. - print_info: Prints the type of move selector.

Note: The Stockfish engine is initialized lazily when the first move is selected, and it is automatically closed after each move is selected.

class chipiron.players.move_selector.stockfish.StockfishPlayer(type: ~typing.Literal[<MoveSelectorTypes.Stockfish: 'Stockfish'>], depth: int = 20, time_limit: float = 0.1, engine: ~typing.Any = None)[source]

Bases: object

A player that selects moves using the Stockfish chess engine.

type

The type of move selector (for serialization).

Type:

Literal[MoveSelectorTypes.Stockfish]

depth

The depth to which Stockfish should search for moves.

Type:

int

time_limit

The time limit (in seconds) for Stockfish to search for moves.

Type:

float

engine

The Stockfish chess engine instance.

Type:

Any

select_move(board

boards.BoardChi, move_seed: int) -> MoveRecommendation: Selects a move based on the given board state and move seed.

print_info() None[source]

Prints the type of move selector.

depth: int = 20
engine: Any = None
print_info() None[source]

Prints the type of move selector.

select_move(board: IBoard, move_seed: int) MoveRecommendation[source]

Selects a move based on the given board state and move seed.

Parameters:
  • board (boards.BoardChi) – The current board state.

  • move_seed (int) – The seed for move selection.

Returns:

A MoveRecommendation object representing the selected move.

Return type:

MoveRecommendation

time_limit: float = 0.1
type: Stockfish: 'Stockfish'>]

Module contents

Module for move selection in a chess game.

class chipiron.players.move_selector.MoveSelector(*args, **kwargs)[source]

Bases: Protocol

Protocol for move selectors in a chess game.

Move selectors are responsible for selecting the best move to play given a chess board and a move seed.

select_move(board: IBoard, move_seed: int) MoveRecommendation[source]

Selects the best move to play given a chess board and a move seed.

Parameters:
  • board – The current chess board.

  • move_seed – The seed for move selection.

Returns:

The recommended move to play along with an optional evaluation score.

class chipiron.players.move_selector.StockfishPlayer(type: ~typing.Literal[<MoveSelectorTypes.Stockfish: 'Stockfish'>], depth: int = 20, time_limit: float = 0.1, engine: ~typing.Any = None)[source]

Bases: object

A player that selects moves using the Stockfish chess engine.

type

The type of move selector (for serialization).

Type:

Literal[MoveSelectorTypes.Stockfish]

depth

The depth to which Stockfish should search for moves.

Type:

int

time_limit

The time limit (in seconds) for Stockfish to search for moves.

Type:

float

engine

The Stockfish chess engine instance.

Type:

Any

select_move(board

boards.BoardChi, move_seed: int) -> MoveRecommendation: Selects a move based on the given board state and move seed.

print_info() None[source]

Prints the type of move selector.

depth: int = 20
engine: Any = None
print_info() None[source]

Prints the type of move selector.

select_move(board: IBoard, move_seed: int) MoveRecommendation[source]

Selects a move based on the given board state and move seed.

Parameters:
  • board (boards.BoardChi) – The current board state.

  • move_seed (int) – The seed for move selection.

Returns:

A MoveRecommendation object representing the selected move.

Return type:

MoveRecommendation

time_limit: float = 0.1
type: Stockfish: 'Stockfish'>]
chipiron.players.move_selector.create_main_move_selector(move_selector_instance_or_args: TreeAndValuePlayerArgs | CommandLineHumanPlayerArgs | GuiHumanPlayerArgs | Random | StockfishPlayer, syzygy: SyzygyTable[Any] | None, random_generator: Random, queue_progress_player: Queue[IsDataclass] | None) MoveSelector[source]

Create the main move selector based on the given arguments.

Parameters:
  • move_selector_instance_or_args (AllMoveSelectorArgs) – The arguments or instance of the move selector.

  • syzygy (SyzygyTable | None) – The syzygy table.

  • random_generator (random.Random) – The random number generator.

Returns:

The main move selector.

Return type:

move_selector.MoveSelector

Raises:

ValueError – If the given move selector instance or arguments are invalid.