Skip to content

Commit ed76dae

Browse files
committed
initial tests for lcp mixed strategies
1 parent ae68c65 commit ed76dae

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

tests/test_nash.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
TOL = 1e-13 # tolerance for floating point assertions
1818

1919

20+
def kuhn_poker_lcp_mixed_strategy_prof():
21+
alice = [0] * 27
22+
alice[1] = "2/3"
23+
alice[4] = "1/3"
24+
bob = [0] * 64
25+
bob[12] = "2/3"
26+
bob[30] = "1/3"
27+
return [alice, bob]
28+
29+
2030
def test_enumpure_strategy():
2131
"""Test calls of enumeration of pure strategies."""
2232
game = games.read_from_file("poker.efg")
@@ -143,19 +153,28 @@ def test_lcp_strategy_double():
143153

144154
@pytest.mark.nash
145155
@pytest.mark.nash_lcp_strategy
146-
def test_lcp_strategy_rational():
156+
@pytest.mark.parametrize(
157+
"game,mixed_strategy_prof_data,stop_after",
158+
[
159+
# Zero-sum games
160+
# (games.create_1_card_poker_efg(), [["1/3", "2/3", 0, 0], ["2/3", "1/3"]]),
161+
# (games.create_myerson_2_card_poker_efg(), [["1/3", "2/3", 0, 0], ["2/3", "1/3"]]),
162+
# (games.create_kuhn_poker_efg(), kuhn_poker_lcp_mixed_strategy_prof())
163+
(games.create_EFG_for_nxn_bimatrix_coordination_game(3), [[[1, 0, 0], [1, 0, 0]]], 1),
164+
# Non-zero-sum games
165+
]
166+
)
167+
def test_lcp_strategy_rational(game: gbt.Game, mixed_strategy_prof_data: list,
168+
stop_after: typing.Union[None, int]):
147169
"""Test calls of LCP for mixed strategy equilibria, rational precision."""
148-
game = games.read_from_file("poker.efg")
149-
result = gbt.nash.lcp_solve(game, use_strategic=True, rational=True)
170+
result = gbt.nash.lcp_solve(game, use_strategic=True, rational=True, stop_after=stop_after)
171+
print(result.equilibria)
150172
assert len(result.equilibria) == 1
151-
expected = game.mixed_strategy_profile(
152-
rational=True,
153-
data=[
154-
[gbt.Rational(1, 3), gbt.Rational(2, 3), gbt.Rational(0), gbt.Rational(0)],
155-
[gbt.Rational(2, 3), gbt.Rational(1, 3)],
156-
],
157-
)
158-
assert result.equilibria[0] == expected
173+
eq = result.equilibria[0]
174+
assert eq.max_regret() == 0
175+
print(eq)
176+
expected = game.mixed_strategy_profile(rational=True, data=mixed_strategy_prof_data[0])
177+
assert eq == expected
159178

160179

161180
def test_lcp_behavior_double():

0 commit comments

Comments
 (0)