def simulate_random_game(game: GameState): bots = {Player.black: RandomBot(), Player.white: RandomBot()} while (not game.is_over()): bot_move = bots[game.next_player].select_move(game) game = game.apply_move(bot_move) return game.winner()
def simulate_random_game(game: GameState) -> Player: bots = { Player.black: FastRandomAgent(), Player.white: FastRandomAgent(), } while not game.is_over(): bot_move = bots[game.next_player].select_move(game) game = game.apply_move(bot_move) return cast(Player, game.winner())
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)