11from pathlib import Path
22
3+ import numpy as np
4+
35from pygambit import Game , read_efg , read_nfg
46
57_CATALOG_DIR = Path (__file__ ).parent
@@ -12,6 +14,17 @@ class CatalogGame:
1214 This class serves as a template for specific games in the catalog.
1315 Calling any subclass will return an instance of the corresponding game.
1416 """
17+
18+ def __new__ (cls ) -> Game :
19+ raise NotImplementedError ("Subclasses must implement __new__ method" )
20+
21+
22+ class CatalogGameFromFile (CatalogGame ):
23+ """
24+ Base class for catalog games loaded from files.
25+ This class serves as a template for specific games in the catalog.
26+ Calling any subclass will return an instance of the corresponding game.
27+ """
1528 # Subclasses must define these
1629 game_file : str | None = None
1730
@@ -39,11 +52,25 @@ def __init_subclass__(cls, **kwargs):
3952 raise TypeError (f"{ cls .__name__ } must define 'game_file' class attribute" )
4053
4154
42- class PrisonersDilemma (CatalogGame ):
55+ class PrisonersDilemma (CatalogGameFromFile ):
4356 """Prisoner's Dilemma game."""
4457 game_file = "pd.nfg"
4558
4659
47- class TwoStageMatchingPennies (CatalogGame ):
60+ class TwoStageMatchingPennies (CatalogGameFromFile ):
4861 """Two-Stage Matching Pennies game."""
4962 game_file = "2smp.efg"
63+
64+
65+ class PrisonersDilemmaTestgame (CatalogGame ):
66+ """A simple test game based on the Prisoner's Dilemma."""
67+ def __new__ (cls ) -> Game :
68+ player1_payoffs = np .array ([[- 1 , - 3 ], [0 , - 2 ]])
69+ player2_payoffs = np .transpose (player1_payoffs )
70+
71+ g1 = Game .from_arrays (
72+ player1_payoffs ,
73+ player2_payoffs ,
74+ title = "Test Prisoner's Dilemma"
75+ )
76+ return g1
0 commit comments