Skip to content

Commit 27537f2

Browse files
committed
betting loop refactored for clarity
1 parent 12ad7f4 commit 27537f2

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

71_Poker/python/game.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,35 +130,42 @@ def _player_discard_draw(self) -> None:
130130
# ------------------------------------------------------------------
131131

132132
def _conduct_betting_round(self, post_draw: bool) -> bool:
133-
"""Core loop for a betting round. Returns True to continue the round."""
133+
"""
134+
Executes a betting round.
135+
Returns True if the betting phase completed (hand continues).
136+
Returns False if a player folded (hand ends).
137+
"""
134138
while True:
135139
human_action = self._get_human_action()
136140

137141
match human_action:
138142
case Player.Action.FOLD:
143+
# Human fold always ends betting loop (hand ends)
139144
self._settle_bets()
140145
self._award_pot(dealer_wins=True)
141146
return False
142147

143-
case Player.Action.CHECK:
144-
if post_draw:
145-
if self._handle_post_draw_check():
146-
return True
147-
continue
148-
return True
149-
150148
case Player.Action.CALL:
149+
# Human call always ends betting loop (proceed to next phase)
151150
self._settle_bets()
152151
return True
153152

153+
case Player.Action.CHECK:
154+
# Pre-draw: human check ends human's turn.
155+
# Post-draw: dealer gets a chance to bet/check back.
156+
if not post_draw or self._handle_human_post_draw_check():
157+
return True
158+
# If dealer bet, we fall through and loop for human response
159+
154160
case Player.Action.RAISE:
155161
if self._handle_human_raise():
156162
return True
163+
# If dealer re-raised, we fall through and loop for human response
157164

158165
case _:
159-
raise ValueError("Unknown player action.")
166+
raise ValueError(f"Unknown player action: {human_action}")
160167

161-
def _handle_post_draw_check(self) -> bool:
168+
def _handle_human_post_draw_check(self) -> bool:
162169
"""Process dealer response to human check. Returns True if phase ends."""
163170
dealer_action = self.dealer.get_check_response()
164171
if self.dealer.money < self.dealer.bet:
@@ -196,7 +203,7 @@ def _handle_human_raise(self) -> bool:
196203
return False
197204

198205
case _:
199-
raise ValueError("Unknown dealer action.")
206+
raise ValueError(f"Unknown dealer action: {dealer_action}")
200207

201208
def _get_human_action(self) -> Player.Action:
202209
"""Prompt user for a bet and return the resulting Action."""

0 commit comments

Comments
 (0)