chipiron.players.move_selector.treevalue.tree_manager package

Submodules

chipiron.players.move_selector.treevalue.tree_manager.algorithm_node_tree_manager module

Defining the AlgorithmNodeTreeManager class

class chipiron.players.move_selector.treevalue.tree_manager.algorithm_node_tree_manager.AlgorithmNodeTreeManager(tree_manager: TreeManager, algorithm_node_updater: AlgorithmNodeUpdater, evaluation_queries: EvaluationQueries, node_evaluator: NodeEvaluator | None, index_manager: NodeExplorationIndexManager)[source]

Bases: object

This class that and manages a tree by opening new nodes and updating the values and indexes on the nodes. It wraps around the Tree Manager class as it has a tree_manager as member and adds functionality as this handles trees with nodes that are of the class AlgorithmNode (managing the value for instance)

algorithm_node_updater: AlgorithmNodeUpdater
evaluation_queries: EvaluationQueries
index_manager: NodeExplorationIndexManager
node_evaluator: NodeEvaluator | None
open_instructions(tree: MoveAndValueTree, opening_instructions: node_sel.OpeningInstructions) TreeExpansions[source]
Parameters:
  • tree – the tree object to open

  • opening_instructions – the opening instructions

Returns: the expansions that have been performed

open_node_move(tree: MoveAndValueTree, parent_node: AlgorithmNode, move: int) TreeExpansion[source]
Parameters:
  • tree – the tree to open

  • parent_node – the node to open

  • move – to move to open with

Returns: the tree expansions

print_best_line(tree: MoveAndValueTree) None[source]

Prints the best line of moves based on the minmax evaluation of the tree.

Parameters:

tree (trees.MoveAndValueTree) – The tree containing the moves and their minmax evaluations.

print_some_stats(tree: MoveAndValueTree) None[source]

Prints statistics about the given tree.

Parameters:

tree (trees.MoveAndValueTree) – The tree to print statistics for.

Returns:

None

test_count(tree: MoveAndValueTree) None[source]

Test the count of nodes in the tree.

Parameters:

tree (trees.MoveAndValueTree) – The tree to be tested.

Returns:

None

test_the_tree(tree: MoveAndValueTree) None[source]

Test the given tree by performing various tests on its nodes.

Parameters:

tree (trees.MoveAndValueTree) – The tree to be tested.

Returns:

None

tree_manager: TreeManager
update_backward(tree_expansions: TreeExpansions) None[source]

Updates the algorithm node tree in a backward manner based on the given tree expansions.

Parameters:

tree_expansions (TreeExpansions) – The tree expansions used to update the algorithm node tree.

Returns:

None

update_indices(tree: MoveAndValueTree) None[source]

Updates the indices of the nodes in the given tree.

Parameters:

tree (trees.MoveAndValueTree) – The tree whose indices need to be updated.

Returns:

None

update_node(node_to_update: AlgorithmNode, update_instructions: UpdateInstructionsTowardsOneParentNode) UpdateInstructionsTowardsMultipleNodes[source]

Updates the given node with the provided update instructions.

Parameters:
  • node_to_update (AlgorithmNode) – The node to be updated.

  • update_instructions (UpdateInstructions) – The instructions for updating the node.

Returns:

A batch of update instructions for the parent nodes of the updated node.

Return type:

UpdateInstructionsBatch

chipiron.players.move_selector.treevalue.tree_manager.factory module

This module provides a factory function for creating an AlgorithmNodeTreeManager object.

The AlgorithmNodeTreeManager is responsible for managing the tree structure of algorithm nodes, performing updates on the nodes, and handling evaluation queries.

chipiron.players.move_selector.treevalue.tree_manager.factory.create_algorithm_node_tree_manager(node_evaluator: NodeEvaluator | None, algorithm_node_factory: AlgorithmNodeFactory, index_computation: IndexComputationType | None, index_updater: IndexUpdater | None) AlgorithmNodeTreeManager[source]

Create an AlgorithmNodeTreeManager object.

Parameters:
  • node_evaluator – The NodeEvaluator object used for evaluating nodes in the tree.

  • algorithm_node_factory – The AlgorithmNodeFactory object used for creating algorithm nodes.

  • index_computation – The type of index computation to be used.

  • index_updater – The IndexUpdater object used for updating the indices.

Returns:

An AlgorithmNodeTreeManager object.

chipiron.players.move_selector.treevalue.tree_manager.tree_expander module

This module contains classes related to tree expansion in a chess game.

class chipiron.players.move_selector.treevalue.tree_manager.tree_expander.TreeExpansion(child_node: ITreeNode[Any], parent_node: ITreeNode[Any] | None, board_modifications: BoardModificationP | None, creation_child_node: bool, move: int | None)[source]

Bases: object

Represents an expansion of a tree in a chess game.

child_node

The child node created during the expansion.

Type:

node.ITreeNode

parent_node

The parent node of the child node. None if it’s the root node.

Type:

node.ITreeNode | None

board_modifications

The modifications made to the chess board during the expansion.

Type:

board_mod.BoardModification | None

creation_child_node

Indicates whether the child node was created during the expansion.

Type:

bool

move

the move from parent to child node.

Type:

chess.Move

board_modifications: BoardModificationP | None
child_node: ITreeNode[Any]
creation_child_node: bool
move: int | None
parent_node: ITreeNode[Any] | None
class chipiron.players.move_selector.treevalue.tree_manager.tree_expander.TreeExpansions(expansions_with_node_creation: ~typing.List[~chipiron.players.move_selector.treevalue.tree_manager.tree_expander.TreeExpansion] = <factory>, expansions_without_node_creation: ~typing.List[~chipiron.players.move_selector.treevalue.tree_manager.tree_expander.TreeExpansion] = <factory>)[source]

Bases: object

Represents a collection of tree expansions in a chess game.

expansions_with_node_creation

List of expansions where child nodes were created.

Type:

List[TreeExpansion]

expansions_without_node_creation

List of expansions where child nodes were not created.

Type:

List[TreeExpansion]

add(tree_expansion: TreeExpansion) None[source]

Adds a tree expansion to the collection.

Parameters:

tree_expansion (TreeExpansion) – The tree expansion to add.

add_connection(tree_expansion: TreeExpansion) None[source]

Adds a tree expansion without a created child node to the collection.

Parameters:

tree_expansion (TreeExpansion) – The tree expansion to add.

add_creation(tree_expansion: TreeExpansion) None[source]

Adds a tree expansion with a created child node to the collection.

Parameters:

tree_expansion (TreeExpansion) – The tree expansion to add.

expansions_with_node_creation: List[TreeExpansion]
expansions_without_node_creation: List[TreeExpansion]

chipiron.players.move_selector.treevalue.tree_manager.tree_manager module

This module contains the TreeManager class, which is responsible for managing a tree by opening new nodes and updating the values and indexes on the nodes.

class chipiron.players.move_selector.treevalue.tree_manager.tree_manager.TreeManager(node_factory: TreeNodeFactory[ITreeNode[Any]])[source]

Bases: object

This class manages a tree by opening new nodes and updating the values and indexes on the nodes.

node_factory: TreeNodeFactory[ITreeNode[Any]]
open_instructions(tree: MoveAndValueTree, opening_instructions: OpeningInstructions) TreeExpansions[source]

Opening multiple nodes based on the opening instructions.

Parameters:
  • tree – The tree object.

  • opening_instructions – The opening instructions.

Returns:

The tree expansions that have been performed.

open_node(tree: MoveAndValueTree, parent_node: ITreeNode[Any], board: IBoard, modifications: BoardModificationP | None, move: int) TreeExpansion[source]

Opening a Node that contains a board given the modifications. Checks if the new node needs to be created or if the new_board already existed in the tree

(was reached from a different serie of move)

Parameters:
  • tree – The tree object.

  • parent_node – The parent node that we want to expand.

  • board – The board object that is a move forward compared to the board in the parent node

  • modifications – The board modifications.

  • move – The move to play to expand the node.

Returns:

The tree expansion object.

open_node_move(tree: MoveAndValueTree, parent_node: ITreeNode[Any], move: int) TreeExpansion[source]

Opening a Node that contains a board following a move.

Parameters:
  • tree – The tree object.

  • parent_node – The parent node that we want to expand.

  • move – The move to play to expand the node.

Returns:

The tree expansion object.

print_best_line(tree: MoveAndValueTree) None[source]

Print the best line in the tree.

Parameters:

tree – The tree object.

print_some_stats(tree: MoveAndValueTree) None[source]

Print some statistics about the tree.

Parameters:

tree – The tree object.

test_count(tree: MoveAndValueTree) None[source]

Test the count of nodes in the tree.

Parameters:

tree – The tree object.

Module contents

This module provides functionality for managing algorithm node trees.

The module includes classes for creating and managing algorithm node tree managers, expanding tree structures, and managing tree expansions.

Classes: - AlgorithmNodeTreeManager: A class for managing algorithm node trees. - TreeManager: A class for managing tree structures. - TreeExpansion: A class for representing a single tree expansion. - TreeExpansions: A class for managing multiple tree expansions.

Functions: - create_algorithm_node_tree_manager: A function for creating an algorithm node tree manager.

class chipiron.players.move_selector.treevalue.tree_manager.AlgorithmNodeTreeManager(tree_manager: TreeManager, algorithm_node_updater: AlgorithmNodeUpdater, evaluation_queries: EvaluationQueries, node_evaluator: NodeEvaluator | None, index_manager: NodeExplorationIndexManager)[source]

Bases: object

This class that and manages a tree by opening new nodes and updating the values and indexes on the nodes. It wraps around the Tree Manager class as it has a tree_manager as member and adds functionality as this handles trees with nodes that are of the class AlgorithmNode (managing the value for instance)

algorithm_node_updater: AlgorithmNodeUpdater
evaluation_queries: EvaluationQueries
index_manager: NodeExplorationIndexManager
node_evaluator: NodeEvaluator | None
open_instructions(tree: MoveAndValueTree, opening_instructions: node_sel.OpeningInstructions) TreeExpansions[source]
Parameters:
  • tree – the tree object to open

  • opening_instructions – the opening instructions

Returns: the expansions that have been performed

open_node_move(tree: MoveAndValueTree, parent_node: AlgorithmNode, move: int) TreeExpansion[source]
Parameters:
  • tree – the tree to open

  • parent_node – the node to open

  • move – to move to open with

Returns: the tree expansions

print_best_line(tree: MoveAndValueTree) None[source]

Prints the best line of moves based on the minmax evaluation of the tree.

Parameters:

tree (trees.MoveAndValueTree) – The tree containing the moves and their minmax evaluations.

print_some_stats(tree: MoveAndValueTree) None[source]

Prints statistics about the given tree.

Parameters:

tree (trees.MoveAndValueTree) – The tree to print statistics for.

Returns:

None

test_count(tree: MoveAndValueTree) None[source]

Test the count of nodes in the tree.

Parameters:

tree (trees.MoveAndValueTree) – The tree to be tested.

Returns:

None

test_the_tree(tree: MoveAndValueTree) None[source]

Test the given tree by performing various tests on its nodes.

Parameters:

tree (trees.MoveAndValueTree) – The tree to be tested.

Returns:

None

tree_manager: TreeManager
update_backward(tree_expansions: TreeExpansions) None[source]

Updates the algorithm node tree in a backward manner based on the given tree expansions.

Parameters:

tree_expansions (TreeExpansions) – The tree expansions used to update the algorithm node tree.

Returns:

None

update_indices(tree: MoveAndValueTree) None[source]

Updates the indices of the nodes in the given tree.

Parameters:

tree (trees.MoveAndValueTree) – The tree whose indices need to be updated.

Returns:

None

update_node(node_to_update: AlgorithmNode, update_instructions: UpdateInstructionsTowardsOneParentNode) UpdateInstructionsTowardsMultipleNodes[source]

Updates the given node with the provided update instructions.

Parameters:
  • node_to_update (AlgorithmNode) – The node to be updated.

  • update_instructions (UpdateInstructions) – The instructions for updating the node.

Returns:

A batch of update instructions for the parent nodes of the updated node.

Return type:

UpdateInstructionsBatch

class chipiron.players.move_selector.treevalue.tree_manager.TreeExpansion(child_node: ITreeNode[Any], parent_node: ITreeNode[Any] | None, board_modifications: BoardModificationP | None, creation_child_node: bool, move: int | None)[source]

Bases: object

Represents an expansion of a tree in a chess game.

child_node

The child node created during the expansion.

Type:

node.ITreeNode

parent_node

The parent node of the child node. None if it’s the root node.

Type:

node.ITreeNode | None

board_modifications

The modifications made to the chess board during the expansion.

Type:

board_mod.BoardModification | None

creation_child_node

Indicates whether the child node was created during the expansion.

Type:

bool

move

the move from parent to child node.

Type:

chess.Move

board_modifications: BoardModificationP | None
child_node: ITreeNode[Any]
creation_child_node: bool
move: int | None
parent_node: ITreeNode[Any] | None
class chipiron.players.move_selector.treevalue.tree_manager.TreeExpansions(expansions_with_node_creation: ~typing.List[~chipiron.players.move_selector.treevalue.tree_manager.tree_expander.TreeExpansion] = <factory>, expansions_without_node_creation: ~typing.List[~chipiron.players.move_selector.treevalue.tree_manager.tree_expander.TreeExpansion] = <factory>)[source]

Bases: object

Represents a collection of tree expansions in a chess game.

expansions_with_node_creation

List of expansions where child nodes were created.

Type:

List[TreeExpansion]

expansions_without_node_creation

List of expansions where child nodes were not created.

Type:

List[TreeExpansion]

add(tree_expansion: TreeExpansion) None[source]

Adds a tree expansion to the collection.

Parameters:

tree_expansion (TreeExpansion) – The tree expansion to add.

add_connection(tree_expansion: TreeExpansion) None[source]

Adds a tree expansion without a created child node to the collection.

Parameters:

tree_expansion (TreeExpansion) – The tree expansion to add.

add_creation(tree_expansion: TreeExpansion) None[source]

Adds a tree expansion with a created child node to the collection.

Parameters:

tree_expansion (TreeExpansion) – The tree expansion to add.

expansions_with_node_creation: List[TreeExpansion]
expansions_without_node_creation: List[TreeExpansion]
class chipiron.players.move_selector.treevalue.tree_manager.TreeManager(node_factory: TreeNodeFactory[ITreeNode[Any]])[source]

Bases: object

This class manages a tree by opening new nodes and updating the values and indexes on the nodes.

node_factory: TreeNodeFactory[ITreeNode[Any]]
open_instructions(tree: MoveAndValueTree, opening_instructions: OpeningInstructions) TreeExpansions[source]

Opening multiple nodes based on the opening instructions.

Parameters:
  • tree – The tree object.

  • opening_instructions – The opening instructions.

Returns:

The tree expansions that have been performed.

open_node(tree: MoveAndValueTree, parent_node: ITreeNode[Any], board: IBoard, modifications: BoardModificationP | None, move: int) TreeExpansion[source]

Opening a Node that contains a board given the modifications. Checks if the new node needs to be created or if the new_board already existed in the tree

(was reached from a different serie of move)

Parameters:
  • tree – The tree object.

  • parent_node – The parent node that we want to expand.

  • board – The board object that is a move forward compared to the board in the parent node

  • modifications – The board modifications.

  • move – The move to play to expand the node.

Returns:

The tree expansion object.

open_node_move(tree: MoveAndValueTree, parent_node: ITreeNode[Any], move: int) TreeExpansion[source]

Opening a Node that contains a board following a move.

Parameters:
  • tree – The tree object.

  • parent_node – The parent node that we want to expand.

  • move – The move to play to expand the node.

Returns:

The tree expansion object.

print_best_line(tree: MoveAndValueTree) None[source]

Print the best line in the tree.

Parameters:

tree – The tree object.

print_some_stats(tree: MoveAndValueTree) None[source]

Print some statistics about the tree.

Parameters:

tree – The tree object.

test_count(tree: MoveAndValueTree) None[source]

Test the count of nodes in the tree.

Parameters:

tree – The tree object.

chipiron.players.move_selector.treevalue.tree_manager.create_algorithm_node_tree_manager(node_evaluator: NodeEvaluator | None, algorithm_node_factory: AlgorithmNodeFactory, index_computation: IndexComputationType | None, index_updater: IndexUpdater | None) AlgorithmNodeTreeManager[source]

Create an AlgorithmNodeTreeManager object.

Parameters:
  • node_evaluator – The NodeEvaluator object used for evaluating nodes in the tree.

  • algorithm_node_factory – The AlgorithmNodeFactory object used for creating algorithm nodes.

  • index_computation – The type of index computation to be used.

  • index_updater – The IndexUpdater object used for updating the indices.

Returns:

An AlgorithmNodeTreeManager object.