lczerolens.play#
Play module for the lczerolens package.
Submodules#
Classes#
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Package Contents#
- class lczerolens.play.ModelSampler[source]#
Bases:
SamplerHelper class that provides a standard way to create an ABC using inheritance.
- use_argmax: bool = True#
- alpha: float = 1.0#
- beta: float = 1.0#
- gamma: float = 1.0#
- draw_score: float = 0.0#
- m_max: float = 0.0345#
- m_slope: float = 0.0027#
- k_0: float = 0.0#
- k_1: float = 1.6521#
- k_2: float = -0.6521#
- q_threshold: float = 0.8#
- choose_move(board, utility, legal_indices)[source]#
Choose the next moves.
- Parameters:
board (LczeroBoard) – The board.
utility (torch.Tensor) – The utility of the board.
legal_indices (torch.Tensor) – The legal indices.
- Returns:
The iterable over the moves.
- Return type:
Iterable[chess.Move]
- get_utilities(boards, **kwargs)[source]#
Get the utility of the board.
- Parameters:
boards (Iterable[LczeroBoard]) – The boards to evaluate.
- Returns:
The iterable over utilities, legal indices, and log dictionaries.
- Return type:
Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]
- class lczerolens.play.Sampler[source]#
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- abstract get_utilities(boards, **kwargs)[source]#
Get the utility of the board.
- Parameters:
boards (Iterable[LczeroBoard]) – The boards to evaluate.
- Returns:
The iterable over utilities, legal indices, and log dictionaries.
- Return type:
Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]
- choose_move(board, utility, legal_indices)[source]#
Choose the next moves.
- Parameters:
board (LczeroBoard) – The board.
utility (torch.Tensor) – The utility of the board.
legal_indices (torch.Tensor) – The legal indices.
- Returns:
The iterable over the moves.
- Return type:
Iterable[chess.Move]
- get_next_moves(boards, **kwargs)[source]#
Get the next move.
- Parameters:
boards (Iterable[LczeroBoard]) – The boards to evaluate.
- Returns:
The iterable over the moves and log dictionaries.
- Return type:
Iterable[Tuple[chess.Move, Dict[str, float]]]
- class lczerolens.play.RandomSampler[source]#
Bases:
SamplerHelper class that provides a standard way to create an ABC using inheritance.
- get_utilities(boards, **kwargs)[source]#
Get the utility of the board.
- Parameters:
boards (Iterable[LczeroBoard]) – The boards to evaluate.
- Returns:
The iterable over utilities, legal indices, and log dictionaries.
- Return type:
Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]
- class lczerolens.play.PolicySampler[source]#
Bases:
ModelSamplerHelper class that provides a standard way to create an ABC using inheritance.
- use_suboptimal: bool = False#
- get_utilities(boards, **kwargs)[source]#
Get the utility of the board.
- Parameters:
boards (Iterable[LczeroBoard]) – The boards to evaluate.
- Returns:
The iterable over utilities, legal indices, and log dictionaries.
- Return type:
Iterable[Tuple[torch.Tensor, torch.Tensor, Dict[str, float]]]
- class lczerolens.play.Game[source]#
- gameid: str#
- moves: List[str]#
- book_exit: int | None = None#
- to_boards(n_history=0, skip_book_exit=False, skip_first_n=0, output_dict=True)[source]#
- Parameters:
n_history (int)
skip_book_exit (bool)
skip_first_n (int)
- Return type:
List[Union[Dict[str, Any], lczerolens.board.LczeroBoard]]
- class lczerolens.play.Puzzle[source]#
- puzzle_id: str#
- fen: str#
- initial_move: chess.Move#
- moves: List[chess.Move]#
- rating: int#
- rating_deviation: int#
- popularity: int#
- nb_plays: int#
- themes: List[str]#
- game_url: str#
- opening_tags: List[str]#
- property initial_board: lczerolens.board.LczeroBoard#
- Return type:
- board_move_generator(all_moves=False)[source]#
- Parameters:
all_moves (bool)
- Return type:
Iterable[Tuple[lczerolens.board.LczeroBoard, chess.Move]]
- classmethod evaluate_multiple(puzzles, sampler, all_moves=False, compute_metrics=True, **kwargs)[source]#
- Parameters:
puzzles (Iterable[Puzzle])
sampler (lczerolens.play.sampling.Sampler)
all_moves (bool)
compute_metrics (bool)
- Return type:
Union[Iterable[Dict[str, float]], Iterable[Tuple[torch.Tensor, torch.Tensor, chess.Move]]]
- evaluate(sampler, all_moves=False, **kwargs)[source]#
- Parameters:
sampler (lczerolens.play.sampling.Sampler)
all_moves (bool)
- Return type:
Tuple[float, Optional[float]]