def test_random_vs_stateful(self):
   game = pyspiel.load_game("tic_tac_toe")
   bots = [
       pyspiel.make_stateful_random_bot(game, 0, 1234),
       uniform_random.UniformRandomBot(1, np.random.RandomState(4321))
   ]
   for _ in range(1000):
     evaluate_bots.evaluate_bots(game.new_initial_state(), bots, np.random)
Example #2
0
 def test_can_play_single_player(self):
   game = pyspiel.load_game("catch")
   max_simulations = 100
   evaluator = mcts.RandomRolloutEvaluator(n_rollouts=20)
   bots = [mcts.MCTSBot(game, UCT_C, max_simulations, evaluator)]
   v = evaluate_bots.evaluate_bots(game.new_initial_state(), bots, np.random)
   self.assertGreater(v[0], 0)
Example #3
0
 def test_can_play_both_sides(self):
   game = pyspiel.load_game("tic_tac_toe")
   bot = mcts.MCTSBot(game, UCT_C, max_simulations=100,
                      evaluator=mcts.RandomRolloutEvaluator(n_rollouts=20))
   bots = [bot, bot]
   v = evaluate_bots.evaluate_bots(game.new_initial_state(), bots, np.random)
   self.assertEqual(v[0] + v[1], 0)
Example #4
0
 def test_cpp_vs_python(self, bots):
     results = np.array([
         evaluate_bots.evaluate_bots(GAME.new_initial_state(), bots,
                                     np.random) for _ in range(10000)
     ])
     average_results = np.mean(results, axis=0)
     np.testing.assert_allclose(average_results, [0.125, -0.125], atol=0.1)
Example #5
0
 def test_can_play_three_player_stochastic_games(self):
   game = pyspiel.load_game("pig(players=3,winscore=20,horizon=30)")
   max_simulations = 100
   evaluator = mcts.RandomRolloutEvaluator(n_rollouts=5)
   bots = [
       mcts.MCTSBot(game, UCT_C, max_simulations, evaluator),
       mcts.MCTSBot(game, UCT_C, max_simulations, evaluator),
       mcts.MCTSBot(game, UCT_C, max_simulations, evaluator),
   ]
   v = evaluate_bots.evaluate_bots(game.new_initial_state(), bots, np.random)
   self.assertEqual(sum(v), 0)
 def test_cpp_vs_python(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([
       evaluate_bots.evaluate_bots(game.new_initial_state(), bots, np.random)
       for _ in range(10000)
   ])
   average_results = np.mean(results, axis=0)
   np.testing.assert_allclose(average_results, [0.125, -0.125], atol=0.1)
Example #7
0
 def test_can_play_tic_tac_toe(self):
     game = pyspiel.load_game("tic_tac_toe")
     uct_c = math.sqrt(2)
     max_simulations = 100
     evaluator = mcts.RandomRolloutEvaluator(n_rollouts=20)
     bots = [
         mcts.MCTSBot(game, 0, uct_c, max_simulations, evaluator),
         mcts.MCTSBot(game, 1, uct_c, max_simulations, evaluator),
     ]
     v = evaluate_bots.evaluate_bots(game.new_initial_state(), bots,
                                     np.random)
     self.assertEqual(v[0] + v[1], 0)
Example #8
0
 def test_can_play_three_player_game(self):
     game = pyspiel.load_game("pig(players=3,winscore=20,horizon=30)")
     uct_c = math.sqrt(2)
     max_search_nodes = 100
     evaluator = mcts.RandomRolloutEvaluator(n_rollouts=5)
     bots = [
         mcts.MCTSBot(game, 0, uct_c, max_search_nodes, evaluator),
         mcts.MCTSBot(game, 1, uct_c, max_search_nodes, evaluator),
         mcts.MCTSBot(game, 2, uct_c, max_search_nodes, evaluator),
     ]
     v = evaluate_bots.evaluate_bots(game.new_initial_state(), bots,
                                     np.random)
     self.assertEqual(sum(v), 0)
Example #9
0
 def ismcts_play_game(self, game):
   evaluator = pyspiel.RandomRolloutEvaluator(1, SEED)
   for final_policy_type in [
       pyspiel.ISMCTSFinalPolicyType.NORMALIZED_VISIT_COUNT,
       pyspiel.ISMCTSFinalPolicyType.MAX_VISIT_COUNT,
       pyspiel.ISMCTSFinalPolicyType.MAX_VALUE
   ]:
     bot = pyspiel.ISMCTSBot(SEED, evaluator, 5.0, 1000, -1, final_policy_type,
                             False, False)
     bots = [bot] * game.num_players()
     evaluate_bots.evaluate_bots(game.new_initial_state(), bots, np.random)
     bot = pyspiel.ISMCTSBot(SEED, evaluator, 5.0, 1000, 10, final_policy_type,
                             False, False)
     bots = [bot] * game.num_players()
     evaluate_bots.evaluate_bots(game.new_initial_state(), bots, np.random)
     bot = pyspiel.ISMCTSBot(SEED, evaluator, 5.0, 1000, 10, final_policy_type,
                             True, True)
     bots = [bot] * game.num_players()
     evaluate_bots.evaluate_bots(game.new_initial_state(), bots, np.random)
Example #10
0
 def xinxin_play_game(self, game):
     bots = []
     for _ in range(4):
         bots.append(pyspiel.make_xinxin_bot(game.get_parameters()))
     evaluate_bots.evaluate_bots(game.new_initial_state(), bots, np.random)