Fix min() error for small time limits (t=0.1)
This commit is contained in:
@@ -9,10 +9,10 @@ from chesspp.util_gaussian import gaussian_ucb1, max_gaussian, min_gaussian
|
|||||||
class BayesianMctsNode(IMctsNode):
|
class BayesianMctsNode(IMctsNode):
|
||||||
def __init__(self, board: chess.Board, strategy: IStrategy, color: chess.Color, parent: Self | None,
|
def __init__(self, board: chess.Board, strategy: IStrategy, color: chess.Color, parent: Self | None,
|
||||||
move: chess.Move | None,
|
move: chess.Move | None,
|
||||||
random_state: random.Random, inherit_result: int | None = None, depth: int = 0):
|
random_state: random.Random, inherit_result: int | None = None, depth: int = 0, visits: int = 0):
|
||||||
super().__init__(board, strategy, parent, move, random_state)
|
super().__init__(board, strategy, parent, move, random_state)
|
||||||
self.color = color # Color of the player whose turn it is
|
self.color = color # Color of the player whose turn it is
|
||||||
self.visits = 0
|
self.visits = visits
|
||||||
self.result = inherit_result if inherit_result is not None else 0
|
self.result = inherit_result if inherit_result is not None else 0
|
||||||
self._set_mu_sigma()
|
self._set_mu_sigma()
|
||||||
self.depth = depth
|
self.depth = depth
|
||||||
@@ -140,8 +140,7 @@ class BayesianMcts(IMcts):
|
|||||||
|
|
||||||
def __init__(self, board: chess.Board, strategy: IStrategy, color: chess.Color, seed: int | None = None):
|
def __init__(self, board: chess.Board, strategy: IStrategy, color: chess.Color, seed: int | None = None):
|
||||||
super().__init__(board, strategy, seed)
|
super().__init__(board, strategy, seed)
|
||||||
self.root = BayesianMctsNode(board, strategy, color, None, None, self.random_state)
|
self.root = BayesianMctsNode(board, strategy, color, None, None, self.random_state, visits=1)
|
||||||
self.root.visits += 1
|
|
||||||
self.color = color
|
self.color = color
|
||||||
|
|
||||||
def sample(self, runs: int = 1000) -> None:
|
def sample(self, runs: int = 1000) -> None:
|
||||||
@@ -164,10 +163,11 @@ class BayesianMcts(IMcts):
|
|||||||
child.depth = 0
|
child.depth = 0
|
||||||
self.root.parent = None
|
self.root.parent = None
|
||||||
self.root.update_depth(0)
|
self.root.update_depth(0)
|
||||||
|
self.root.visits = 1
|
||||||
return
|
return
|
||||||
|
|
||||||
# if no child node contains the move, initialize a new tree.
|
# if no child node contains the move, initialize a new tree.
|
||||||
self.root = BayesianMctsNode(self.board, self.root.strategy, self.color, None, None, self.random_state)
|
self.root = BayesianMctsNode(self.board, self.root.strategy, self.color, None, None, self.random_state, visits=1)
|
||||||
|
|
||||||
def get_children(self) -> list[IMctsNode]:
|
def get_children(self) -> list[IMctsNode]:
|
||||||
return self.root.children
|
return self.root.children
|
||||||
|
|||||||
Reference in New Issue
Block a user