Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
90a5e36
Create catalog dir and move one EFG and one NFG into it from contrib/…
edwardchalstrey1 Feb 3, 2026
83dd410
ignore catalog files copied into pygambit
edwardchalstrey1 Feb 3, 2026
7fc2199
add failing tests
edwardchalstrey1 Feb 3, 2026
3c53bea
improve tests
edwardchalstrey1 Feb 3, 2026
898a916
add pandas to pyproject.toml
edwardchalstrey1 Feb 3, 2026
8f916db
add test_catalog_load_invalid_slug
edwardchalstrey1 Feb 3, 2026
606dd8a
create load function
edwardchalstrey1 Feb 3, 2026
00beed3
add catalog to __init__
edwardchalstrey1 Feb 3, 2026
64eb310
add games() function
edwardchalstrey1 Feb 3, 2026
d24befd
refactor to define READERS once
edwardchalstrey1 Feb 3, 2026
72aade1
Big refactor to get catalog files from catalog dir external to pygambit
edwardchalstrey1 Feb 3, 2026
e7953e9
update Makefile.am for the 2 examples we moved into the catalog so far
edwardchalstrey1 Feb 3, 2026
7490ae6
update Game.comment to be Game.description in Python code
edwardchalstrey1 Feb 4, 2026
ebf6829
Revert "update Game.comment to be Game.description in Python code"
edwardchalstrey1 Feb 4, 2026
fbf6b89
Add initial update catalog script and RST page
edwardchalstrey1 Feb 4, 2026
1ca3461
rename table headers on output df from game() func
edwardchalstrey1 Feb 4, 2026
bd3c1f3
add generating the catalog csv for docs into GH actions
edwardchalstrey1 Feb 4, 2026
569148c
Revert "add generating the catalog csv for docs into GH actions"
edwardchalstrey1 Feb 4, 2026
8cf0396
refactor update script so its run from repo root
edwardchalstrey1 Feb 4, 2026
1b20438
update readthedocs to build the catalog csv before docs build
edwardchalstrey1 Feb 4, 2026
e977e64
add function which updates Makefile.am
edwardchalstrey1 Feb 4, 2026
af08d29
use a proper path for CATALOG_CSV
edwardchalstrey1 Feb 4, 2026
cd2ffc9
tidy update script
edwardchalstrey1 Feb 4, 2026
5675444
use explicit python executable from the virtualenv to create CSV for …
edwardchalstrey1 Feb 4, 2026
f574223
add developer doc for updating the catalog
edwardchalstrey1 Feb 4, 2026
5147278
Don't update Makefile.am by default
edwardchalstrey1 Feb 4, 2026
4b033c9
consistency in notebook comment
edwardchalstrey1 Feb 4, 2026
b14402a
demo loading from catalog in tutorial 1
edwardchalstrey1 Feb 4, 2026
264f7fb
load from catalog for game examples in advanced tutorials
edwardchalstrey1 Feb 4, 2026
0e268a2
Try using pip instead of setuptools to ensure pyproject.toml deps ins…
edwardchalstrey1 Feb 4, 2026
8649946
remove deleted contrib games from Makefile.am
edwardchalstrey1 Feb 4, 2026
adea4f2
add a warning about moving games from contrib
edwardchalstrey1 Feb 4, 2026
a72f7a2
check if pandas duplications error exists if we dont save outputs on …
edwardchalstrey1 Feb 4, 2026
57863d4
fix problem with print function
edwardchalstrey1 Feb 4, 2026
b687e20
resave notebook outputs
edwardchalstrey1 Feb 4, 2026
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ Gambit.app/*
*.ef
build_support/msw/gambit.wxs
build_support/osx/Info.plist
src/pygambit/catalog
doc/catalog.csv
6 changes: 5 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ build:
- libgmp-dev
- pandoc
- texlive-full
jobs:
# Create CSV for catalog table in docs
post_install:
- $READTHEDOCS_VIRTUALENV_PATH/bin/python src/pygambit/update_catalog.py

python:
install:
- requirements: doc/requirements.txt
- method: setuptools
- method: pip
path: "."
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
recursive-include src/core *.cc *.h *.imp
recursive-include src/games *.cc *.h *.imp
recursive-include src/solvers *.c *.cc *.h *.imp
recursive-include catalog *
include src/gambit.h
include src/pygambit/*.pxd
include src/pygambit/*.pyx
Expand Down
10 changes: 5 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ EXTRA_DIST = \
src/gui/bitmaps/zoom1.xpm \
src/gui/bitmaps/gambitrc.rc \
contrib/games/2s2x2x2.efg \
contrib/games/2smp.efg \
contrib/games/2x2x2.efg \
contrib/games/4cards.efg \
contrib/games/artist1.efg \
Expand Down Expand Up @@ -169,7 +168,6 @@ EXTRA_DIST = \
contrib/games/my_3-3d.efg \
contrib/games/my_3-3e.efg \
contrib/games/my_3-4.efg \
contrib/games/myerson.efg \
contrib/games/nim7.efg \
contrib/games/nim.efg \
contrib/games/palf2.efg \
Expand All @@ -195,7 +193,6 @@ EXTRA_DIST = \
contrib/games/2x2a.nfg \
contrib/games/2x2const.nfg \
contrib/games/2x2.nfg \
contrib/games/2x2x2.nfg \
contrib/games/2x2x2x2.nfg \
contrib/games/2x2x2x2x2.nfg \
contrib/games/3x3x3.nfg \
Expand Down Expand Up @@ -224,7 +221,6 @@ EXTRA_DIST = \
contrib/games/mixdom2.nfg \
contrib/games/mixdom.nfg \
contrib/games/oneill.nfg \
contrib/games/pd.nfg \
contrib/games/perfect1.nfg \
contrib/games/perfect2.nfg \
contrib/games/perfect3.nfg \
Expand All @@ -240,7 +236,11 @@ EXTRA_DIST = \
contrib/games/winkels.nfg \
contrib/games/yamamoto.nfg \
contrib/games/zero.nfg \
src/README.rst
src/README.rst \
catalog/2smp.efg \
catalog/2x2x2.nfg \
catalog/myerson_fig_4_2.efg \
catalog/pd.nfg

core_SOURCES = \
src/core/core.h \
Expand Down
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions catalog/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from importlib.resources import as_file, files

import pandas as pd

import pygambit as gbt

# Use the full string path to the virtual package we created
_CATALOG_RESOURCE = files(__name__)

READERS = {
".nfg": gbt.read_nfg,
".efg": gbt.read_efg,
}


def load(slug: str) -> gbt.Game:
"""
Load a game from the package catalog.
"""
for suffix, reader in READERS.items():
resource_path = _CATALOG_RESOURCE / f"{slug}{suffix}"

if resource_path.is_file():
# as_file ensures we have a real filesystem path for the reader
with as_file(resource_path) as path:
return reader(str(path))

raise FileNotFoundError(f"No catalog entry called {slug}.nfg or {slug}.efg")


def games() -> pd.DataFrame:
"""
List games available in the package catalog.
"""
records: list[dict[str, str]] = []

# iterdir() works directly on the Traversable object
for resource_path in sorted(_CATALOG_RESOURCE.iterdir()):
reader = READERS.get(resource_path.suffix)

if reader is not None and resource_path.is_file():
with as_file(resource_path) as path:
game = reader(str(path))
records.append(
{
"Game": resource_path.stem,
"Title": game.title,
}
)

return pd.DataFrame.from_records(records, columns=["Game", "Title"])
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions doc/catalog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Catalog of games
================

.. csv-table::
:file: catalog.csv
:header-rows: 1
:widths: 20, 80
:class: tight-table
45 changes: 45 additions & 0 deletions doc/developer.catalog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Updating the Games Catalog
==========================

This page covers the process for contributing to and updating Gambit's :ref:`Games Catalog <pygambit-catalog>`.
To do so, you will need to have the `gambit` GitHub repo cloned and be able to submit pull request via GitHub;
you may wish to first review the :ref:`contributor guidelines <contributing>`.

You can add games to the catalog saved in a valid representation :ref:`format <file-formats>`.
Currently supported representations are:

- `.efg` for extensive form games
- `.nfg` for normal form games

Add new games
-------------

1. **Create the game file:**

Use either :ref:`pygambit <pygambit>`, the Gambit :ref:`CLI <command-line>` or :ref:`GUI <section-gui>` to create and save game in a valid representation :ref:`format <file-formats>`.

2. **Add the game file:**

Create a new branch in the ``gambit`` repo. Add your new game file(s) inside the ``catalog`` dir and commit them.

3. **Update the catalog:**

Use the ``update_catalog.py`` script to update Gambit's documentation & build files.

.. code-block:: bash

python src/pygambit/update_catalog.py --build

.. note::

Run this script in a Python environment where ``pygambit`` itself is also :ref:`installed <build-python>`.

.. warning::

This script updates `Makefile.am` with the game file added to the catalog, but if you moved games that were previously in `contrib/games` you'll want to manually remove those files from `EXTRA_DIST`.

4. **Submit a pull request to GitHub with all changes.**

.. warning::

Make sure you commit all changed files e.g. run ``git add --all`` before committing and pushing.
2 changes: 2 additions & 0 deletions doc/developer.contributing.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _contributing:

Contributing to Gambit
======================

Expand Down
1 change: 1 addition & 0 deletions doc/developer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ This section contains information for developers who want to contribute to the G

developer.build
developer.contributing
developer.catalog
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ We recommended most new users install the PyGambit Python package and read the a
pygambit
tools
gui
catalog
samples
developer
formats
Expand Down
Loading