Esempio n. 1
0
    def _test_game(self, game, expected_supports, expected_minimax_values):
        support_p1, support_p2, \
        minimax_val_p1, minimax_val_p2 = solve_zero_sum_game(game)

        supports = (support_p1, support_p2)
        minimax_vals = (minimax_val_p1, minimax_val_p2)

        # Supports should range over the same number of actions
        for actual_s, expected_s in zip(supports, expected_supports):
            self.assertEqual(len(actual_s), len(expected_s))

        # Supports should distribute probability mass as expected
        for actual_s, expected_s in zip(supports, expected_supports):
            for actual_action_support, expected_action_support in zip(
                    actual_s, expected_s):
                np.testing.assert_array_almost_equal(actual_action_support,
                                                     expected_action_support)

        # Minimax values should match
        for actual_minimax_val, expected_minimax_val in zip(
                minimax_vals, expected_minimax_values):
            self.assertAlmostEqual(actual_minimax_val, expected_minimax_val)
Esempio n. 2
0
def default_meta_game_solver(winrate_matrix: np.ndarray):
    return solve_zero_sum_game(winrate_matrix)[0].reshape((-1))
Esempio n. 3
0
 def test_for_none_game_raises_valueerror(self):
     with pytest.raises(ValueError) as _:
         _ = solve_zero_sum_game(None)
Esempio n. 4
0
 def test_for_non_integer_or_float_list_raises_valueerror(self):
     with pytest.raises(ValueError) as _:
         _ = solve_zero_sum_game([['a', 'b']])
Esempio n. 5
0
 def test_for_empty_numpy_array_game_raises_valueerror(self):
     with pytest.raises(ValueError) as _:
         _ = solve_zero_sum_game(np.array(None))