|
17 | 17 | TOL = 1e-13 # tolerance for floating point assertions |
18 | 18 |
|
19 | 19 |
|
20 | | -def test_enumpure_strategy(): |
21 | | - """Test calls of enumeration of pure strategies.""" |
22 | | - game = games.read_from_file("poker.efg") |
23 | | - assert len(gbt.nash.enumpure_solve(game, use_strategic=True).equilibria) == 0 |
| 20 | +@pytest.mark.nash |
| 21 | +@pytest.mark.nash_enumpure_strategy |
| 22 | +@pytest.mark.parametrize( |
| 23 | + "game,pure_strategy_prof_data", |
| 24 | + [ |
| 25 | + # Zero-sum games |
| 26 | + ( |
| 27 | + games.create_two_player_perfect_info_win_lose_efg(), |
| 28 | + [ |
| 29 | + [[0, 0, 1, 0], [1, 0, 0]], |
| 30 | + [[0, 0, 1, 0], [0, 1, 0]], |
| 31 | + [[0, 0, 1, 0], [0, 0, 1]], |
| 32 | + ] |
| 33 | + ), |
| 34 | + (games.create_myerson_2_card_poker_efg(), []), |
| 35 | + # Non-zero-sum 2-player games |
| 36 | + (games.create_one_shot_trust_efg(), [[[0, 1], [0, 1]]]), |
| 37 | + ( |
| 38 | + games.create_EFG_for_nxn_bimatrix_coordination_game(3), |
| 39 | + [ |
| 40 | + [[1, 0, 0], [1, 0, 0]], |
| 41 | + [[0, 1, 0], [0, 1, 0]], |
| 42 | + [[0, 0, 1], [0, 0, 1]], |
| 43 | + ], |
| 44 | + ), |
| 45 | + (games.create_EFG_for_6x6_bimatrix_with_long_LH_paths_and_unique_eq(), []), |
| 46 | + # 3-player game |
| 47 | + ( |
| 48 | + games.create_mixed_behav_game_efg(), |
| 49 | + [ |
| 50 | + [[1, 0], [1, 0], [1, 0]], |
| 51 | + [[0, 1], [0, 1], [1, 0]], |
| 52 | + [[0, 1], [1, 0], [0, 1]], |
| 53 | + [[1, 0], [0, 1], [0, 1]], |
| 54 | + ], |
| 55 | + ), |
| 56 | + ] |
| 57 | +) |
| 58 | +def test_enumpure_strategy(game: gbt.Game, pure_strategy_prof_data: list): |
| 59 | + """Test calls of enumeration of pure strategy equilibria |
24 | 60 |
|
| 61 | + Tests max regret being zero (internal consistency) and compares the computed sequence of |
| 62 | + pure strategy equilibria to a previosuly computed sequence (regression test) |
| 63 | + """ |
| 64 | + result = gbt.nash.enumpure_solve(game, use_strategic=True) |
| 65 | + assert len(result.equilibria) == len(pure_strategy_prof_data) |
| 66 | + for eq, exp in zip(result.equilibria, pure_strategy_prof_data): |
| 67 | + assert eq.max_regret() == 0 |
| 68 | + expected = game.mixed_strategy_profile(rational=True, data=exp) |
| 69 | + assert eq == expected |
25 | 70 |
|
26 | | -def test_enumpure_agent(): |
27 | | - """Test calls of enumeration of pure agent strategies.""" |
28 | | - game = games.read_from_file("poker.efg") |
29 | | - assert len(gbt.nash.enumpure_solve(game, use_strategic=False).equilibria) == 0 |
| 71 | + |
| 72 | +@pytest.mark.nash |
| 73 | +@pytest.mark.nash_enumpure_agent |
| 74 | +@pytest.mark.parametrize( |
| 75 | + "game,pure_behav_prof_data", |
| 76 | + [ |
| 77 | + # Zero-sum games |
| 78 | + ( |
| 79 | + games.create_two_player_perfect_info_win_lose_efg(), |
| 80 | + [ |
| 81 | + [[[1, 0], [1, 0]], [[0, 1], [1, 0]]], |
| 82 | + [[[0, 1], [1, 0]], [[1, 0], [1, 0]]], |
| 83 | + [[[0, 1], [1, 0]], [[1, 0], [0, 1]]], |
| 84 | + [[[0, 1], [1, 0]], [[0, 1], [1, 0]]], |
| 85 | + [[[0, 1], [1, 0]], [[0, 1], [0, 1]]] |
| 86 | + ] |
| 87 | + ), |
| 88 | + (games.create_myerson_2_card_poker_efg(), []), |
| 89 | + # Non-zero-sum 2-player games |
| 90 | + (games.create_one_shot_trust_efg(), [[[[0, 1]], [[0, 1]]]]), |
| 91 | + ( |
| 92 | + games.create_EFG_for_nxn_bimatrix_coordination_game(3), |
| 93 | + [ |
| 94 | + [[[1, 0, 0]], [[1, 0, 0]]], |
| 95 | + [[[0, 1, 0]], [[0, 1, 0]]], |
| 96 | + [[[0, 0, 1]], [[0, 0, 1]]], |
| 97 | + ], |
| 98 | + ), |
| 99 | + (games.create_EFG_for_6x6_bimatrix_with_long_LH_paths_and_unique_eq(), []), |
| 100 | + # 3-player game |
| 101 | + ( |
| 102 | + games.create_mixed_behav_game_efg(), |
| 103 | + [ |
| 104 | + [[[1, 0]], [[1, 0]], [[1, 0]]], |
| 105 | + [[[1, 0]], [[0, 1]], [[0, 1]]], |
| 106 | + [[[0, 1]], [[1, 0]], [[0, 1]]], |
| 107 | + [[[0, 1]], [[0, 1]], [[1, 0]]], |
| 108 | + ], |
| 109 | + ), |
| 110 | + ] |
| 111 | +) |
| 112 | +def test_enumpure_agent(game: gbt.Game, pure_behav_prof_data: list): |
| 113 | + """Test calls of enumeration of pure agent (behavior) equilibria |
| 114 | +
|
| 115 | + Tests max regret being zero (internal consistency) and compares the computed sequence of |
| 116 | + pure agent equilibria to a previosuly computed sequence (regression test) |
| 117 | + """ |
| 118 | + result = gbt.nash.enumpure_solve(game, use_strategic=False) |
| 119 | + assert len(result.equilibria) == len(pure_behav_prof_data) |
| 120 | + for eq, exp in zip(result.equilibria, pure_behav_prof_data): |
| 121 | + assert eq.max_regret() == 0 |
| 122 | + expected = game.mixed_behavior_profile(rational=True, data=exp) |
| 123 | + assert eq == expected |
30 | 124 |
|
31 | 125 |
|
32 | 126 | def test_enummixed_double(): |
|
0 commit comments