def __init__(self, game_state: GameState, parent: 'MCTSNode' = None, move: Move = None): self.parent = parent self.game_state = game_state self.move = move self.win_counts = {Player.white: 0, Player.black: 0} self.num_rollouts = 0 self.children: List[MCTSNode] = [] self.univisted_moves = game_state.legal_moves()
def __init__(self, game_state: GameState, parent: MCTSNode = None, last_move: Move = None): self.game_state = game_state self.parent = parent self.last_move = last_move self.win_counts: Dict[Player, int] = { Player.black: 0, Player.white: 0, } self.num_rollouts: int = 0 self.children: List[MCTSNode] = [] b: Board = game_state.board p: Player = game_state.next_player moves: List[Move] = game_state.legal_moves() self.unvisited_moves: List[Move] = [m for m in moves if not (m.point and is_point_an_eye(b, m.point, p))]
def select_move(self, game_state: GameState): best_moves: List[Move] = [] best_score = float("-inf") # Loop over all legal moves. for possible_move in game_state.legal_moves(): if possible_move.point and is_point_an_eye(game_state.board, possible_move.point, game_state.next_player): continue # skip the eye next_state = game_state.apply_move(possible_move) result = alphabeta(next_state, False, game_state.next_player, self.max_depth, ev_fn=self.ev_fn) if (not best_moves) or result > best_score: best_moves = [possible_move] best_score = result elif result == best_score: best_moves.append(possible_move) # For variety, randomly select among all equally good moves. return random.choice(best_moves)