Skip to content

Commit 836cd49

Browse files
committed
used new + operator in construction of Kuhn poker in tests
1 parent 4c2604b commit 836cd49

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

tests/games.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,30 @@ def create_kuhn_poker_efg() -> gbt.Game:
146146
g = gbt.Game.new_tree(
147147
players=["Alice", "Bob"], title="Three-card poker (J, Q, K), two-player"
148148
)
149+
cards = ["J", "Q", "K"]
149150
deals = ["JQ", "JK", "QJ", "QK", "KJ", "KQ"]
151+
152+
def deals_by_infoset(player, card):
153+
player_idx = 0 if player == "Alice" else 1
154+
return [d for d in deals if d[player_idx] == card]
155+
150156
g.append_move(g.root, g.players.chance, deals)
151157
g.set_chance_probs(g.root.infoset, [gbt.Rational(1, 6)]*6)
152-
# group the children of the root (indices of `deals`) by each player's dealt card
153-
alice_grouping = [[0, 1], [2, 3], [4, 5]] # J, Q, K
154-
bob_grouping = [[0, 5], [1, 3], [2, 4]] # Q, K, J
155-
156-
# Alice's first move
157-
for ij in alice_grouping:
158-
term_nodes = [g.root.children[k] for k in ij]
158+
for alice_card in cards:
159+
# Alice's first move
160+
term_nodes = [g.root + d for d in deals_by_infoset("Alice", alice_card)]
159161
g.append_move(term_nodes, "Alice", ["Check", "Bet"])
160-
# Bob's move after Alice checks
161-
for ij in bob_grouping:
162-
term_nodes = [g.root.children[k].children[0] for k in ij]
162+
for bob_card in cards:
163+
# Bob's move after Alice checks
164+
term_nodes = [g.root + d + "Check" for d in deals_by_infoset("Bob", bob_card)]
163165
g.append_move(term_nodes, "Bob", ["Check", "Bet"])
164-
# Alice's move if Bob's second action is bet
165-
for ij in alice_grouping:
166-
term_nodes = [g.root.children[k].children[0].children[1] for k in ij]
166+
for alice_card in cards:
167+
# Alice's move if Bob's second action is bet
168+
term_nodes = [g.root + d + "Check" + "Bet" for d in deals_by_infoset("Alice", alice_card)]
167169
g.append_move(term_nodes, "Alice", ["Fold", "Call"])
168-
# Bob's move after Alice bets initially
169-
for ij in bob_grouping:
170-
term_nodes = [g.root.children[k].children[1] for k in ij]
170+
for bob_card in cards:
171+
# Bob's move after Alice bets initially
172+
term_nodes = [g.root + d + "Bet" for d in deals_by_infoset("Bob", bob_card)]
171173
g.append_move(term_nodes, "Bob", ["Fold", "Call"])
172174

173175
def calculate_payoffs(term_node):

0 commit comments

Comments
 (0)