lczerolens.play.sampling#

Classes for playing.

class lczerolens.play.sampling.ModelSampler(model: lczerolens.model.LczeroModel, 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)#

Bases: Sampler

choose_move(board: LczeroBoard, utility: Tensor, legal_indices: Tensor) Move#

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: Iterable[LczeroBoard], **kwargs) Iterable[Tuple[Tensor, Tensor, Dict[str, float]]]#

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.sampling.PolicySampler(model: lczerolens.model.LczeroModel, 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, use_suboptimal: bool = False)#

Bases: ModelSampler

get_utilities(boards: Iterable[LczeroBoard], **kwargs) Iterable[Tuple[Tensor, Tensor, Dict[str, float]]]#

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.sampling.RandomSampler#

Bases: Sampler

get_utilities(boards: Iterable[LczeroBoard], **kwargs) Iterable[Tuple[Tensor, Tensor, Dict[str, float]]]#

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.sampling.Sampler#

Bases: ABC

choose_move(board: LczeroBoard, utility: Tensor, legal_indices: Tensor) Move#

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: Iterable[LczeroBoard], **kwargs) Iterable[Tuple[Move, Dict[str, float]]]#

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]]]

abstract get_utilities(boards: Iterable[LczeroBoard], **kwargs) Iterable[Tuple[Tensor, Tensor, Dict[str, float]]]#

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.sampling.SelfPlay(white: Sampler, black: Sampler)#

Bases: object

A class for generating games.

play(board: LczeroBoard | None = None, max_moves: int = 100, to_play: bool = True, report_fn: Callable[[dict, bool], None] | None = None, white_kwargs: Dict | None = None, black_kwargs: Dict | None = None)#

Plays a game.