Skip to content

Commit 2d3744f

Browse files
ignore games that are marked as invalid in the catalog
1 parent f31203b commit 2d3744f

3 files changed

Lines changed: 75 additions & 18 deletions

File tree

doc/tutorials/01_quickstart.ipynb

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,27 @@
485485
"gbt.catalog.games(game_type=\"nfg\", num_players=2)"
486486
]
487487
},
488+
{
489+
"cell_type": "code",
490+
"execution_count": 14,
491+
"id": "ff307b74-16bc-4889-b57c-fef3124ce5ca",
492+
"metadata": {},
493+
"outputs": [
494+
{
495+
"data": {
496+
"text/plain": [
497+
"''"
498+
]
499+
},
500+
"execution_count": 14,
501+
"metadata": {},
502+
"output_type": "execute_result"
503+
}
504+
],
505+
"source": [
506+
"gbt.catalog.PrisonersDilemma.description"
507+
]
508+
},
488509
{
489510
"cell_type": "markdown",
490511
"id": "a919ddf7",
@@ -495,7 +516,7 @@
495516
},
496517
{
497518
"cell_type": "code",
498-
"execution_count": 14,
519+
"execution_count": 15,
499520
"id": "6db7a29a",
500521
"metadata": {},
501522
"outputs": [
@@ -509,7 +530,7 @@
509530
"Game(title='Two person Prisoner's Dilemma game')"
510531
]
511532
},
512-
"execution_count": 14,
533+
"execution_count": 15,
513534
"metadata": {},
514535
"output_type": "execute_result"
515536
}
@@ -535,7 +556,7 @@
535556
},
536557
{
537558
"cell_type": "code",
538-
"execution_count": 15,
559+
"execution_count": 16,
539560
"id": "f58eaa77",
540561
"metadata": {},
541562
"outputs": [],
@@ -553,7 +574,7 @@
553574
},
554575
{
555576
"cell_type": "code",
556-
"execution_count": 16,
577+
"execution_count": 17,
557578
"id": "4119a2ac",
558579
"metadata": {},
559580
"outputs": [],

doc/tutorials/02_extensive_form.ipynb

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,30 @@
12381238
{
12391239
"cell_type": "code",
12401240
"execution_count": 16,
1241+
"id": "bd8b291b-6cc6-4f9a-b5c3-0d1f4c05252b",
1242+
"metadata": {},
1243+
"outputs": [
1244+
{
1245+
"data": {
1246+
"text/html": [
1247+
"Game(title='One-shot trust game, after Kreps (1990)')"
1248+
],
1249+
"text/plain": [
1250+
"Game(title='One-shot trust game, after Kreps (1990)')"
1251+
]
1252+
},
1253+
"execution_count": 16,
1254+
"metadata": {},
1255+
"output_type": "execute_result"
1256+
}
1257+
],
1258+
"source": [
1259+
"gbt.catalog.OneShotTrust(unique_NE_variant=True)"
1260+
]
1261+
},
1262+
{
1263+
"cell_type": "code",
1264+
"execution_count": 17,
12411265
"id": "4556c0bf",
12421266
"metadata": {},
12431267
"outputs": [
@@ -1416,7 +1440,7 @@
14161440
"<IPython.core.display.SVG object>"
14171441
]
14181442
},
1419-
"execution_count": 16,
1443+
"execution_count": 17,
14201444
"metadata": {},
14211445
"output_type": "execute_result"
14221446
}
@@ -1442,7 +1466,7 @@
14421466
},
14431467
{
14441468
"cell_type": "code",
1445-
"execution_count": 17,
1469+
"execution_count": 18,
14461470
"id": "37c51152",
14471471
"metadata": {},
14481472
"outputs": [],
@@ -1460,7 +1484,7 @@
14601484
},
14611485
{
14621486
"cell_type": "code",
1463-
"execution_count": 18,
1487+
"execution_count": 19,
14641488
"id": "0d86a750",
14651489
"metadata": {},
14661490
"outputs": [],
@@ -1479,7 +1503,7 @@
14791503
},
14801504
{
14811505
"cell_type": "code",
1482-
"execution_count": 19,
1506+
"execution_count": 20,
14831507
"id": "1bab777f-8a0b-4f1e-9c0c-270690288243",
14841508
"metadata": {},
14851509
"outputs": [],
@@ -1491,7 +1515,7 @@
14911515
},
14921516
{
14931517
"cell_type": "code",
1494-
"execution_count": 20,
1518+
"execution_count": 21,
14951519
"id": "2b715221-e427-4092-ad2f-9f4f2b548fa4",
14961520
"metadata": {},
14971521
"outputs": [],

src/pygambit/catalog/catalog.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,29 @@ def _generate_contrib_game_classes(catalog: dict[str, dict]) -> None:
171171
raise ValueError(f"Missing 'file' for catalog entry '{class_name}'")
172172

173173
game_file = entry["file"]
174+
metadata = entry.get("metadata", {})
174175

175-
cls = type(
176-
class_name,
177-
(CatalogGameFromContrib,),
178-
{
179-
"game_file": game_file,
180-
"__module__": __name__,
181-
},
182-
)
176+
# Build class attributes dict
177+
class_attrs = {
178+
"game_file": game_file,
179+
"__module__": __name__,
180+
}
181+
182+
# Add metadata fields as class attributes
183+
if metadata and "valid_game" in metadata and metadata["valid_game"] is False:
184+
pass # Marked as invalid game, do not create class
185+
else:
186+
if metadata:
187+
for key, value in metadata.items():
188+
class_attrs[key] = value
189+
190+
cls = type(
191+
class_name,
192+
(CatalogGameFromContrib,),
193+
class_attrs,
194+
)
183195

184-
setattr(module, class_name, cls)
196+
setattr(module, class_name, cls)
185197

186198

187199
# Generate classes at import time

0 commit comments

Comments
 (0)