chipiron.players.move_selector.treevalue.node_selector package

Subpackages

Submodules

chipiron.players.move_selector.treevalue.node_selector.factory module

Factory to build node selectors

class chipiron.players.move_selector.treevalue.node_selector.factory.UniformArgs(type: ~typing.Literal[<NodeSelectorType.Uniform: 'Uniform'>])[source]

Bases: object

Arguments for the Uniform node selector.

type: Uniform: 'Uniform'>]
chipiron.players.move_selector.treevalue.node_selector.factory.create(args: RecurZipfBaseArgs | SequoolArgs | UniformArgs, opening_instructor: OpeningInstructor, random_generator: Random) NodeSelector[source]

Creation of a node selector

chipiron.players.move_selector.treevalue.node_selector.move_explorer module

This module contains the MoveExplorer class and its subclasses. MoveExplorer is responsible for exploring moves in a game tree.

class chipiron.players.move_selector.treevalue.node_selector.move_explorer.MoveExplorer(priority_sampling: SamplingPriorities)[source]

Bases: object

MoveExplorer is responsible for exploring moves in a game tree. It provides a method to sample a child node to explore.

priority_sampling: SamplingPriorities
class chipiron.players.move_selector.treevalue.node_selector.move_explorer.SamplingPriorities(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: str, Enum

Enumeration class representing the sampling priorities for move exploration.

NO_PRIORITY

No priority for move sampling.

Type:

str

PRIORITY_BEST

Priority for the best move.

Type:

str

PRIORITY_TWO_BEST

Priority for the two best moves.

Type:

str

NO_PRIORITY = 'no_priority'
PRIORITY_BEST = 'priority_best'
PRIORITY_TWO_BEST = 'priority_two_best'
class chipiron.players.move_selector.treevalue.node_selector.move_explorer.ZipfMoveExplorer(priority_sampling: SamplingPriorities, random_generator: Random)[source]

Bases: MoveExplorer

ZipfMoveExplorer is a subclass of MoveExplorer that uses the Zipf distribution for sampling.

sample_move_to_explore(tree_node_to_sample_from: AlgorithmNode) int[source]

Samples a child node to explore from the given tree node.

Parameters:

tree_node_to_sample_from (AlgorithmNode) – The tree node to sample from.

Returns:

The sampled child node to explore.

Return type:

AlgorithmNode

chipiron.players.move_selector.treevalue.node_selector.node_selector module

This module contains the definition of the NodeSelector class and related types.

class chipiron.players.move_selector.treevalue.node_selector.node_selector.NodeSelector(*args, **kwargs)[source]

Bases: Protocol

Protocol for Node Selectors.

choose_node_and_move_to_open(tree: MoveAndValueTree, latest_tree_expansions: tree_man.TreeExpansions) OpeningInstructions[source]

Selects a node from the given tree and returns the instructions to move to an open position.

Parameters:
  • tree (MoveAndValueTree) – The tree containing the moves and their corresponding values.

  • latest_tree_expansions (tree_man.TreeExpansions) – The latest expansions of the tree.

Returns:

The instructions to move to an open position.

Return type:

OpeningInstructions

class chipiron.players.move_selector.treevalue.node_selector.node_selector.NodeSelectorState[source]

Bases: object

Node Selector State

chipiron.players.move_selector.treevalue.node_selector.node_selector_args module

This module defines the NodeSelectorArgs class, which represents the arguments for a node selector.

The NodeSelectorArgs class is a dataclass that contains a single attribute: - type: The type of the node selector, represented by the NodeSelectorType enum.

Example usage:

args = NodeSelectorArgs(type=NodeSelectorType.BEST)

class chipiron.players.move_selector.treevalue.node_selector.node_selector_args.NodeSelectorArgs(type: NodeSelectorType)[source]

Bases: object

Represents the arguments for a node selector.

type: NodeSelectorType

chipiron.players.move_selector.treevalue.node_selector.node_selector_types module

This module defines the NodeSelectorType enumeration, which represents the types of node selectors.

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

Bases: str, Enum

Enumeration representing the types of node selectors.

RecurZipfBase = 'RecurZipfBase'
Sequool = 'Sequool'
Uniform = 'Uniform'

chipiron.players.move_selector.treevalue.node_selector.notations_and_statics module

This module contains functions for selecting elements based on Zipf distribution.

Zipf distribution is a discrete probability distribution that models the occurrence of elements in a dataset. The functions in this module provide methods for selecting elements based on their rank and value.

chipiron.players.move_selector.treevalue.node_selector.notations_and_statics.zipf_picks(ranks_values: dict[int, int | float], random_generator: Random, shift: bool = False, random_pick: bool = False) int[source]

Selects an element based on its rank and value.

Parameters:
  • ranks_values (dict[int, int | float]) – A dictionary containing the ranks and values of the elements.

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

  • shift (bool, optional) – Whether to shift the ranks. Defaults to False.

  • random_pick (bool, optional) – Whether to perform a random pick. Defaults to False.

Returns:

The rank of the selected element.

Return type:

int

Raises:

Exception – If random_pick is True (not implemented yet).

chipiron.players.move_selector.treevalue.node_selector.notations_and_statics.zipf_picks_random(ordered_list_elements: list[T], random_generator: Random) T[source]

Selects a random element from an ordered list based on Zipf distribution.

Parameters:
  • ordered_list_elements (list[T]) – A list of elements.

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

Returns:

The selected element.

Return type:

T

Raises:

AssertionError – If the length of the list is 0.

chipiron.players.move_selector.treevalue.node_selector.opening_instructions module

This module contains classes and functions related to opening instructions in a chess game.

class chipiron.players.move_selector.treevalue.node_selector.opening_instructions.OpeningInstruction(node_to_open: ITreeNode[Any], move_to_play: int)[source]

Bases: object

Represents an opening instruction for a specific node in the game tree.

move_to_play: int
node_to_open: ITreeNode[Any]
print_info() None[source]

Prints information about the opening instruction.

class chipiron.players.move_selector.treevalue.node_selector.opening_instructions.OpeningInstructions(dictionary: dict[Any, chipiron.players.move_selector.treevalue.node_selector.opening_instructions.OpeningInstruction] | None = None)[source]

Bases: object

Represents a collection of opening instructions.

batch: dict[Any, chipiron.players.move_selector.treevalue.node_selector.opening_instructions.OpeningInstruction]
items() ItemsView[Any, OpeningInstruction][source]

Returns a view of the items (key-value pairs) in the collection.

Returns:

A view of the items.

merge(another_opening_instructions_batch: Self) None[source]

Merges another batch of opening instructions into the current collection.

Parameters:

another_opening_instructions_batch – Another OpeningInstructions object.

pop_items(how_many: int, popped: Self) None[source]

Pops a specified number of opening instructions from the collection.

Parameters:
  • how_many – The number of opening instructions to pop.

  • popped – An OpeningInstructions object to store the popped instructions.

print_info() None[source]

Prints information about the opening instructions in the collection.

values() ValuesView[OpeningInstruction][source]

Returns a view of the values in the collection.

Returns:

A view of the values.

class chipiron.players.move_selector.treevalue.node_selector.opening_instructions.OpeningInstructor(opening_type: OpeningType, random_generator: Random)[source]

Bases: object

Represents an opening instructor that provides opening instructions based on a specific opening type.

all_moves_to_open(node_to_open: ITreeNode[Any]) list[int][source]

Returns a list of all possible moves to open from a given node.

Parameters:

node_to_open – The node to open.

Returns:

A list of chess moves.

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

Bases: Enum

Represents the type of opening to use.

AllChildren = 'all_children'
chipiron.players.move_selector.treevalue.node_selector.opening_instructions.create_instructions_to_open_all_moves(moves_to_play: list[int], node_to_open: ITreeNode[Any]) OpeningInstructions[source]

Creates opening instructions for all possible moves to play from a given node.

Parameters:
  • moves_to_play – A list of chess moves.

  • node_to_open – The node to open.

Returns:

An OpeningInstructions object containing the opening instructions.

Module contents

This module provides classes and functions for selecting nodes in a tree structure.

The module includes the following components: - create: A factory function for creating node selectors. - AllNodeSelectorArgs: A class that represents all possible arguments for node selectors. - NodeSelector: A class that represents a node selector. - NodeSelectorArgs: A class that represents the arguments for a node selector. - NodeSelectorType: An enumeration of different types of node selectors. - OpeningInstructions: A class that represents opening instructions for node selectors. - OpeningInstruction: A class that represents an opening instruction for node selectors. - OpeningType: An enumeration of different types of opening instructions.

To use this module, import it and use the provided classes and functions as needed.

class chipiron.players.move_selector.treevalue.node_selector.NodeSelector(*args, **kwargs)[source]

Bases: Protocol

Protocol for Node Selectors.

choose_node_and_move_to_open(tree: MoveAndValueTree, latest_tree_expansions: tree_man.TreeExpansions) OpeningInstructions[source]

Selects a node from the given tree and returns the instructions to move to an open position.

Parameters:
  • tree (MoveAndValueTree) – The tree containing the moves and their corresponding values.

  • latest_tree_expansions (tree_man.TreeExpansions) – The latest expansions of the tree.

Returns:

The instructions to move to an open position.

Return type:

OpeningInstructions

class chipiron.players.move_selector.treevalue.node_selector.NodeSelectorArgs(type: NodeSelectorType)[source]

Bases: object

Represents the arguments for a node selector.

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

Bases: str, Enum

Enumeration representing the types of node selectors.

RecurZipfBase = 'RecurZipfBase'
Sequool = 'Sequool'
Uniform = 'Uniform'
class chipiron.players.move_selector.treevalue.node_selector.OpeningInstruction(node_to_open: ITreeNode[Any], move_to_play: int)[source]

Bases: object

Represents an opening instruction for a specific node in the game tree.

move_to_play: int
node_to_open: ITreeNode[Any]
print_info() None[source]

Prints information about the opening instruction.

class chipiron.players.move_selector.treevalue.node_selector.OpeningInstructions(dictionary: dict[Any, chipiron.players.move_selector.treevalue.node_selector.opening_instructions.OpeningInstruction] | None = None)[source]

Bases: object

Represents a collection of opening instructions.

batch: dict[Any, chipiron.players.move_selector.treevalue.node_selector.opening_instructions.OpeningInstruction]
items() ItemsView[Any, OpeningInstruction][source]

Returns a view of the items (key-value pairs) in the collection.

Returns:

A view of the items.

merge(another_opening_instructions_batch: Self) None[source]

Merges another batch of opening instructions into the current collection.

Parameters:

another_opening_instructions_batch – Another OpeningInstructions object.

pop_items(how_many: int, popped: Self) None[source]

Pops a specified number of opening instructions from the collection.

Parameters:
  • how_many – The number of opening instructions to pop.

  • popped – An OpeningInstructions object to store the popped instructions.

print_info() None[source]

Prints information about the opening instructions in the collection.

values() ValuesView[OpeningInstruction][source]

Returns a view of the values in the collection.

Returns:

A view of the values.

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

Bases: Enum

Represents the type of opening to use.

AllChildren = 'all_children'
chipiron.players.move_selector.treevalue.node_selector.create(args: RecurZipfBaseArgs | SequoolArgs | UniformArgs, opening_instructor: OpeningInstructor, random_generator: Random) NodeSelector[source]

Creation of a node selector