Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion freeride/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,22 @@ def battle_of_the_sexes(cls) -> "Game":
action_names=(("Opera", "Boxing Match"), ("Opera", "Boxing Match")),
)

@classmethod
def bach_or_stravinsky(cls) -> "Game":
"""Return the Bach or Stravinsky coordination game."""

p1 = [[2, 0], [0, 1]]
p2 = [[1, 0], [0, 2]]
return cls(
p1,
p2,
player_names=("Anna", "Boris"),
action_names=(
("Bach", "Stravinsky"),
("Bach", "Stravinsky"),
),
)

@classmethod
def pure_coordination(cls) -> "Game":
"""Return a simple pure coordination game."""
Expand Down Expand Up @@ -584,4 +600,3 @@ def rock_paper_scissors(cls) -> "Game":

# Backwards compatibility
NormalFormGame = Game

13 changes: 13 additions & 0 deletions tests/test_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ def test_class_helpers(self):
# Test nash equilibrium with proper action names
self.assertEqual(set(bos.nash_equilibria()), {('Opera', 'Opera'), ('Boxing Match', 'Boxing Match')})

bos_alt = Game.bach_or_stravinsky()
self.assertEqual(bos_alt.payoffs1.tolist(), [[2, 0], [0, 1]])
self.assertEqual(bos_alt.payoffs2.tolist(), [[1, 0], [0, 2]])
self.assertEqual(bos_alt.player_names, ("Anna", "Boris"))
self.assertEqual(
bos_alt.action_names,
(("Bach", "Stravinsky"), ("Bach", "Stravinsky")),
)
self.assertEqual(
set(bos_alt.nash_equilibria()),
{("Bach", "Bach"), ("Stravinsky", "Stravinsky")},
)

sh = Game.stag_hunt()
self.assertEqual(sh.payoffs1.tolist(), [[2, 0], [1, 1]])
self.assertEqual(sh.payoffs2.tolist(), [[2, 1], [0, 1]])
Expand Down
Loading