Update MCTS to change color for children

This commit is contained in:
2024-01-31 17:39:08 +01:00
parent b6bb61ec45
commit 793d83b943
3 changed files with 9 additions and 9 deletions

View File

@@ -29,7 +29,7 @@ class ClassicMcts:
self.untried_actions.remove(move) self.untried_actions.remove(move)
next_board = self.board.copy() next_board = self.board.copy()
next_board.push(move) next_board.push(move)
child_node = ClassicMcts(next_board, color=self.color, strategy=self.strategy, parent=self, move=move) child_node = ClassicMcts(next_board, color=not self.color, strategy=self.strategy, parent=self, move=move)
self.children.append(child_node) self.children.append(child_node)
return child_node return child_node

View File

@@ -40,13 +40,13 @@ class IMcts(ABC):
""" """
pass pass
@abstractmethod #@abstractmethod
def get_moves(self) -> Dict[chess.Move, int]: #def get_moves(self) -> Dict[chess.Move, int]:
""" # """
Return all legal moves from this node with respective scores # Return all legal moves from this node with respective scores
:return: dictionary with moves as key and scores as values # :return: dictionary with moves as key and scores as values
""" # """
pass # pass
""" """
TODO: add score class: TODO: add score class:

View File

@@ -6,6 +6,7 @@ import chess
from chesspp.i_strategy import IStrategy from chesspp.i_strategy import IStrategy
class IMctsNode(ABC): class IMctsNode(ABC):
def __init__(self, board: chess.Board, strategy: IStrategy, parent: Self | None, move: chess.Move | None, def __init__(self, board: chess.Board, strategy: IStrategy, parent: Self | None, move: chess.Move | None,
random_state: random.Random): random_state: random.Random):
@@ -16,7 +17,6 @@ class IMctsNode(ABC):
self.move = move self.move = move
self.legal_moves = list(board.legal_moves) self.legal_moves = list(board.legal_moves)
self.random_state = random_state self.random_state = random_state
self.depth = 0
@abstractmethod @abstractmethod
def select(self) -> Self: def select(self) -> Self: