|
1 | 1 | """A utility module to create/load games for the test suite.""" |
2 | 2 | import pathlib |
3 | 3 |
|
| 4 | +import numpy as np |
| 5 | + |
4 | 6 | import pygambit as gbt |
5 | 7 |
|
6 | 8 |
|
7 | 9 | def read_from_file(fn: str) -> gbt.Game: |
8 | 10 | if fn.endswith(".efg"): |
9 | | - return gbt.read_efg(pathlib.Path("tests/test_games")/fn) |
| 11 | + return gbt.read_efg(pathlib.Path("tests/test_games") / fn) |
10 | 12 | elif fn.endswith(".nfg"): |
11 | | - return gbt.read_nfg(pathlib.Path("tests/test_games")/fn) |
| 13 | + return gbt.read_nfg(pathlib.Path("tests/test_games") / fn) |
12 | 14 | else: |
13 | 15 | raise ValueError(f"Unknown file extension in {fn}") |
14 | 16 |
|
15 | 17 |
|
16 | 18 | ################################################################################################ |
17 | 19 | # Normal-form (aka strategic-form) games (nfg) |
18 | 20 |
|
| 21 | + |
19 | 22 | def create_2x2_zero_nfg() -> gbt.Game: |
20 | 23 | """ |
21 | 24 | Returns |
@@ -73,6 +76,7 @@ def create_coord_4x4_nfg(outcome_version: bool = False) -> gbt.Game: |
73 | 76 | ################################################################################################ |
74 | 77 | # Extensive-form games (efg) |
75 | 78 |
|
| 79 | + |
76 | 80 | def create_mixed_behav_game_efg() -> gbt.Game: |
77 | 81 | """ |
78 | 82 | Returns |
@@ -124,3 +128,76 @@ def create_selten_horse_game_efg() -> gbt.Game: |
124 | 128 | 5-player Selten's Horse Game |
125 | 129 | """ |
126 | 130 | return read_from_file("e01.efg") |
| 131 | + |
| 132 | + |
| 133 | +def create_reduction_generic_payoffs_efg() -> gbt.Game: |
| 134 | + # tree with only root |
| 135 | + g = gbt.Game.new_tree(players=["1", "2"], title="TEST") |
| 136 | + |
| 137 | + # add four children |
| 138 | + g.append_move(g.root, "2", ["a", "b", "c", "d"]) |
| 139 | + |
| 140 | + # add L and R after a |
| 141 | + g.append_move(g.root.children[0], "1", ["L", "R"]) |
| 142 | + |
| 143 | + # add C and D to single infoset after b and c |
| 144 | + nodes = [g.root.children[1], g.root.children[2]] |
| 145 | + g.append_move(nodes, "1", ["C", "D"]) |
| 146 | + |
| 147 | + # add s and t from single infoset after rightmost C and D |
| 148 | + g.append_move(g.root.children[2].children, "2", ["s", "t"]) |
| 149 | + |
| 150 | + # add p and q |
| 151 | + g.append_move(g.root.children[0].children[1], "2", ["p", "q"]) |
| 152 | + |
| 153 | + # add U and V in a single infoset after p and q |
| 154 | + g.append_move(g.root.children[0].children[1].children, "1", ["U", "V"]) |
| 155 | + |
| 156 | + # Set outcomes |
| 157 | + |
| 158 | + g.set_outcome(g.root.children[0].children[0], g.add_outcome([1, -1], label="aL")) |
| 159 | + g.set_outcome( |
| 160 | + g.root.children[0].children[1].children[0].children[0], |
| 161 | + g.add_outcome([2, -2], label="aRpU"), |
| 162 | + ) |
| 163 | + g.set_outcome( |
| 164 | + g.root.children[0].children[1].children[0].children[1], |
| 165 | + g.add_outcome([3, -3], label="aRpV"), |
| 166 | + ) |
| 167 | + g.set_outcome( |
| 168 | + g.root.children[0].children[1].children[1].children[0], |
| 169 | + g.add_outcome([4, -4], label="aRqU"), |
| 170 | + ) |
| 171 | + g.set_outcome( |
| 172 | + g.root.children[0].children[1].children[1].children[1], |
| 173 | + g.add_outcome([5, -5], label="aRqV"), |
| 174 | + ) |
| 175 | + |
| 176 | + g.set_outcome(g.root.children[1].children[0], g.add_outcome([6, -6], label="bC")) |
| 177 | + g.set_outcome(g.root.children[1].children[1], g.add_outcome([7, -7], label="bD")) |
| 178 | + |
| 179 | + g.set_outcome( |
| 180 | + g.root.children[2].children[0].children[0], g.add_outcome([8, -8], label="cCs") |
| 181 | + ) |
| 182 | + g.set_outcome( |
| 183 | + g.root.children[2].children[0].children[1], g.add_outcome([9, -9], label="cCt") |
| 184 | + ) |
| 185 | + g.set_outcome( |
| 186 | + g.root.children[2].children[1].children[0], |
| 187 | + g.add_outcome([10, -10], label="cDs"), |
| 188 | + ) |
| 189 | + g.set_outcome( |
| 190 | + g.root.children[2].children[1].children[1], |
| 191 | + g.add_outcome([11, -11], label="cDt"), |
| 192 | + ) |
| 193 | + |
| 194 | + g.set_outcome(g.root.children[3], g.add_outcome([12, -12], label="d")) |
| 195 | + |
| 196 | + return g |
| 197 | + |
| 198 | + |
| 199 | +def make_rational(input: str): |
| 200 | + return gbt.Rational(input) |
| 201 | + |
| 202 | + |
| 203 | +vectorized_make_rational = np.vectorize(make_rational) |
0 commit comments