Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions build_support/catalog/catalog.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
CATALOG_FILES = \
catalog/books/myerson1991/fig2_1.efg \
catalog/books/myerson1991/fig4_2.efg \
catalog/books/shohambrown2008/fig5_1.efg \
catalog/books/shohambrown2008/fig5_10.efg \
catalog/books/shohambrown2008/fig5_10__original_layout.ef \
catalog/books/shohambrown2008/fig5_11.efg \
catalog/books/shohambrown2008/fig5_11__original_layout.ef \
catalog/books/shohambrown2008/fig5_12.efg \
catalog/books/shohambrown2008/fig5_12__original_layout.ef \
catalog/books/shohambrown2008/fig5_15.efg \
catalog/books/shohambrown2008/fig5_15__original_layout.ef \
catalog/books/shohambrown2008/fig5_1__original_layout.ef \
catalog/books/shohambrown2008/fig5_2.efg \
catalog/books/shohambrown2008/fig5_2__original_layout.ef \
catalog/books/shohambrown2008/fig5_9.efg \
catalog/books/shohambrown2008/fig5_9__original_layout.ef \
catalog/books/shohambrown2008/fig6_2.efg \
catalog/books/shohambrown2008/fig6_2__original_layout.ef \
catalog/books/shohambrown2008/fig6_8.efg \
catalog/books/shohambrown2008/fig6_8__original_layout.ef \
catalog/books/vonstengel2022/fig10.1.efg \
catalog/books/vonstengel2022/fig10.12.efg \
catalog/books/vonstengel2022/fig10.5.efg \
Expand All @@ -23,6 +41,7 @@ CATALOG_FILES = \
catalog/journals/ijgt/selten1975/fig2.efg \
catalog/journals/ijgt/selten1975/fig3.efg \
catalog/journals/mor/vonstengelforges2008/fig1.efg \
catalog/journals/mor/vonstengelforges2008/fig1__Original_Layout.ef \
catalog/journals/mor/vonstengelforges2008/fig6.efg \
catalog/journals/mor/vonstengelforges2008/fig6__Original_Layout.ef \
catalog/journals/mor/vonstengelforges2008/fig9.efg \
Expand Down
1 change: 1 addition & 0 deletions build_support/catalog/catalog_hierarchy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ labels:
books/myerson1991: "Myerson (1991) — Game Theory: Analysis of Conflict"
books/vonstengel2022: "von Stengel (2022) — Game Theory Basics"
books/watson2013: "Watson (2013) — Strategy: An Introduction to Game Theory"
books/shohambrown2008: "Shoham and Leyton-Brown (2008) — Multiagent Systems, Algorithmic, Game-Theoretic, and Logical Foundations"
journals/geb/gilboa1997: "Gilboa (1997)"
journals/geb/wichardt2008: "Wichardt (2008)"
journals/ijgt/nau2004: "Nau et al. (2004)"
Expand Down
28 changes: 28 additions & 0 deletions build_support/catalog/gtdraw_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,31 @@ overrides:
2: '#DD79E0'
3: '#1616BC'
4: '#985003'

books/shohambrown2008/fig6_8:
scale_factor: 1.0
level_scaling: 1.0
sublevel_scaling: 1.0
width_scaling: 1.0
horizontal: false
mirror: false
shared_terminal_depth: false
color_scheme: colorblind
edge_thickness: 1.0
action_label_position: 0.5
action_label_position_by: player
action_label_dist: 1.0
vary_action_label_positions: false
vary_action_label_positions_by: all
font_family: rmfamily
font_bold: false
font_italic: false
font_size: normalsize
node_size: 1.5
label_bg: false
label_bg_color: white
label_bg_opacity: 0.8
iset_fill: false
iset_fill_opacity: 0.2
iset_boundary: solid
legend_position: top-left
51 changes: 51 additions & 0 deletions build_support/catalog/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,57 @@ def _make_image_files(catalog_dir, slug, fmt="efg"):
(img_dir / f"{slug}.ef").touch()


# ---------------------------------------------------------------------------
# Tests for catalog resource selection
# ---------------------------------------------------------------------------


@pytest.mark.catalog_update
class TestCatalogResourceSelection:
def test_catalog_games_uses_requested_catalog_dir_and_restores_resource(
self, tmp_path, monkeypatch
):
stale_dir = tmp_path / "installed_catalog_data"
checkout_dir = tmp_path / "checkout_catalog"
stale_dir.mkdir()
checkout_dir.mkdir()
calls = []

def fake_games(**kwargs):
calls.append((update.gbt.catalog._CATALOG_RESOURCE, kwargs))
return _make_df(_efg_row("checkout/game1"))

monkeypatch.setattr(update.gbt.catalog, "_CATALOG_RESOURCE", stale_dir)
monkeypatch.setattr(update.gbt.catalog, "games", fake_games)

df = update._catalog_games(checkout_dir)

assert calls == [(checkout_dir, {"include_descriptions": True})]
assert stale_dir == update.gbt.catalog._CATALOG_RESOURCE
assert list(df["Game"]) == ["checkout/game1"]

def test_generate_rst_table_uses_requested_catalog_dir_while_rendering(
self, tmp_path, monkeypatch
):
stale_dir = tmp_path / "installed_catalog_data"
checkout_dir = tmp_path / "checkout_catalog"
stale_dir.mkdir()
checkout_dir.mkdir()
observed = []

def fake_write_tree_level(*args, **kwargs):
observed.append(update.gbt.catalog._CATALOG_RESOURCE)

monkeypatch.setattr(update.gbt.catalog, "_CATALOG_RESOURCE", stale_dir)
monkeypatch.setattr(update, "load_hierarchy_labels", lambda: {})
monkeypatch.setattr(update, "_write_tree_level", fake_write_tree_level)

update.generate_rst_table(_make_df(), tmp_path / "out.rst", catalog_dir=checkout_dir)

assert observed == [checkout_dir]
assert stale_dir == update.gbt.catalog._CATALOG_RESOURCE


# ---------------------------------------------------------------------------
# Tests for catalog_gtdraw_settings
# ---------------------------------------------------------------------------
Expand Down
23 changes: 21 additions & 2 deletions build_support/catalog/update.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import shutil
import sys
from contextlib import contextmanager
from pathlib import Path

import pandas as pd
Expand All @@ -17,6 +18,24 @@
SUPPORTED_GAME_FORMATS = {"efg", "nfg"}


@contextmanager
def _using_catalog_dir(catalog_dir: Path):
"""Temporarily make pygambit.catalog read data from the checked-out catalog."""
old_resource = gbt.catalog._CATALOG_RESOURCE
gbt.catalog._CATALOG_RESOURCE = catalog_dir
try:
yield
finally:
gbt.catalog._CATALOG_RESOURCE = old_resource


def _catalog_games(catalog_dir: Path | None = None) -> pd.DataFrame:
"""Return catalog games using files from *catalog_dir*, not installed package data."""
catalog_dir = catalog_dir or CATALOG_DIR
with _using_catalog_dir(catalog_dir):
return gbt.catalog.games(include_descriptions=True)


def catalog_gtdraw_settings(slug: str) -> dict:
"""Return the gtdraw settings for a given catalog slug."""
with open(GTDRAW_SETTINGS_CONFIG, encoding="utf-8") as f:
Expand Down Expand Up @@ -325,7 +344,7 @@ def generate_rst_table(
catalog_dir = catalog_dir or CATALOG_DIR
labels = load_hierarchy_labels()
tree = _build_slug_tree(df)
with open(rst_path, "w", encoding="utf-8") as f:
with _using_catalog_dir(catalog_dir), open(rst_path, "w", encoding="utf-8") as f:
_write_tree_level(
f, tree, "", labels, catalog_dir, indent="", regenerate_images=regenerate_images
)
Expand Down Expand Up @@ -409,7 +428,7 @@ def update_makefile(
args = parser.parse_args()

# Create RST list-table used by doc/catalog.rst
df = gbt.catalog.games(include_descriptions=True)
df = _catalog_games()
_warn_missing_descriptions(df)
generate_rst_table(df, CATALOG_RST_TABLE, regenerate_images=args.regenerate_images)
print(f"Generated {CATALOG_RST_TABLE} for use in local docs build. DO NOT COMMIT.")
Expand Down
21 changes: 21 additions & 0 deletions catalog/books/shohambrown2008/fig5_1.efg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
EFG 2 R "Fig 5.1 from Shoham and Leyton-Brown (2008)" { "1" "2" }

"
Figure 5.1 from :cite:p:`ShoLeyB08`.
This is a sharing game. Imagine a brother and sister sharing two indivisible and identical presents
from their parents. First the brother suggests a split, which can be one of three: he
keeps both, she keeps both, or they each keep one. Then the sister chooses whether
to accept or reject the split. If she accepts they each get their allocated present(s),
and otherwise neither gets any gift.
"

p "" 1 1 "" { "2-0" "1-1" "0-2" } 0
p "" 2 2 "" { "no" "yes" } 0
t "" 1 "" { 0 0 }
t "" 2 "" { 2 0 }
p "" 2 3 "" { "no" "yes" } 0
t "" 3 "" { 0 0 }
t "" 4 "" { 1 1 }
p "" 2 4 "" { "no" "yes" } 0
t "" 5 "" { 0 0 }
t "" 6 "" { 0 2 }
16 changes: 16 additions & 0 deletions catalog/books/shohambrown2008/fig5_10.efg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
EFG 2 R "Fig 5.10 from Shoham and Leyton-Brown (2008)" { "1" "2" }

"
Figure 5.10 from :cite:p:`ShoLeyB08`.
This is an example of an imperfect-information game.
"

p "" 1 2 "" { "L" "R" } 0
p "" 2 3 "" { "A" "B" } 0
p "" 1 1 "" { "l" "r" } 0
t "" 1 "" { 0 0 }
t "" 2 "" { 2 4 }
p "" 1 1 0
t "" 3 "" { 4 2 }
t "" 4 "" { 0 0 }
t "" 5 "" { 0 0 }
12 changes: 12 additions & 0 deletions catalog/books/shohambrown2008/fig5_10__original_layout.ef
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
player 1 name 1
player 2 name 2
level 0 node 1 player 1
level 2 node 1 player 2 xshift -3.58 from 0,1 move L
level 2 node 2 xshift 3.58 from 0,1 move R payoffs 0 0
level 4 node 1 xshift -2.86 from 2,1 move A
level 4 node 2 xshift 2.86 from 2,1 move B
level 6 node 1 xshift -1.43 from 4,1 move l payoffs 0 0
level 6 node 2 xshift 1.43 from 4,1 move r payoffs 2 4
level 6 node 3 xshift -1.43 from 4,2 move l payoffs 4 2
level 6 node 4 xshift 1.43 from 4,2 move r payoffs 0 0
iset 4,1 4,2 player 1
14 changes: 14 additions & 0 deletions catalog/books/shohambrown2008/fig5_11.efg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
EFG 2 R "Fig 5.11 from Shoham and Leyton-Brown (2008)" { "1" "2" }

"
Figure 5.11 from :cite:p:`ShoLeyB08`.
The Prisoner's Dilemma game in extensive form.
"

p "" 1 2 "" { "C" "D" } 0
p "" 2 1 "" { "c" "d" } 0
t "" 1 "" { -1 -1 }
t "" 2 "" { -4 0 }
p "" 2 1 0
t "" 3 "" { 0 -4 }
t "" 4 "" { -3 -3 }
10 changes: 10 additions & 0 deletions catalog/books/shohambrown2008/fig5_11__original_layout.ef
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
player 1 name 1
player 2 name 2
level 0 node 1 player 1
level 2 node 1 xshift -3.58 from 0,1 move C
level 2 node 2 xshift 3.58 from 0,1 move D
level 4 node 1 xshift -1.79 from 2,1 move c payoffs -1 -1
level 4 node 2 xshift 1.79 from 2,1 move d payoffs -4 0
level 4 node 3 xshift -1.79 from 2,2 move c payoffs 0 -4
level 4 node 4 xshift 1.79 from 2,2 move d payoffs -3 -3
iset 2,1 2,2 player 2
15 changes: 15 additions & 0 deletions catalog/books/shohambrown2008/fig5_12.efg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
EFG 2 R "Fig 5.12 from Shoham and Leyton-Brown (2008)" { "1" "2" }

"
Figure 5.12 from :cite:p:`ShoLeyB08`.
A game with imperfect recall, in particular absent-mindedness.
"


p "" 1 1 "" { "L" "R" } 0
p "" 1 1 0
t "" 1 "" { 1 0 }
t "" 2 "" { 100 100 }
p "" 2 2 "" { "U" "D" } 0
t "" 3 "" { 5 1 }
t "" 4 "" { 2 2 }
15 changes: 15 additions & 0 deletions catalog/books/shohambrown2008/fig5_12__original_layout.ef
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
% Extensive-form game transcribed from the uploaded image
player 1 name 1
player 2 name 2

% Player 1's two decision nodes are in the same information set.
level 0 node 1
level 2 node 1 xshift -3 from 0,1 move L
level 2 node 2 xshift 3 from 0,1 move R player 2

level 4 node 1 xshift -1 from 2,1 move L payoffs 1 0
level 4 node 2 xshift 1 from 2,1 move R payoffs 100 100
level 4 node 3 xshift -1 from 2,2 move U payoffs 5 1
level 4 node 4 xshift 1 from 2,2 move D payoffs 2 2

iset 0,1 2,1 player 1
17 changes: 17 additions & 0 deletions catalog/books/shohambrown2008/fig5_15.efg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
EFG 2 R "Fig 5.15 from Shoham and Leyton-Brown (2008)" { "1" "2" }

"
Figure 5.15 from :cite:p:`ShoLeyB08`.
A game with imperfect information.
This example shows how a requirement that a substrategy be a best response in
all subgames is too simplistic for defining SPE in games with imperfect information.
"

p "" 1 2 "" { "L" "C" "R" } 0
t "" 1 "" { 1 1 }
p "" 2 1 "" { "U" "D" } 0
t "" 2 "" { 0 1000 }
t "" 3 "" { 0 0 }
p "" 2 1 0
t "" 4 "" { 1 0 }
t "" 5 "" { 3 1 }
11 changes: 11 additions & 0 deletions catalog/books/shohambrown2008/fig5_15__original_layout.ef
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
player 1 name 1
player 2 name 2
level 0 node 1 player 1
level 2 node 1 xshift -5.01 from 0,1 move L payoffs 1 1
level 2 node 2 xshift -0.72 from 0,1 move C
level 2 node 3 xshift 5.01 from 0,1 move R
level 4 node 1 xshift -1.43 from 2,2 move U payoffs 0 1000
level 4 node 2 xshift 1.43 from 2,2 move D payoffs 0 0
level 4 node 3 xshift -1.43 from 2,3 move U payoffs 1 0
level 4 node 4 xshift 1.43 from 2,3 move D payoffs 3 1
iset 2,2 2,3 player 2
12 changes: 12 additions & 0 deletions catalog/books/shohambrown2008/fig5_1__original_layout.ef
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
player 1 name 1
player 2 name 2
level 0 node 1 player 1
level 2 node 1 player 2 xshift -4.77 from 0,1 move 2-0
level 2 node 2 player 2 xshift 0 from 0,1 move 1-1
level 4 node 1 xshift -1.19 from 2,1 move no payoffs 0 0
level 4 node 2 xshift 1.19 from 2,1 move yes payoffs 2 0
level 2 node 3 player 2 xshift 4.77 from 0,1 move 0-2
level 4 node 3 xshift -1.19 from 2,2 move no payoffs 0 0
level 4 node 4 xshift 1.19 from 2,2 move yes payoffs 1 1
level 4 node 5 xshift -1.19 from 2,3 move no payoffs 0 0
level 4 node 6 xshift 1.19 from 2,3 move yes payoffs 0 2
16 changes: 16 additions & 0 deletions catalog/books/shohambrown2008/fig5_2.efg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
EFG 2 R "Fig 5.2 from Shoham and Leyton-Brown (2008)" { "1" "2" }

"
Figure 5.2 from :cite:p:`ShoLeyB08`.
This is an example of a perfect-information game in extensive form.
"

p "" 1 1 "" { "A" "B" } 0
p "" 2 2 "" { "C" "D" } 0
t "" 1 "" { 3 8 }
t "" 2 "" { 8 3 }
p "" 2 3 "" { "E" "F" } 0
t "" 3 "" { 5 5 }
p "" 1 4 "" { "G" "H" } 0
t "" 4 "" { 2 10 }
t "" 5 "" { 1 0 }
11 changes: 11 additions & 0 deletions catalog/books/shohambrown2008/fig5_2__original_layout.ef
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
player 1 name 1
player 2 name 2
level 0 node 1 player 1
level 2 node 1 player 2 xshift -3.22 from 0,1 move A
level 2 node 2 player 2 xshift 3.22 from 0,1 move B
level 4 node 1 xshift -1.43 from 2,1 move C payoffs 3 8
level 4 node 2 xshift 1.43 from 2,1 move D payoffs 8 3
level 4 node 3 xshift -2.15 from 2,2 move E payoffs 5 5
level 4 node 4 player 1 xshift 2.15 from 2,2 move F
level 6 node 1 xshift -1.43 from 4,4 move G payoffs 2 10
level 6 node 2 xshift 1.43 from 4,4 move H payoffs 1 0
22 changes: 22 additions & 0 deletions catalog/books/shohambrown2008/fig5_9.efg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
EFG 2 R "Fig 5.9 from Shoham and Leyton-Brown (2008)" { "1" "2" }

"
Figure 5.9 from :cite:p:`ShoLeyB08`.
This is the centipede game. In this game two players alternate in making decisions, at each
turn choosing between going down and ending the game or going across and
continuing it.
This example is used to explain the criticisms of backward induction for finding subgame-perfect equilibrium.
Note that centipede is also a parametrized game, with the parameter being the number of rounds.
"

p "" 1 1 "" { "A" "D" } 0
t "" 1 "" { 1 0 }
p "" 2 2 "" { "A" "D" } 0
t "" 2 "" { 0 2 }
p "" 1 3 "" { "A" "D" } 0
t "" 3 "" { 3 1 }
p "" 2 4 "" { "A" "D" } 0
t "" 4 "" { 2 4 }
p "" 1 5 "" { "A" "D" } 0
t "" 5 "" { 4 3 }
t "" 6 "" { 3 5 }
Loading
Loading