chipiron.players.move_selector.treevalue.node_selector package
Subpackages
- chipiron.players.move_selector.treevalue.node_selector.recurzipf package
- chipiron.players.move_selector.treevalue.node_selector.sequool package
- Submodules
- chipiron.players.move_selector.treevalue.node_selector.sequool.factory module
- chipiron.players.move_selector.treevalue.node_selector.sequool.sequool module
- Module contents
- chipiron.players.move_selector.treevalue.node_selector.uniform package
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:
objectArguments 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:
objectMoveExplorer 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,EnumEnumeration class representing the sampling priorities for move exploration.
- Variables:
NO_PRIORITY (str) – No priority for move sampling.
PRIORITY_BEST (str) – Priority for the best move.
PRIORITY_TWO_BEST (str) – Priority for the two best moves.
- 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:
MoveExplorerZipfMoveExplorer 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:
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:
ProtocolProtocol 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:
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:
objectRepresents 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,EnumEnumeration 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:
objectRepresents an opening instruction for a specific node in the game tree.
- move_to_play: int
- 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:
objectRepresents a collection of opening instructions.
- __bool__() bool[source]
Checks if the collection is non-empty.
- Returns:
True if the collection is non-empty, False otherwise.
- __getitem__(key: Any) OpeningInstruction[source]
Retrieves an opening instruction from the collection.
- Parameters:
key – The key for the opening instruction.
- Returns:
The opening instruction.
- __iter__() Iterator[Any][source]
Returns an iterator over the keys of the opening instructions.
- Returns:
An iterator over the keys.
- __len__() int[source]
Returns the number of opening instructions in the collection.
- Returns:
The number of opening instructions.
- __setitem__(key: Any, value: OpeningInstruction) None[source]
Sets an opening instruction in the collection.
- Parameters:
key – The key for the opening instruction.
value – The opening instruction.
- 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.
- 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:
objectRepresents an opening instructor that provides opening instructions based on a specific opening type.
- 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:
EnumRepresents 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:
ProtocolProtocol 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:
- class chipiron.players.move_selector.treevalue.node_selector.NodeSelectorArgs(type: NodeSelectorType)[source]
Bases:
objectRepresents 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,EnumEnumeration 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:
objectRepresents an opening instruction for a specific node in the game tree.
- move_to_play: int
- 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:
objectRepresents a collection of opening instructions.
- __bool__() bool[source]
Checks if the collection is non-empty.
- Returns:
True if the collection is non-empty, False otherwise.
- __getitem__(key: Any) OpeningInstruction[source]
Retrieves an opening instruction from the collection.
- Parameters:
key – The key for the opening instruction.
- Returns:
The opening instruction.
- __iter__() Iterator[Any][source]
Returns an iterator over the keys of the opening instructions.
- Returns:
An iterator over the keys.
- __len__() int[source]
Returns the number of opening instructions in the collection.
- Returns:
The number of opening instructions.
- __setitem__(key: Any, value: OpeningInstruction) None[source]
Sets an opening instruction in the collection.
- Parameters:
key – The key for the opening instruction.
value – The opening instruction.
- 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.
- 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:
EnumRepresents 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