diff --git a/freeride/games.py b/freeride/games.py index 98e0f8e..c84f13f 100644 --- a/freeride/games.py +++ b/freeride/games.py @@ -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.""" @@ -584,4 +600,3 @@ def rock_paper_scissors(cls) -> "Game": # Backwards compatibility NormalFormGame = Game - diff --git a/tests/test_games.py b/tests/test_games.py index af73d82..8c5ef8f 100644 --- a/tests/test_games.py +++ b/tests/test_games.py @@ -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]])