def test_max_iterations_less_than_available_actions():
     # Here not all of the root node's children will be expanded.
     options = MctsPlayerOptions(max_iterations=1,
                                 max_permutations=10,
                                 num_processes=1)
     game_state = GameState.new(random_seed=0)
     mcts_player = CythonMctsPlayer(game_state.next_player, False, options)
     mcts_player.request_next_action(game_state.next_player_view())
def _get_dataframe(game_state: GameState, cheater: bool,
                   options: MctsPlayerOptions, num_samples: int) -> DataFrame:
    data = []
    game_view = game_state if cheater else game_state.next_player_view()
    for _ in range(num_samples):
        player = CythonMctsPlayer(game_state.next_player, cheater, options)
        actions_and_scores = player.get_actions_and_scores(game_view)
        for action, score in actions_and_scores:
            data.append((str(action), score))
    dataframe = DataFrame(data, columns=["action", "score"])
    dataframe = dataframe.pivot(columns=["action"], values=["score"])
    dataframe.columns = dataframe.columns.droplevel()
    return dataframe
Пример #3
0
def evaluate_bummerl(
        bummerl: Bummerl,
        bummerl_id: str = "0",
        options: Optional[MctsPlayerOptions] = None) -> EvalResults:
    options = options or MctsPlayerOptions(
        num_processes=1,
        max_permutations=150,
        max_iterations=667,
        merge_scoring_info_func=average_score_with_tiebreakers)
    players = PlayerPair(CythonMctsPlayer(PlayerId.ONE, False, options),
                         CythonMctsPlayer(PlayerId.TWO, False, options))
    bummerl_score = PlayerPair(0, 0)
    eval_results = []
    for game_id, game in enumerate(bummerl.completed_games):
        eval_results.extend(
            evaluate_game(game, players, bummerl_score, bummerl_id, game_id))
        bummerl_score.one += game.game_state.game_points.one
        bummerl_score.two += game.game_state.game_points.two
    return eval_results
Пример #4
0
def _main():
    # filename = "../autosave_bummerl.pickle"
    # with open(filename, "rb") as input_file:
    #   bummerl = pickle.load(input_file)
    # results = evaluate_bummerl(bummerl)
    # print_eval_results(results, None)

    options = MctsPlayerOptions(
        num_processes=1,
        max_permutations=150,
        max_iterations=667,
        merge_scoring_info_func=average_score_with_tiebreakers)
    players = PlayerPair(CythonMctsPlayer(PlayerId.ONE, False, options),
                         CythonMctsPlayer(PlayerId.TWO, False, options))
    bummerl_score = PlayerPair(0, 0)
    with open("../autosave_game.pickle", "rb") as input_file:
        game = pickle.load(input_file)
    print_eval_results(evaluate_game(game, players, bummerl_score, "0", "0"),
                       None)
Пример #5
0
def _get_player_closure(game_state: GameState, iterations: int,
                        max_permutations: int) -> Tuple[Closure, Closure]:
    mcts = CythonMctsPlayer(game_state.next_player,
                            cheater=False,
                            options=MctsPlayerOptions(
                                max_permutations=max_permutations,
                                max_iterations=iterations,
                                num_processes=1))

    def _run():
        mcts.request_next_action(game_state.next_player_view())

    return _run, mcts.cleanup
Пример #6
0
def _get_algorithm_closure(game_state: GameState,
                           iterations: int) -> Tuple[Closure, Closure]:
    mcts = CythonMctsPlayer(
        game_state.next_player,
        cheater=True,
        options=MctsPlayerOptions(
            max_permutations=10,  # Won't matter if cheater=True
            max_iterations=iterations,
            num_processes=1))

    def _run():
        mcts.request_next_action(game_state)

    return _run, mcts.cleanup
 def setUp(self) -> None:
     options = mcts_player_options_v1()
     self._mcts_player = CythonMctsPlayer(PlayerId.ONE, options=options)
 def setUp(self) -> None:
     options = MctsPlayerOptions(max_iterations=None,
                                 select_best_child=True,
                                 save_rewards=True,
                                 num_processes=1)
     self._mcts_player = CythonMctsPlayer(PlayerId.ONE, options=options)
 def test_cannot_instantiate_with_multi_threading(self) -> None:
     options = MctsPlayerOptions(max_iterations=None, num_processes=10)
     with self.assertRaisesRegex(ValueError, "10 threads"):
         CythonMctsPlayer(PlayerId.ONE, options=options)
 def setUp(self) -> None:
     options = MctsPlayerOptions(
         max_iterations=None,
         merge_scoring_info_func=merge_ucbs_using_weighted_average,
         num_processes=1)
     self._mcts_player = CythonMctsPlayer(PlayerId.ONE, options=options)
 def setUp(self) -> None:
     options = MctsPlayerOptions(max_iterations=None,
                                 merge_scoring_info_func=count_visits,
                                 num_processes=1)
     self._mcts_player = CythonMctsPlayer(PlayerId.ONE, options=options)
 def setUp(self) -> None:
     options = MctsPlayerOptions(
         max_iterations=None,
         merge_scoring_info_func=best_action_frequency,
         num_processes=1)
     self._mcts_player = CythonMctsPlayer(PlayerId.ONE, options=options)
Пример #13
0
    "HeuristicNoTrumpForMarriages":
    lambda player_id: HeuristicPlayer(
        player_id, HeuristicPlayerOptions(trump_for_marriage=False)),
    "HeuristicNoAvoidDirectLoss":
    lambda player_id: HeuristicPlayer(
        player_id, HeuristicPlayerOptions(avoid_direct_loss=False)),
    "HeuristicWithTrumpControl":
    lambda player_id: HeuristicPlayer(
        player_id, HeuristicPlayerOptions(trump_control=True)),

    # Same permutations, different iterations
    "MctsPlayer30perm10000iter":
    lambda player_id: CythonMctsPlayer(
        player_id, False,
        MctsPlayerOptions(num_processes=1,
                          max_permutations=30,
                          max_iterations=10000,
                          select_best_child=True,
                          exploration_param=math.sqrt(2))),
    "MctsPlayer30perm5000iter":
    lambda player_id: CythonMctsPlayer(
        player_id, False,
        MctsPlayerOptions(num_processes=1,
                          max_permutations=30,
                          max_iterations=5000,
                          select_best_child=True,
                          exploration_param=math.sqrt(2))),
    "MctsPlayer30perm2500iter":
    lambda player_id: CythonMctsPlayer(
        player_id, False,
        MctsPlayerOptions(num_processes=1,