def test_single_step(self):
     game = pyspiel.load_matrix_game("matrix_rps")
     solver = double_oracle.DoubleOracleSolver(game)
     solver.subgame_strategies = [[0], [0]]
     best_response, best_response_utility = solver.step()
     self.assertListEqual(best_response, [1, 1])
     self.assertListEqual(best_response_utility, [1.0, 1.0])
 def test_rock_paper_scissors(self):
     game = pyspiel.load_matrix_game("matrix_rps")
     solver = double_oracle.DoubleOracleSolver(game)
     solution, iteration, value = solver.solve(
         initial_strategies=[[0], [0]])
     np.testing.assert_allclose(solution[0], np.ones(3) / 3.)
     np.testing.assert_allclose(solution[1], np.ones(3) / 3.)
     self.assertEqual(iteration, 3)
     self.assertAlmostEqual(value, 0.0)
    def test_kuhn_poker(self):
        game = pyspiel.extensive_to_matrix_game(
            pyspiel.load_game("kuhn_poker"))
        solver = double_oracle.DoubleOracleSolver(game)
        solution, iteration, value = solver.solve(
            initial_strategies=[[0], [0]])

        # check if solution is Nash
        exp_utilty = solution[0] @ solver.payoffs @ solution[1]
        self.assertAlmostEqual(max(solver.payoffs[0] @ solution[1]),
                               exp_utilty[0])
        self.assertAlmostEqual(max(solution[0] @ solver.payoffs[1]),
                               exp_utilty[1])

        self.assertEqual(iteration, 8)
        self.assertAlmostEqual(value, 0.0)