Skip to content

Commit d543ec2

Browse files
committed
Merge branch 'master' into issue_823
2 parents 6c508b3 + 06018d9 commit d543ec2

20 files changed

Lines changed: 553 additions & 169 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ Gambit.app/*
5151
build_support/msw/gambit.wxs
5252
build_support/osx/Info.plist
5353
src/pygambit/catalog
54-
doc/catalog.csv
54+
doc/catalog_table.rst

build_support/catalog/update.py

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,106 @@
11
import argparse
22
from pathlib import Path
33

4+
import pandas as pd
5+
46
import pygambit as gbt
57

6-
CATALOG_CSV = Path(__file__).parent.parent.parent / "doc" / "catalog.csv"
8+
CATALOG_RST_TABLE = Path(__file__).parent.parent.parent / "doc" / "catalog_table.rst"
79
CATALOG_DIR = Path(__file__).parent.parent.parent / "catalog"
810
MAKEFILE_AM = Path(__file__).parent.parent.parent / "Makefile.am"
911

1012

13+
def _write_efg_table(df: pd.DataFrame, f):
14+
"""Write the EFG games list-table to file handle f."""
15+
f.write(".. list-table::\n")
16+
f.write(" :header-rows: 1\n")
17+
f.write(" :widths: 100\n")
18+
f.write(" :class: tight-table\n")
19+
f.write("\n")
20+
f.write(" * - **Extensive form games**\n")
21+
22+
efg_df = df[df["Format"] == "efg"]
23+
for _, row in efg_df.iterrows():
24+
slug = row["Game"]
25+
title = str(row.get("Title", "")).strip()
26+
description = str(row.get("Description", "")).strip()
27+
# Skip any games which lack a description
28+
if description:
29+
# Main dropdown
30+
f.write(f" * - .. dropdown:: {title}\n")
31+
f.write(" :open:\n")
32+
f.write(" \n")
33+
for line in description.splitlines():
34+
f.write(f" {line}\n")
35+
f.write(" \n")
36+
f.write(" **Load in PyGambit:**\n")
37+
f.write(" \n")
38+
f.write(" .. code-block:: python\n")
39+
f.write(" \n")
40+
f.write(f' pygambit.catalog.load("{slug}")\n')
41+
f.write(" \n")
42+
43+
# Download links (inside the dropdown)
44+
download_links = [row["Download"]]
45+
f.write(" **Download:**\n")
46+
f.write(" \n")
47+
f.write(f" {' '.join(download_links)}\n")
48+
f.write(" \n")
49+
50+
51+
# def _write_nfg_table(df: pd.DataFrame, f):
52+
# """Write the NFG games list-table to file handle f."""
53+
# f.write(".. list-table::\n")
54+
# f.write(" :header-rows: 1\n")
55+
# f.write(" :widths: 100\n")
56+
# f.write(" :class: tight-table\n")
57+
# f.write("\n")
58+
# f.write(" * - **Strategic form games**\n")
59+
60+
# nfg_df = df[df["Format"] == "nfg"]
61+
# for _, row in nfg_df.iterrows():
62+
# slug = row["Game"]
63+
64+
# # Title as plain text header
65+
# f.write(" * - \n")
66+
# f.write(" \n")
67+
68+
# # Jupyter-execute block (no dropdown)
69+
# f.write(" .. jupyter-execute::\n")
70+
# f.write(" \n")
71+
# f.write(" import pygambit\n")
72+
# f.write(f' pygambit.catalog.load("{slug}")\n')
73+
# f.write(" \n")
74+
75+
# # Download link (plain, no dropdown)
76+
# f.write(f" :download:`{slug}.nfg <../catalog/{slug}.nfg>`\n")
77+
# f.write(" \n")
78+
79+
80+
def generate_rst_table(df: pd.DataFrame, rst_path: Path):
81+
"""Generate RST output with two list-tables: one for EFG and one for NFG games."""
82+
83+
with open(rst_path, "w", encoding="utf-8") as f:
84+
# TOC linking to both sections
85+
# f.write(".. contents::\n")
86+
# f.write(" :local:\n")
87+
# f.write(" :depth: 1\n")
88+
# f.write("\n")
89+
90+
# EFG section
91+
# f.write("Extensive form games\n")
92+
# f.write("--------------------\n")
93+
# f.write("\n")
94+
_write_efg_table(df, f)
95+
# f.write("\n")
96+
97+
# # NFG section
98+
# f.write("Strategic form games\n")
99+
# f.write("--------------------\n")
100+
# f.write("\n")
101+
# _write_nfg_table(df, f)
102+
103+
11104
def update_makefile():
12105
"""Update the Makefile.am with all games from the catalog."""
13106

@@ -60,15 +153,14 @@ def update_makefile():
60153

61154

62155
if __name__ == "__main__":
63-
64156
parser = argparse.ArgumentParser()
65157
parser.add_argument("--build", action="store_true")
66158
args = parser.parse_args()
67159

68-
# Create CSV used by RST docs page
69-
gbt.catalog.games().to_csv(CATALOG_CSV, index=False)
70-
print(f"Generated {CATALOG_CSV} for use in local docs build. DO NOT COMMIT.")
71-
72-
# Update the Makefile.am with the current list of catalog files
160+
# Create RST list-table used by doc/catalog.rst
161+
df = gbt.catalog.games(include_descriptions=True)
162+
generate_rst_table(df, CATALOG_RST_TABLE)
163+
print(f"Generated {CATALOG_RST_TABLE} for use in local docs build. DO NOT COMMIT.")
73164
if args.build:
165+
# Update the Makefile.am with the current list of catalog files
74166
update_makefile()

catalog/bagwell1995.efg

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
EFG 2 R "Bagwell (GEB 1995) commitment and (un)observability" { "Player 1" "Player 2" }
22
"This is a Stackelberg-type game with imperfectly observed commitment, following the
3-
analysis of Bagwell [^Bag1995]. The outcomes and payoffs are the same as in Bagwell's
3+
analysis of `Bag1995 <https://gambitproject.readthedocs.io/en/latest/biblio.html#Bag1995>`_. The outcomes and payoffs are the same as in Bagwell's
44
model. This example sets the probability that the follower 'correctly' observes the
55
leader's action as .99 (99/100). The key result is that the only pure-strategy
66
equilibrium that survives if observability is imperfect is the one in which players
77
choose the actions that would form an equilibrium if the game was a *simultaneous-move*
88
game. There is an equilibrium in which the 'Stackelberg' action is played with high
99
probability, but strictly less than one.
10-
11-
[^Bag1995]: Bagwell, Kyle (1995) Commitment and observability in games.
12-
_Games and Economic Behavior_ 8: 271-280.
1310
"
1411

1512
p "" 1 1 "" { "S" "C" } 0

catalog/myerson1991/fig2_1.efg

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
EFG 2 R "A simple Poker game" { "Fred" "Alice" }
2-
"This is a simple game of one-card poker from Myerson [^Mye91], used as the
2+
"This is a simple game of one-card poker from `Mye91 <https://gambitproject.readthedocs.io/en/latest/biblio.html#Mye91>`_, used as the
33
introductory example for game models.
44

55
Note that as specified in the text, the game has the slightly unusual feature
66
that folding with the high (red) card results in the player winning rather than
77
losing.
88

9-
See also
10-
--------
11-
reiley2008/fig1
9+
See also `Rei2008 <https://gambitproject.readthedocs.io/en/latest/biblio.html#Rei2008>`_
1210
Another one-card poker game where folding with the high card is a loss rather
1311
than a win.
14-
15-
16-
[^Mye1991]: Myerson, Roger B. (1991) Game Theory: Analysis of Conflict.
17-
Cambridge: Harvard University Press.
1812
"
1913

2014
c "" 1 "" { "Red" 1/2 "Black" 1/2 } 0

catalog/myerson1991/fig4_2.efg

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
EFG 2 R "Myerson (1991) Figure 4.2" { "Player 1" "Player 2" }
2-
"An example from Myerson [^Mye1991] which illustrates the distinction between
2+
"An example from `Mye91 <https://gambitproject.readthedocs.io/en/latest/biblio.html#Mye91>`_ which illustrates the distinction between
33
an equilibrium of an extensive form game and an equilibrium of its
44
(multi)agent representation. The actions B1, Z1, and W2 form a
55
behavior profile which is an equilibrium in the (multi)agent
66
representation. However, it is not a Nash equilibrium of the extensive
77
game, because Player 1 would prefer to switch from (B1, Z1) to
88
(A1, Y1); the (multi)agent representation rules out such coordinated
99
deviations across information sets.
10-
11-
[^Mye1991]: Myerson, Roger B. (1991) Game Theory: Analysis of Conflict.
12-
Cambridge: Harvard University Press.
1310
"
1411

1512
p "" 1 1 "" { "A1" "B1" } 0

catalog/reiley2008/fig1.efg

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
EFG 2 R "Stripped-down poker (Reiley et al 2008)" { "Professor" "Student" }
2-
"This is a one-card poker game used in [^Rei2008] as a teaching exercise.
2+
"This is a one-card poker game used in `Rei2008 <https://gambitproject.readthedocs.io/en/latest/biblio.html#Rei2008>`_ as a teaching exercise.
33

4-
See also
5-
--------
6-
myerson1991/fig2_1
4+
See also `Mye91 <https://gambitproject.readthedocs.io/en/latest/biblio.html#Mye91>`_
75
Another one-card poker game with slightly different rules.
8-
9-
[^Rei2008]: Reiley, David H., Urbancic, Michael B, and Walker, Mark. (2008)
10-
Stripped-Down Poker: A Classroom Game with Signaling and Bluffing.
11-
_The Journal of Economic Education_ 4: 323-341.
126
"
137

148
c "" 1 "" { "King" 1/2 "Queen" 1/2 } 0

catalog/selten1975/fig1.efg

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
EFG 2 R "Selten's horse (Selten IJGT 1975, Figure 1)" { "Player 1" "Player 2" "Player 3" }
2-
"This is a three-player game presented in Selten [^Sel1975], commonly referred
2+
"This is a three-player game presented in `Sel75 <https://gambitproject.readthedocs.io/en/latest/biblio.html#Sel75>`_, commonly referred
33
to as \"Selten's horse\" owing to the layout in which it can be drawn.
44
It is the motivating example for his definition of (trembling-hand)
55
perfect equilibrium, by showing a game that has an equilibrium which
66
is \"unreasonable\", but which is not ruled out by subgame perfection because
77
this game has no proper subgames.
8-
9-
[^Sel1975]: Selten, Reinhard (1975). A reexamination of the perfectness concept
10-
for equilibrium points in extensive games. International Journal of Game
11-
Theory 4(1): 25-55.
128
"
139

1410
p "" 1 1 "" { "R" "L" } 0

catalog/selten1975/fig2.efg

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
EFG 2 R "Selten (IJGT 1975) Figure 2" { "Player 1" "Player 2" }
2-
"This is a counterexample presented in [^Sel1975], to show that extensive and
2+
"This is a counterexample presented in `Sel75 <https://gambitproject.readthedocs.io/en/latest/biblio.html#Sel75>`_, to show that extensive and
33
normal form concepts of perfectness do not coincide. This game has one
44
perfect equilibrium in the extensive from, but a distinct (pure) strategy
55
equilibrium is also perfect in the normal form.
6-
7-
[^Sel75]: Selten, Reinhard (1975). A reexamination of the perfectness concept
8-
for equilibrium points in extensive games. International Journal of Game
9-
Theory 4(1): 25-55.
106
"
117

128
p "" 1 1 "" { "R" "L" } 0

catalog/selten1975/fig3.efg

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
EFG 2 R "Selten (IJGT 1975) Figure 3" { "Player 1" "Player 2" "Player 3" }
2-
"This is a counterexample presented in [^Sel1975], to show that extensive and
2+
"This is a counterexample presented in `Sel75 <https://gambitproject.readthedocs.io/en/latest/biblio.html#Sel75>`_, to show that extensive and
33
normal form concepts of perfectness do not coincide. Specifically, there
44
are two equilibria which are perfect in the normal form but not perfect
55
in the extensive form.
6-
7-
[^Sel75]: Selten, Reinhard (1975). A reexamination of the perfectness concept
8-
for equilibrium points in extensive games. International Journal of Game
9-
Theory 4(1): 25-55.
106
"
117

128
p "" 1 1 "" { "R" "L" } 0

catalog/watson2013/exercise29_6.efg

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
EFG 2 R "Princess Bride signaling game (from Watson)" { "Wesley" "Prince" }
2-
"This game is Exercise 29.6 from Watson [^Wat13], based on a scene from
3-
the Rob Reiner film, _The Princess Bride_:
2+
"This game is Exercise 29.6 from Watson `Wat13 <https://gambitproject.readthedocs.io/en/latest/biblio.html#Wat13>`_, based on a scene from
3+
the Rob Reiner film, The Princess Bride:
44

55
Wesley (the protagonist) confronts the evil prince Humperdinck. Wesley
66
is one of two types: weak or strong. Wesley knows whether he is weak or
@@ -15,9 +15,6 @@ swordsman. Also, the weak Wesley must pay a cost to get out of bed.
1515

1616
In the game in this file, the cost the weak Wesley pays to get out of bed
1717
is set to 2.
18-
19-
[^Wat13]: Watson, Joel. (2013) Strategy: An Introduction to Game Theory,
20-
third edition. W. W. Norton & Company.
2118
"
2219

2320
c "" 1 "" { "Strong" 1/2 "Weak" 1/2 } 0

0 commit comments

Comments
 (0)