algorhino-anemone 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: algorhino-anemone
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: anemone searches trees
5
5
  Author-email: Victor Gabillon <victorgabillon@gmail.com>
6
6
  License-Expression: GPL-3.0-only
@@ -12,8 +12,8 @@ Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.13
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
- Requires-Dist: valanga
16
- Requires-Dist: atomheart
15
+ Requires-Dist: valanga>=0.1.4
16
+ Requires-Dist: atomheart>=0.1.2
17
17
  Requires-Dist: rich
18
18
  Requires-Dist: sortedcollections>=2.1.0
19
19
  Requires-Dist: graphviz
@@ -1,10 +1,10 @@
1
- algorhino_anemone-0.1.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
1
+ algorhino_anemone-0.1.4.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
2
2
  anemone/__init__.py,sha256=iKX9OGJxbyIqe9Fy-xxZY6sdH7WcG4RFyPR0WBai7Ls,942
3
- anemone/basics.py,sha256=jMKY9mFLbbMZ_xNvtBVlbZI_vP15rg2tUGUf9ZQ-9tw,1023
4
- anemone/factory.py,sha256=Nmx84UrSqED3R9891XoBTX56jKlINvZn4DLYduSbHgo,6020
3
+ anemone/basics.py,sha256=plCN-SfAcCj4TPDVD3r19Q36UFjiKmNvuEyPH0kQ7Qs,574
4
+ anemone/factory.py,sha256=seGZuwQNzfdSV7moN-kwqDGp0EfEY0srS0awHAR7mvk,6044
5
5
  anemone/state_transition.py,sha256=fxvHZOYRtWV5ExXRIoehdRg9qV6zhgiE5uiCeOc80Dc,1418
6
- anemone/tree_and_value_branch_selector.py,sha256=bervTIx03h79g-Qu1npGpcA5YlSzZKRk0xA86l69jX4,3480
7
- anemone/tree_exploration.py,sha256=Fb6mNw0UxbaaFtbBAhxjjKJQbClbRPzhrEG2pWHQkjY,10378
6
+ anemone/tree_and_value_branch_selector.py,sha256=9m7cWzw_nsFKiqZ4l7B2fz0lZ9HZ2NUNH2flZpaaQvQ,3479
7
+ anemone/tree_exploration.py,sha256=cg1iTp3j9p9jUNjm07ogbflX8VC15AV8GEhGz3g1YNU,10529
8
8
  anemone/indices/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  anemone/indices/index_manager/__init__.py,sha256=P49ofGrnP_Nfmv63Rg_-Zvwn5NFvFFDQ3MD3GMeWNWw,515
10
10
  anemone/indices/index_manager/factory.py,sha256=Fti6PTnLOEg0g5cqqRBMsmGGNZw6uVFiKpjv0B766qE,1783
@@ -17,12 +17,12 @@ anemone/nn/torch_evaluator.py,sha256=cXcaldEI5S8JE1Yy9aNUamVEK3DPsPmBmGeUi9611zU
17
17
  anemone/node_evaluation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  anemone/node_evaluation/node_direct_evaluation/__init__.py,sha256=2_YwJ3oe0KBfIc3Hs-FLz093RLZsTG-VaNmecLceoiY,898
19
19
  anemone/node_evaluation/node_direct_evaluation/factory.py,sha256=lpFmBJkIGAnar5-pQ1vMze9jUFKFchp5Pg2S8eK-ABM,470
20
- anemone/node_evaluation/node_direct_evaluation/node_direct_evaluator.py,sha256=jM-gkNeaOOXBXS4JNAAVeXJ5K2bAOppQwV7wpTBX1Ck,5787
21
- anemone/node_evaluation/node_tree_evaluation/node_minmax_evaluation.py,sha256=npqy9r7ZKHGMJsDhSY7bZZbRvakwoTyABpwQOVTQ-ww,35126
22
- anemone/node_evaluation/node_tree_evaluation/node_tree_evaluation.py,sha256=-fiuTO0nWKKiKWAdgFi-L8kKxIjH0A_0yeUKrp4fk34,4260
20
+ anemone/node_evaluation/node_direct_evaluation/node_direct_evaluator.py,sha256=EU9idWUGVjVBclnSiGE-3OZvvV9a7nhUZKTJCnOBhqw,5787
21
+ anemone/node_evaluation/node_tree_evaluation/node_minmax_evaluation.py,sha256=JuD1yg15l-FONW85s3rkp9mD1a1Y_kCZoiqI4-DGlg0,35127
22
+ anemone/node_evaluation/node_tree_evaluation/node_tree_evaluation.py,sha256=fHAKN_8vriERrfKfr_qDH-y7El6HBYFXHOe9eFFCDUw,4260
23
23
  anemone/node_evaluation/node_tree_evaluation/node_tree_evaluation_factory.py,sha256=UY1glqflqMOqOPAHhtuzJ8QhGOp55Y9InqdhCMt9KJ8,1279
24
24
  anemone/node_factory/__init__.py,sha256=qhbX58hu8-TdFof5zo3ibfPFvF-OWNSgJf3RDMrtyTQ,553
25
- anemone/node_factory/algorithm_node_factory.py,sha256=eHsyZ6_no8i9ACfZV8VSKefV3kXiQHvdMNEighDn8Lc,3947
25
+ anemone/node_factory/algorithm_node_factory.py,sha256=DfFRIJAdycwJ1CROXVdvEbyJAmVzjN_UBqF3BhT5pIs,3994
26
26
  anemone/node_factory/base.py,sha256=t_immiv-BDrPeQTUiOqvZLSlUq0zA2IbnM5Rweqv_n8,2134
27
27
  anemone/node_selector/__init__.py,sha256=DThR5UV-4WZG4PT5Lo0RPv9_P83ixFGfOSFoGihKtuA,1320
28
28
  anemone/node_selector/branch_explorer.py,sha256=3ywYkJe2R1Dg5nhmDXCgyhex85bT39Ql7ifRY--9Z_A,2677
@@ -40,23 +40,23 @@ anemone/node_selector/sequool/sequool.py,sha256=NSGwIQk8KxD-TSzdw2LvFIOPUlNfQX8O
40
40
  anemone/node_selector/uniform/__init__.py,sha256=fRGC0FL_fnXXeNoj3QeMQmNoESrFfSDaiHp-zHpF_zw,366
41
41
  anemone/node_selector/uniform/uniform.py,sha256=Frxyik7Vx2-vF0CcMWclPqymj7XEl08nILtMv4Wjxj8,3745
42
42
  anemone/nodes/__init__.py,sha256=XWTr9wZGGX9XHp-bw3zjKfCVdKnNEgVGL1wFWW-ozzI,393
43
- anemone/nodes/itree_node.py,sha256=ywQIvF8LIihf-7p8OgzMjfTg6S39GRbY3u1b4Ka4JoM,3536
44
- anemone/nodes/tree_node.py,sha256=DxsFJw5Y8vromLu-oZL8D5F9aLME4FjI1d8XF9e3Eq8,7728
43
+ anemone/nodes/itree_node.py,sha256=ZXyux7M2BBEGyraUWLHyYeoLgEHvuRgB0JJb-W-Ln_g,3547
44
+ anemone/nodes/tree_node.py,sha256=C9jKzA62ToYhANYjwhS2qPAHti81l-x-p7RmKe6Sb0Q,7739
45
45
  anemone/nodes/tree_traversal.py,sha256=sE9as_8-74bIUuAYNhk2MK6VvlrN1Y3mFExff_HGpQ8,3958
46
46
  anemone/nodes/utils.py,sha256=_NPGFnjzouFMpepyNPw5D0d3999_F3tmJHa0bafwo7M,4501
47
47
  anemone/nodes/algorithm_node/__init__.py,sha256=8cNk3PmDzd22K78YWiO29Mu5A1FCObzPwEfWE1ym6Jk,116
48
- anemone/nodes/algorithm_node/algorithm_node.py,sha256=VzZsLZ0KmRt92me1U_mwATLu_uyVVafTOA-wtugtyms,6517
48
+ anemone/nodes/algorithm_node/algorithm_node.py,sha256=DUJIVM9PdSRndeir9lPe5e9ebiu9lNx27c0z819Rw64,6544
49
49
  anemone/progress_monitor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
50
  anemone/progress_monitor/progress_monitor.py,sha256=ExuvwOntZBwrBjIbNr8ZpeCd2F5s21rsX74FFog7gqY,10896
51
51
  anemone/recommender_rule/__init__.py,sha256=9K73T0bkpvHg0IsQc1OW8QgsUhCNYq9ceqPMkwdqE8c,347
52
- anemone/recommender_rule/recommender_rule.py,sha256=Ck34nf3fw6FZOi-1HR_XJpuEggcCTxGoCJE_ueUNVO4,4587
52
+ anemone/recommender_rule/recommender_rule.py,sha256=yQlIWWWFKJQFSxuDaEBNtUrgDe1PRwNusM2a1ds89hw,4427
53
53
  anemone/search_factory/__init__.py,sha256=ToU88Fa1lBBdf2AYTJ2PNVwWzi5Hzh-78-WOxClVkN4,619
54
54
  anemone/search_factory/search_factory.py,sha256=vCkxJk4cs6i6jjrTrUAsRBtp38N84j_uhyvpYIODoG4,6757
55
55
  anemone/tree_manager/__init__.py,sha256=D3j8emzRNF1fkPTpNUPsXbqAzMM9SyI3Ty_4Y_b2Tas,962
56
56
  anemone/tree_manager/algorithm_node_tree_manager.py,sha256=ekDfS4lfYGP9tNtUGre6DGz0haHi3-MZuUVO-kF0JQU,8801
57
57
  anemone/tree_manager/factory.py,sha256=d10uuf5DtHZ_jKT7Z688Wd3_a7TewwmUywlTeWdUQwc,2679
58
58
  anemone/tree_manager/tree_expander.py,sha256=LpKFDKsOrW0cq09m11aXQZV82s10iyiizQafRBHQ7ts,4041
59
- anemone/tree_manager/tree_manager.py,sha256=n0ck4Z-i0WIiRI5RkqrhnYNFD88B9Uw1cU0Xa_q0LAE,8281
59
+ anemone/tree_manager/tree_manager.py,sha256=QJAKOyln-zPSAwGbcyX3OTnHW-lawshOgwxp69j_sN0,8284
60
60
  anemone/trees/__init__.py,sha256=FtX6ZDfZI7JDjv6IAgKRVytJmafL3Vod3RF7L-bDTWc,269
61
61
  anemone/trees/descendants.py,sha256=bq8GrckFsPpteWr68og4a5KA94hYWn-qrDzC6dDfOKw,27249
62
62
  anemone/trees/factory.py,sha256=GIZcojZzxl5VG6lEpxxF9PV8VZnS-c18xWxg0dza0r8,2180
@@ -76,7 +76,7 @@ anemone/utils/dict_of_numbered_dict_with_pointer_on_max.py,sha256=s5Z-O5mBwJUh4P
76
76
  anemone/utils/logger.py,sha256=bJQ8COqdn5obtbi8TuokQHmdHpp57XRksTmfvCLLfyM,2973
77
77
  anemone/utils/my_value_sorted_dict.py,sha256=LbqtpBSCS7VrUTUChWCsi18IKZj65FkTJREqbl-xSVA,619
78
78
  anemone/utils/small_tools.py,sha256=l9dy5Oqvuvg8qQXqJUfyb3uwBHwVGVrKz6WeTHjyLTk,2766
79
- algorhino_anemone-0.1.2.dist-info/METADATA,sha256=BxqVitC0TFU3tWcoxkf_aSsdefABd1flA9_uYBKkgdM,5677
80
- algorhino_anemone-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
81
- algorhino_anemone-0.1.2.dist-info/top_level.txt,sha256=G1vbB-vAevQVde3UZ5X1_Ysy1_6sJDEueHRi2qcDgrY,8
82
- algorhino_anemone-0.1.2.dist-info/RECORD,,
79
+ algorhino_anemone-0.1.4.dist-info/METADATA,sha256=beVHIe1Er6XUzU7LmxPcJTvD9x9TMCJAOzrfDES-5kw,5691
80
+ algorhino_anemone-0.1.4.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
81
+ algorhino_anemone-0.1.4.dist-info/top_level.txt,sha256=G1vbB-vAevQVde3UZ5X1_Ysy1_6sJDEueHRi2qcDgrY,8
82
+ algorhino_anemone-0.1.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
anemone/basics.py CHANGED
@@ -1,11 +1,8 @@
1
1
  """Basic types and protocols for Anemone."""
2
2
 
3
- from dataclasses import dataclass
4
- from typing import Annotated, Mapping, Protocol
3
+ from typing import Annotated, Protocol
5
4
 
6
- from valanga import BoardEvaluation, BranchKey, Color, HasTurn, State
7
-
8
- from anemone.recommender_rule.recommender_rule import BranchPolicy
5
+ from valanga import Color, HasTurn, State
9
6
 
10
7
  type Seed = Annotated[int, "seed"]
11
8
  type TreeDepth = Annotated[int, "Depth level of a node in a tree structure"]
@@ -17,16 +14,6 @@ class StateWithTurn(State, HasTurn, Protocol):
17
14
  ...
18
15
 
19
16
 
20
- @dataclass(frozen=True, slots=True)
21
- class BranchRecommendation:
22
- """A recommendation for a specific branch in a tree node."""
23
-
24
- branch_key: BranchKey
25
- evaluation: BoardEvaluation | None = None
26
- policy: BranchPolicy | None = None
27
- child_evals: Mapping[BranchKey, BoardEvaluation] | None = None
28
-
29
-
30
17
  class HasBlackAndWhiteTurn(Protocol):
31
18
  """Protocol for state that has black and white turns."""
32
19
 
anemone/factory.py CHANGED
@@ -56,7 +56,8 @@ def create_tree_and_value_branch_selector[StateT: TurnState](
56
56
  args: TreeAndValuePlayerArgs,
57
57
  random_generator: Random,
58
58
  master_state_evaluator: MasterStateEvaluator,
59
- state_representation_factory: RepresentationFactory[ContentRepresentation] | None,
59
+ state_representation_factory: RepresentationFactory[StateT, ContentRepresentation]
60
+ | None,
60
61
  queue_progress_player: Queue[IsDataclass] | None,
61
62
  ) -> TreeAndValueBranchSelector[StateT]:
62
63
  """Convenience constructor using the default minmax tree evaluation.
@@ -85,7 +86,8 @@ def create_tree_and_value_branch_selector_with_tree_eval_factory[StateT: TurnSta
85
86
  args: TreeAndValuePlayerArgs,
86
87
  random_generator: Random,
87
88
  master_state_evaluator: MasterStateEvaluator,
88
- state_representation_factory: RepresentationFactory[ContentRepresentation] | None,
89
+ state_representation_factory: RepresentationFactory[StateT, ContentRepresentation]
90
+ | None,
89
91
  node_tree_evaluation_factory: NodeTreeEvaluationFactory[StateT],
90
92
  queue_progress_player: Queue[IsDataclass] | None,
91
93
  ) -> TreeAndValueBranchSelector[StateT]:
@@ -89,7 +89,7 @@ class MasterStateEvaluator(Protocol):
89
89
  class NodeDirectEvaluator[StateT: State = State]:
90
90
  """
91
91
  The NodeEvaluator class is responsible for evaluating the value of nodes in a tree structure.
92
- It uses a board evaluator and a syzygy evaluator to calculate the value of the nodes.
92
+ It uses a state evaluator and a syzygy evaluator to calculate the value of the nodes.
93
93
  """
94
94
 
95
95
  master_state_evaluator: MasterStateEvaluator
@@ -21,12 +21,12 @@ from random import choice
21
21
  from typing import Any, Protocol, Self, runtime_checkable
22
22
 
23
23
  from valanga import (
24
- BoardEvaluation,
25
24
  BranchKey,
26
25
  Color,
27
26
  FloatyStateEvaluation,
28
27
  ForcedOutcome,
29
28
  OverEvent,
29
+ StateEvaluation,
30
30
  TurnState,
31
31
  )
32
32
 
@@ -140,7 +140,7 @@ class NodeMinmaxEvaluation[
140
140
  return self.value_white_minmax
141
141
 
142
142
  def set_evaluation(self, evaluation: float) -> None:
143
- """sets the evaluation from the board evaluator
143
+ """Set the evaluation from the state evaluator.
144
144
 
145
145
  Args:
146
146
  evaluation (float): The evaluation value to be set.
@@ -874,8 +874,9 @@ class NodeMinmaxEvaluation[
874
874
  best_branches.append(branch_key)
875
875
  return best_branches
876
876
 
877
- def evaluate(self) -> BoardEvaluation:
878
- """Build a BoardEvaluation from current minmax state."""
877
+ def evaluate(self) -> StateEvaluation:
878
+ """Build a StateEvaluation from current minmax state."""
879
+
879
880
  if self.over_event.is_over():
880
881
  return ForcedOutcome(
881
882
  outcome=self.over_event,
@@ -1,10 +1,10 @@
1
1
  from typing import TYPE_CHECKING, Protocol, Self
2
2
 
3
3
  from valanga import (
4
- BoardEvaluation,
5
4
  BranchKey,
6
5
  OverEvent,
7
6
  State,
7
+ StateEvaluation,
8
8
  )
9
9
 
10
10
  type BranchSortValue = tuple[float, int, int]
@@ -43,7 +43,7 @@ class NodeTreeEvaluation[StateT: State = State](Protocol):
43
43
  value_white_minmax: float | None = None
44
44
 
45
45
  def set_evaluation(self, evaluation: float) -> None:
46
- """sets the evaluation from the board evaluator
46
+ """Set the evaluation from the state evaluator.
47
47
 
48
48
  Args:
49
49
  evaluation (float): The evaluation value to be set.
@@ -90,8 +90,8 @@ class NodeTreeEvaluation[StateT: State = State](Protocol):
90
90
  """Update terminal state based on updated branches."""
91
91
  ...
92
92
 
93
- def evaluate(self) -> BoardEvaluation:
94
- """Return a board evaluation for this node."""
93
+ def evaluate(self) -> StateEvaluation:
94
+ """Return a state evaluation for this node."""
95
95
  ...
96
96
 
97
97
  def description_tree_visualizer_branch(self, child: "ITreeNode[StateT]") -> str:
@@ -37,7 +37,9 @@ class AlgorithmNodeFactory[StateT: State = State]:
37
37
  """
38
38
 
39
39
  tree_node_factory: TreeNodeFactory[AlgorithmNode[StateT], StateT]
40
- state_representation_factory: RepresentationFactory | None
40
+ state_representation_factory: (
41
+ RepresentationFactory[StateT, ContentRepresentation] | None
42
+ )
41
43
  node_tree_evaluation_factory: NodeTreeEvaluationFactory[StateT]
42
44
  exploration_index_data_create: node_indices.ExplorationIndexDataFactory[
43
45
  AlgorithmNode[StateT], StateT
@@ -57,7 +57,7 @@ class AlgorithmNode[StateT: State = State]:
57
57
  tree_node (TreeNode): The tree node that is wrapped.
58
58
  tree_evaluation (NodeTreeEvaluation): The object computing the value.
59
59
  exploration_index_data (NodeExplorationData | None): The object storing the information to help the algorithm decide the next nodes to explore.
60
- state_representation (StateRepresentation | None): The board representation.
60
+ state_representation (ContentRepresentation | None): The state representation used for evaluation.
61
61
  """
62
62
  self.tree_node = tree_node
63
63
  self.tree_evaluation = tree_evaluation
@@ -145,9 +145,9 @@ class AlgorithmNode[StateT: State = State]:
145
145
  )
146
146
 
147
147
  @property
148
- def all_branches_keys(self) -> BranchKeyGeneratorP:
148
+ def all_branches_keys(self) -> BranchKeyGeneratorP[BranchKey]:
149
149
  """
150
- Returns a generator that yields the branch keys for the current board state.
150
+ Returns a generator that yields the branch keys for the current state.
151
151
 
152
152
  Returns:
153
153
  BranchKeyGenerator: A generator that yields the branch keys.
@@ -108,7 +108,7 @@ class ITreeNode[StateT: State = State](Protocol):
108
108
  """
109
109
 
110
110
  @property
111
- def all_branches_keys(self) -> BranchKeyGeneratorP:
111
+ def all_branches_keys(self) -> BranchKeyGeneratorP[BranchKey]:
112
112
  """
113
113
  Get the available branch keys of the node.
114
114
 
@@ -152,7 +152,7 @@ class TreeNode[
152
152
  return not self.parent_nodes
153
153
 
154
154
  @property
155
- def all_branches_keys(self) -> BranchKeyGeneratorP:
155
+ def all_branches_keys(self) -> BranchKeyGeneratorP[BranchKey]:
156
156
  """
157
157
  Returns a generator that yields the branch keys for the current state.
158
158
 
@@ -16,9 +16,10 @@ Example usage:
16
16
  from dataclasses import dataclass
17
17
  from enum import Enum
18
18
  from random import Random
19
- from typing import Literal, Mapping, Protocol
19
+ from typing import Literal, Protocol
20
20
 
21
21
  from valanga import BranchKey, State
22
+ from valanga.policy import BranchPolicy
22
23
 
23
24
  from anemone.nodes.algorithm_node.algorithm_node import (
24
25
  AlgorithmNode,
@@ -26,15 +27,6 @@ from anemone.nodes.algorithm_node.algorithm_node import (
26
27
  from anemone.utils.small_tools import softmax
27
28
 
28
29
 
29
- @dataclass(frozen=True, slots=True)
30
- class BranchPolicy:
31
- """
32
- Represents a probability distribution over branches.
33
- """
34
-
35
- probs: Mapping[BranchKey, float] # should sum to ~1.0
36
-
37
-
38
30
  def sample_from_policy(policy: BranchPolicy, rng: Random) -> BranchKey:
39
31
  """Sample a branch key from a probability policy using a RNG."""
40
32
  branches = list(policy.probs.keys())
@@ -5,8 +5,9 @@ from queue import Queue
5
5
  from random import Random
6
6
 
7
7
  from valanga import TurnState
8
+ from valanga.policy import Recommendation
8
9
 
9
- from anemone.basics import BranchRecommendation, Seed
10
+ from anemone.basics import Seed
10
11
  from anemone.progress_monitor.progress_monitor import (
11
12
  AllStoppingCriterionArgs,
12
13
  )
@@ -43,14 +44,12 @@ class TreeAndValueBranchSelector[StateT: TurnState = TurnState]:
43
44
  recommend_branch_after_exploration: recommender_rule.AllRecommendFunctionsArgs
44
45
  queue_progress_player: Queue[IsDataclass] | None
45
46
 
46
- def select_branch(
47
- self, state: StateT, selection_seed: Seed
48
- ) -> BranchRecommendation:
47
+ def select_branch(self, state: StateT, selection_seed: Seed) -> Recommendation:
49
48
  """
50
49
  Selects the best branch based on the tree and value strategy.
51
50
 
52
51
  Args:
53
- - board: The current board state.
52
+ - state: The current state to explore.
54
53
  - selection_seed: The seed used for randomization during branch selection.
55
54
 
56
55
  Returns:
@@ -59,7 +58,7 @@ class TreeAndValueBranchSelector[StateT: TurnState = TurnState]:
59
58
  tree_exploration: TreeExploration = self.create_tree_exploration(state=state)
60
59
  self.random_generator.seed(selection_seed)
61
60
 
62
- branch_recommendation: BranchRecommendation = tree_exploration.explore(
61
+ branch_recommendation: Recommendation = tree_exploration.explore(
63
62
  random_generator=self.random_generator
64
63
  ).branch_recommendation
65
64
 
@@ -20,9 +20,10 @@ from queue import Queue
20
20
  from random import Random
21
21
  from typing import TYPE_CHECKING, Any, Callable
22
22
 
23
- from valanga import BoardEvaluation, BranchKey, PlayerProgressMessage, State, TurnState
23
+ from valanga import BranchKey, PlayerProgressMessage, State, StateEvaluation, TurnState
24
+ from valanga.game import BranchName
25
+ from valanga.policy import Recommendation
24
26
 
25
- from anemone.basics import BranchRecommendation
26
27
  from anemone.nodes.algorithm_node.algorithm_node import AlgorithmNode
27
28
  from anemone.progress_monitor.progress_monitor import (
28
29
  AllStoppingCriterionArgs,
@@ -39,7 +40,7 @@ from . import tree_manager as tree_man
39
40
  from .trees.factory import ValueTreeFactory
40
41
 
41
42
  if TYPE_CHECKING:
42
- from anemone.recommender_rule.recommender_rule import BranchPolicy
43
+ from valanga.policy import BranchPolicy
43
44
 
44
45
 
45
46
  @dataclass
@@ -48,21 +49,22 @@ class TreeExplorationResult[NodeT: AlgorithmNode[Any] = AlgorithmNode[Any]]:
48
49
  Tree Exploration Result holds the result of a tree exploration.
49
50
  """
50
51
 
51
- branch_recommendation: BranchRecommendation
52
+ branch_recommendation: Recommendation
52
53
  tree: trees.Tree[NodeT]
53
54
 
54
55
 
55
56
  def compute_child_evals[StateT: State](
56
57
  root: AlgorithmNode[StateT],
57
- ) -> dict[BranchKey, BoardEvaluation]:
58
+ ) -> dict[BranchName, StateEvaluation]:
58
59
  """Compute evaluations for each existing child branch."""
59
- evals: dict[BranchKey, BoardEvaluation] = {}
60
+ evals: dict[BranchName, StateEvaluation] = {}
60
61
  for bk, child in root.branches_children.items():
61
62
  if child is None:
62
63
  continue
63
64
 
64
65
  # Use whatever your canonical per-node evaluation is:
65
- evals[bk] = child.tree_evaluation.evaluate()
66
+ bk_name = root.state.branch_name_from_key(bk)
67
+ evals[bk_name] = child.tree_evaluation.evaluate()
66
68
  return evals
67
69
 
68
70
 
@@ -188,15 +190,16 @@ class TreeExploration[NodeT: AlgorithmNode[Any] = AlgorithmNode[Any]]:
188
190
  policy, random_generator
189
191
  )
190
192
 
193
+ best_branch_name = self.tree.root_node.state.branch_name_from_key(best_branch)
191
194
  self.tree_manager.print_best_line(
192
195
  tree=self.tree
193
196
  ) # todo maybe almost best chosen line no?
194
197
 
195
- branch_recommendation = BranchRecommendation(
196
- branch_key=best_branch,
198
+ branch_recommendation = Recommendation(
199
+ recommended_name=best_branch_name,
197
200
  evaluation=self.tree.root_node.tree_evaluation.evaluate(),
198
201
  policy=policy,
199
- child_evals=compute_child_evals(self.tree.root_node),
202
+ branch_evals=compute_child_evals(self.tree.root_node),
200
203
  )
201
204
 
202
205
  tree_exploration_result: TreeExplorationResult[NodeT] = TreeExplorationResult(
@@ -70,7 +70,7 @@ class TreeManager[
70
70
  Returns:
71
71
  The tree expansion object.
72
72
  """
73
- # The parent board is copied, we only copy the stack (history of previous board) if the depth is smaller than 2
73
+ # The parent state is copied; we only copy the stack (history of previous states) if the depth is smaller than 2.
74
74
  # Having the stack information allows checking for draw by repetition.
75
75
  # To limit computation we limit copying it all the time. The resulting policy will only be aware of immediate
76
76
  # risk of draw by repetition
@@ -117,7 +117,7 @@ class TreeManager[
117
117
  The tree expansion object.
118
118
  """
119
119
 
120
- # Creation of the child node. If the board already exited in another node, that node is returned as child_node.
120
+ # Creation of the child node. If the state already existed in another node, that node is returned as child_node.
121
121
  tree_depth: int = parent_node.tree_depth + 1
122
122
  state_tag: StateTag = state.tag
123
123