def test_python_and_cpp_bot(self): game = pyspiel.load_game("kuhn_poker") bots = [ pyspiel.make_uniform_random_bot(0, 1234), uniform_random.UniformRandomBot(1, np.random.RandomState(4321)), ] results = np.array([ pyspiel.evaluate_bots(game.new_initial_state(), bots, iteration) for iteration in range(10000) ]) average_results = np.mean(results, axis=0) np.testing.assert_allclose(average_results, [0.125, -0.125], atol=0.1)
def bot_evaluation(game, bots, num_evaluations): """Returns a tuple (wins, losses, draws) for player 2.""" wins, losses, draws = 0, 0, 0 for i in range(num_evaluations): [_, result] = pyspiel.evaluate_bots(game.new_initial_state(), bots, i) if result == 0: draws += 1 elif result == 1: wins += 1 else: losses += 1 return (wins, losses, draws)
def test_passing_params(self): game = pyspiel.load_game("tic_tac_toe") bots = [ pyspiel.load_bot("fixed_action_preference", game, player=0, params={"actions": "0:1:2"}), pyspiel.load_bot("fixed_action_preference", game, player=1, params={"actions": "3:4"}), ] result = pyspiel.evaluate_bots(game.new_initial_state(), bots, seed=0) self.assertEqual(result, [1, -1]) # Player 0 wins.
def test_cpp_mcts_bot(self): game = pyspiel.load_game("tic_tac_toe") bots = [ pyspiel.MCTSBot(game, pyspiel.RandomRolloutEvaluator(1, 0), 2.0, 100, 100, False, 42, False) ] * 2 _ = np.array([ pyspiel.evaluate_bots(game.new_initial_state(), bots, iteration) for iteration in range(10) ]) # Do a search directly, and inspect the values. state = game.new_initial_state() search_node = bots[0].mcts_search(state) for child in search_node.children: print( f"Child action {child.action}, total reward: {child.total_reward}" + f", explore count: {child.explore_count}") # Similar way to achieve the above. print(f"Children string: {search_node.children_str(state)}") print(f"Best child: {search_node.best_child().to_string(state)}")