|
1 | | -import inspect |
| 1 | +# import inspect |
2 | 2 |
|
3 | 3 | # import sys |
4 | 4 | from pathlib import Path |
5 | 5 |
|
6 | 6 | # import yaml |
7 | 7 | # from ..gambit import Game, read_efg, read_nfg |
8 | | -import pygambit as gbt |
| 8 | +# import pygambit as gbt |
9 | 9 |
|
10 | 10 | _GAMEFILES_DIR = Path(__file__).parent.parent.parent.parent / "contrib/games" |
11 | 11 |
|
12 | 12 |
|
13 | | -class CatalogGame: |
14 | | - """ |
15 | | - Base class for catalog games. |
16 | | - This class serves as a template for specific games in the catalog. |
17 | | - Calling any subclass will return an instance of the corresponding game. |
18 | | - """ |
19 | | - |
20 | | - game: gbt.Game | None = None |
21 | | - """Cached ``Game`` instance. Overwritten on each instantiation.""" |
22 | | - |
23 | | - def __new__(cls, *args, **kwargs) -> gbt.Game: |
24 | | - """Create a game instance by calling the _game() method.""" |
25 | | - cls.game = cls._game(*args, **kwargs) |
26 | | - cls._extract_description(cls.game) |
27 | | - return cls.game |
28 | | - |
29 | | - @staticmethod |
30 | | - def _game() -> gbt.Game: |
31 | | - """Override this method in subclasses to define the game.""" |
32 | | - raise NotImplementedError("Subclasses must implement _game() method") |
33 | | - |
34 | | - @classmethod |
35 | | - def _extract_description(cls, game: gbt.Game) -> None: |
36 | | - """Extract game description from docstring and apply to game.""" |
37 | | - cleaned_docstring = "" |
38 | | - if cls.__doc__: |
39 | | - cleaned_docstring = inspect.cleandoc(cls.__doc__) |
40 | | - if len(cleaned_docstring) > 0: |
41 | | - game.description = cleaned_docstring |
42 | | - |
43 | | - def __init_subclass__(cls, **kwargs): |
44 | | - """Extract metadata when subclass is defined (if not a file-based game).""" |
45 | | - super().__init_subclass__(**kwargs) |
46 | | - |
47 | | - # Skip if this is CatalogGameFromContrib or its subclasses |
48 | | - if cls.__name__ == "CatalogGameFromContrib" or issubclass(cls, CatalogGameFromContrib): |
49 | | - return |
50 | | - |
51 | | - # Load game and extract metadata immediately when class is defined |
52 | | - cls.game = cls._game() |
53 | | - cls._extract_description(cls.game) |
54 | | - |
55 | | - |
56 | | -class CatalogGameFromContrib(CatalogGame): |
57 | | - """ |
58 | | - Base class for catalog games loaded from files. |
59 | | - This class serves as a template for specific games in the catalog. |
60 | | - Calling any subclass will return an instance of the corresponding game. |
61 | | - """ |
62 | | - |
63 | | - game_file: str |
64 | | - """Filename of the game file in contrib/games directory.""" |
65 | | - |
66 | | - def __new__(cls) -> gbt.Game: |
67 | | - if cls.game is None: |
68 | | - cls.game = cls._load_game() |
69 | | - return cls.game |
70 | | - |
71 | | - @classmethod |
72 | | - def _load_game(cls) -> gbt.Game: |
73 | | - """Load the game from file.""" |
74 | | - if not hasattr(cls, "game_file") or cls.game_file is None: |
75 | | - raise TypeError(f"{cls.__name__} must define 'game_file' class attribute") |
76 | | - |
77 | | - game_type = cls.game_file.split(".")[-1] |
78 | | - file_path = _GAMEFILES_DIR / cls.game_file |
79 | | - |
80 | | - if game_type == "nfg": |
81 | | - return gbt.read_nfg(str(file_path)) |
82 | | - elif game_type == "efg": |
83 | | - return gbt.read_efg(str(file_path)) |
84 | | - else: |
85 | | - raise ValueError(f"gbt.Game file extension must be 'nfg' or 'efg', got '{game_type}'") |
86 | | - |
87 | | - def __init_subclass__(cls, **kwargs): |
88 | | - """Validate and extract metadata when subclass is defined.""" |
89 | | - super().__init_subclass__(**kwargs) |
90 | | - |
91 | | - # Load game and extract metadata immediately when class is defined |
92 | | - cls.game = cls._load_game() |
93 | | - cls._extract_description(cls.game) |
| 13 | +# class CatalogGame: |
| 14 | +# """ |
| 15 | +# Base class for catalog games. |
| 16 | +# This class serves as a template for specific games in the catalog. |
| 17 | +# Calling any subclass will return an instance of the corresponding game. |
| 18 | +# """ |
| 19 | + |
| 20 | +# game: gbt.Game | None = None |
| 21 | +# """Cached ``Game`` instance. Overwritten on each instantiation.""" |
| 22 | + |
| 23 | +# def __new__(cls, *args, **kwargs) -> gbt.Game: |
| 24 | +# """Create a game instance by calling the _game() method.""" |
| 25 | +# cls.game = cls._game(*args, **kwargs) |
| 26 | +# cls._extract_description(cls.game) |
| 27 | +# return cls.game |
| 28 | + |
| 29 | +# @staticmethod |
| 30 | +# def _game() -> gbt.Game: |
| 31 | +# """Override this method in subclasses to define the game.""" |
| 32 | +# raise NotImplementedError("Subclasses must implement _game() method") |
| 33 | + |
| 34 | +# @classmethod |
| 35 | +# def _extract_description(cls, game: gbt.Game) -> None: |
| 36 | +# """Extract game description from docstring and apply to game.""" |
| 37 | +# cleaned_docstring = "" |
| 38 | +# if cls.__doc__: |
| 39 | +# cleaned_docstring = inspect.cleandoc(cls.__doc__) |
| 40 | +# if len(cleaned_docstring) > 0: |
| 41 | +# game.description = cleaned_docstring |
| 42 | + |
| 43 | +# def __init_subclass__(cls, **kwargs): |
| 44 | +# """Extract metadata when subclass is defined (if not a file-based game).""" |
| 45 | +# super().__init_subclass__(**kwargs) |
| 46 | + |
| 47 | +# # Skip if this is CatalogGameFromContrib or its subclasses |
| 48 | +# if cls.__name__ == "CatalogGameFromContrib" or issubclass(cls, CatalogGameFromContrib): |
| 49 | +# return |
| 50 | + |
| 51 | +# # Load game and extract metadata immediately when class is defined |
| 52 | +# cls.game = cls._game() |
| 53 | +# cls._extract_description(cls.game) |
| 54 | + |
| 55 | + |
| 56 | +# class CatalogGameFromContrib(CatalogGame): |
| 57 | +# """ |
| 58 | +# Base class for catalog games loaded from files. |
| 59 | +# This class serves as a template for specific games in the catalog. |
| 60 | +# Calling any subclass will return an instance of the corresponding game. |
| 61 | +# """ |
| 62 | + |
| 63 | +# game_file: str |
| 64 | +# """Filename of the game file in contrib/games directory.""" |
| 65 | + |
| 66 | +# def __new__(cls) -> gbt.Game: |
| 67 | +# if cls.game is None: |
| 68 | +# cls.game = cls._load_game() |
| 69 | +# return cls.game |
| 70 | + |
| 71 | +# @classmethod |
| 72 | +# def _load_game(cls) -> gbt.Game: |
| 73 | +# """Load the game from file.""" |
| 74 | +# if not hasattr(cls, "game_file") or cls.game_file is None: |
| 75 | +# raise TypeError(f"{cls.__name__} must define 'game_file' class attribute") |
| 76 | + |
| 77 | +# game_type = cls.game_file.split(".")[-1] |
| 78 | +# file_path = _GAMEFILES_DIR / cls.game_file |
| 79 | + |
| 80 | +# if game_type == "nfg": |
| 81 | +# return gbt.read_nfg(str(file_path)) |
| 82 | +# elif game_type == "efg": |
| 83 | +# return gbt.read_efg(str(file_path)) |
| 84 | +# else: |
| 85 | +# raise ValueError(f"gbt.Game file extension must be 'nfg' or 'efg', got '{game_type}'") |
| 86 | + |
| 87 | +# def __init_subclass__(cls, **kwargs): |
| 88 | +# """Validate and extract metadata when subclass is defined.""" |
| 89 | +# super().__init_subclass__(**kwargs) |
| 90 | + |
| 91 | +# # Load game and extract metadata immediately when class is defined |
| 92 | +# cls.game = cls._load_game() |
| 93 | +# cls._extract_description(cls.game) |
94 | 94 |
|
95 | 95 |
|
96 | 96 | # def games( |
|
0 commit comments