Skip to content

Commit f2a8039

Browse files
committed
removed create_chance_in_middle_efg from games.py
1 parent 2cfa8a1 commit f2a8039

File tree

3 files changed

+27
-58
lines changed

3 files changed

+27
-58
lines changed

tests/games.py

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def create_efg_corresponding_to_bimatrix_game(
4444

4545
def create_2x2_zero_sum_efg(missing_term_outcome: bool = False) -> gbt.Game:
4646
"""
47+
TODO: use create_efg_corresponding_to_bimatrix_game
48+
4749
EFG corresponding to 2x2 zero-sum game (I,-I).
4850
If missing_term_outcome, the terminal node after "T" then "r" does not have an outcome.
4951
"""
@@ -85,6 +87,7 @@ def create_perfect_info_with_chance_efg() -> gbt.Game:
8587
g.root.children[0].children[1].children[1], g.add_outcome([-2, 2], label="aRD")
8688
)
8789
g.set_outcome(g.root.children[1], g.add_outcome([-1, 1], label="b"))
90+
g.to_efg("perfect_info_with_chance.efg")
8891
return g
8992

9093

@@ -129,6 +132,8 @@ def create_three_action_internal_outcomes_efg(nonterm_outcomes: bool = False) ->
129132
g.set_outcome(g.root.children[1].children[1].children[1], o_m1)
130133
g.set_outcome(g.root.children[1].children[2].children[0], o_m1)
131134
g.set_outcome(g.root.children[1].children[2].children[1], o_1)
135+
tmp = "_nonterm_outcomes_and_missing_term_outcomes" if nonterm_outcomes else ""
136+
g.to_efg(f"2_player_chance_3_actions{tmp}.efg")
132137
return g
133138

134139

@@ -151,6 +156,8 @@ def create_entry_accomodation_efg(nonterm_outcomes: bool = False) -> gbt.Game:
151156
g.set_outcome(g.root.children[1].children[0].children[0], g.add_outcome([2, 3]))
152157
g.set_outcome(g.root.children[1].children[0].children[1], g.add_outcome([1, 0]))
153158
g.set_outcome(g.root.children[1].children[1], g.add_outcome([3, 1]))
159+
tmp = "_with_nonterm_outcomes" if nonterm_outcomes else ""
160+
g.to_efg(f"entry_accomodation{tmp}.efg")
154161
return g
155162

156163

@@ -173,56 +180,8 @@ def create_non_zero_sum_lacking_outcome_efg(missing_term_outcome: bool = False)
173180
g.set_outcome(g.root.children[1].children[0].children[1], g.add_outcome([0, 1]))
174181
g.set_outcome(g.root.children[1].children[1].children[0], g.add_outcome([-1, 1]))
175182
g.set_outcome(g.root.children[1].children[1].children[1], g.add_outcome([2, -1]))
176-
return g
177-
178-
179-
def create_chance_in_middle_efg(nonterm_outcomes: bool = False) -> gbt.Game:
180-
g = gbt.Game.new_tree(players=["1", "2"],
181-
title="Chance in middle game")
182-
g.append_move(g.root, "1", ["A", "B"])
183-
g.append_move(g.root.children[0], g.players.chance, ["H", "L"])
184-
g.set_chance_probs(g.root.children[0].infoset, ["1/5", "4/5"])
185-
g.append_move(g.root.children[1], g.players.chance, ["H", "L"])
186-
g.set_chance_probs(g.root.children[1].infoset, ["7/10", "3/10"])
187-
for i in range(2):
188-
g.append_move(g.root.children[0].children[i], "2", ["X", "Y"])
189-
ist = g.root.children[0].children[i].infoset
190-
g.append_infoset(g.root.children[1].children[i], ist)
191-
for i in range(2):
192-
for j in range(2):
193-
g.append_move(g.root.children[i].children[0].children[j], "1", ["C", "D"])
194-
ist = g.root.children[i].children[0].children[j].infoset
195-
g.append_infoset(g.root.children[i].children[1].children[j], ist)
196-
o_1 = g.add_outcome([1, -1], label="1")
197-
o_m1 = g.add_outcome([-1, 1], label="-1")
198-
o_m2 = g.add_outcome([-2, 2], label="-2")
199-
o_h = g.add_outcome(["1/2", "-1/2"], label="0.5")
200-
o_mh = g.add_outcome(["-1/2", "1/2"], label="-0.5")
201-
o_z = g.add_outcome([0, 0], label="0")
202-
o_m3o2 = g.add_outcome(["-3/2", "3/2"], label="-1.5")
203-
if nonterm_outcomes:
204-
g.set_outcome(g.root.children[0].children[0], g.add_outcome([-1, 1], label="a"))
205-
g.set_outcome(g.root.children[0].children[0].children[0].children[0], o_1)
206-
g.set_outcome(g.root.children[0].children[0].children[0].children[1], o_m1)
207-
g.set_outcome(g.root.children[0].children[0].children[1].children[0], o_h)
208-
g.set_outcome(g.root.children[0].children[0].children[1].children[1], o_mh)
209-
else:
210-
g.set_outcome(g.root.children[0].children[0].children[0].children[0], o_z)
211-
g.set_outcome(g.root.children[0].children[0].children[0].children[1], o_m2)
212-
g.set_outcome(g.root.children[0].children[0].children[1].children[0], o_mh)
213-
g.set_outcome(g.root.children[0].children[0].children[1].children[1], o_m3o2)
214-
g.set_outcome(g.root.children[0].children[1].children[0].children[0], o_h)
215-
g.set_outcome(g.root.children[0].children[1].children[0].children[1], o_mh)
216-
g.set_outcome(g.root.children[0].children[1].children[1].children[0], o_1)
217-
g.set_outcome(g.root.children[0].children[1].children[1].children[1], o_m1)
218-
g.set_outcome(g.root.children[1].children[0].children[0].children[0], o_h)
219-
g.set_outcome(g.root.children[1].children[0].children[0].children[1], o_mh)
220-
g.set_outcome(g.root.children[1].children[0].children[1].children[0], o_1)
221-
g.set_outcome(g.root.children[1].children[0].children[1].children[1], o_m1)
222-
g.set_outcome(g.root.children[1].children[1].children[0].children[0], o_1)
223-
g.set_outcome(g.root.children[1].children[1].children[0].children[1], o_m1)
224-
g.set_outcome(g.root.children[1].children[1].children[1].children[0], o_h)
225-
g.set_outcome(g.root.children[1].children[1].children[1].children[1], o_mh)
183+
tmp = "_missing_term_outcome" if missing_term_outcome else ""
184+
g.to_efg(f"non_zero_sum_2_player{tmp}.efg")
226185
return g
227186

228187

@@ -246,6 +205,7 @@ def create_large_payoff_game_efg() -> gbt.Game:
246205
g.set_outcome(g.root.children[1].children[0].children[1], o_1)
247206
g.set_outcome(g.root.children[1].children[1].children[0], o_zero)
248207
g.set_outcome(g.root.children[1].children[1].children[1], o_large)
208+
g.to_efg("large_payoff_game.efg")
249209
return g
250210

251211

@@ -294,11 +254,15 @@ def create_3_player_with_internal_outcomes_efg(nonterm_outcomes: bool = False) -
294254
o = g.add_outcome([0, 0, 0])
295255
g.set_outcome(g.root.children[0].children[0].children[1].children[0], o)
296256
g.set_outcome(g.root.children[0].children[0].children[1].children[1], o)
257+
tmp = "_with_nonterm_outcomes" if nonterm_outcomes else ""
258+
g.to_efg(f"3_player{tmp}.efg")
297259
return g
298260

299261

300262
def create_matching_pennies_efg(with_neutral_outcome: bool = False) -> gbt.Game:
301263
"""
264+
TODO: use create_efg_corresponding_to_bimatrix_game
265+
302266
The version with_neutral_outcome adds a (0,0) payoff outcomes at a non-terminal node.
303267
"""
304268
g = gbt.Game.new_tree(
@@ -751,6 +715,7 @@ def create_reduction_generic_payoffs_efg() -> gbt.Game:
751715
)
752716

753717
g.set_outcome(g.root.children[3], g.add_outcome([12, -12], label="d"))
718+
g.to_efg("reduction_generic_payoffs.efg")
754719
return g
755720

756721

@@ -763,6 +728,7 @@ def create_reduction_one_player_generic_payoffs_efg() -> gbt.Game:
763728
g.set_outcome(g.root.children[1], g.add_outcome([3]))
764729
g.set_outcome(g.root.children[2], g.add_outcome([4]))
765730
g.set_outcome(g.root.children[3], g.add_outcome([5]))
731+
g.to_efg("reduction_one_player_generic_payoffs.efg")
766732
return g
767733

768734

@@ -785,6 +751,7 @@ def create_reduction_both_players_payoff_ties_efg() -> gbt.Game:
785751
g.set_outcome(g.root.children[2].children[1].children[0], g.add_outcome([7, 8]))
786752
g.set_outcome(g.root.children[2].children[1].children[1], g.add_outcome([2, 2]))
787753
g.set_outcome(g.root.children[3], g.add_outcome([6, 4]))
754+
g.to_efg("reduction_both_players_payoff_ties_GTE_survey.efg")
788755
return g
789756

790757

@@ -815,6 +782,8 @@ def create_two_player_perfect_info_win_lose_efg(nonterm_outcomes: bool = False)
815782
g.set_outcome(g.root.children[0].children[1], g.add_outcome([101, -51], label="aR"))
816783
g.set_outcome(g.root.children[1].children[0], g.add_outcome([1, -1], label="bL"))
817784
g.set_outcome(g.root.children[1].children[1], g.add_outcome([-1, 1], label="bR"))
785+
tmp = "_with_nonterm_outcomes" if nonterm_outcomes else ""
786+
g.to_efg(f"two_player_perfect_info_win_lose{tmp}.efg")
818787
return g
819788

820789

tests/test_extensive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ def test_reduced_strategic_form(
409409
games.create_3_player_with_internal_outcomes_efg(nonterm_outcomes=True)
410410
),
411411
(
412-
games.create_chance_in_middle_efg(),
413-
games.create_chance_in_middle_efg(nonterm_outcomes=True)
412+
games.read_from_file("chance_in_middle.efg"),
413+
games.read_from_file("chance_in_middle_with_nonterm_outcomes.efg")
414414
),
415415
(
416416
games.create_non_zero_sum_lacking_outcome_efg(),

tests/test_nash.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,14 @@ def test_enummixed_rational(game: gbt.Game, mixed_strategy_prof_data: list):
279279
##############################################################################
280280
##############################################################################
281281
(
282-
games.create_chance_in_middle_efg(),
282+
games.read_from_file("chance_in_middle.efg"),
283283
[[[["3/11", "8/11"], [1, 0], [1, 0], [1, 0], [1, 0]], [[1, 0], ["6/11", "5/11"]]],
284284
], # [[[1, 0], [1, 0], [1, 0], [0, 0], [0, 0]], [[0, 1], [1, 0]]],
285285
# [[[0, 1], [0, 0], [0, 0], [1, 0], [1, 0]], [[1, 0], [0, 1]]],
286286
1, # subsequent eqs have undefined infosets; include after #issue 660
287287
),
288288
(
289-
games.create_chance_in_middle_efg(nonterm_outcomes=True),
289+
games.read_from_file("chance_in_middle_with_nonterm_outcomes.efg"),
290290
[[[["3/11", "8/11"], [1, 0], [1, 0], [1, 0], [1, 0]], [[1, 0], ["6/11", "5/11"]]],
291291
], # [[[1, 0], [1, 0], [1, 0], [0, 0], [0, 0]], [[0, 1], [1, 0]]],
292292
# [[[0, 1], [0, 0], [0, 0], [1, 0], [1, 0]], [[1, 0], [0, 1]]],
@@ -587,14 +587,14 @@ def test_lcp_behavior_double():
587587
],
588588
),
589589
(
590-
games.create_chance_in_middle_efg(),
590+
games.read_from_file("chance_in_middle.efg"),
591591
[
592592
[["3/11", "8/11"], [1, 0], [1, 0], [1, 0], [1, 0]],
593593
[[1, 0], ["6/11", "5/11"]]
594594
]
595595
),
596596
(
597-
games.create_chance_in_middle_efg(nonterm_outcomes=True),
597+
games.read_from_file("chance_in_middle_with_nonterm_outcomes.efg"),
598598
[
599599
[["3/11", "8/11"], [1, 0], [1, 0], [1, 0], [1, 0]],
600600
[[1, 0], ["6/11", "5/11"]]
@@ -791,14 +791,14 @@ def test_lp_behavior_double():
791791
],
792792
),
793793
(
794-
games.create_chance_in_middle_efg(),
794+
games.read_from_file("chance_in_middle.efg"),
795795
[
796796
[["3/11", "8/11"], [1, 0], [1, 0], [1, 0], [1, 0]],
797797
[[1, 0], ["6/11", "5/11"]]
798798
],
799799
),
800800
(
801-
games.create_chance_in_middle_efg(nonterm_outcomes=True),
801+
games.read_from_file("chance_in_middle_with_nonterm_outcomes.efg"),
802802
[
803803
[["3/11", "8/11"], [1, 0], [1, 0], [1, 0], [1, 0]],
804804
[[1, 0], ["6/11", "5/11"]]

0 commit comments

Comments
 (0)