Fix heads-up blind assignment and betting order#83
Open
jianrontan wants to merge 1 commit into
Open
Conversation
- Assign the small blind to the button seat in heads-up play; keep the
seat left of the button for 3+ player games
- Detect heads-up via the count of chip-holding players taken before
ante zeroing, so a game shrinking from 3 to 2 players switches correctly
- Apply the fix in both blind code paths: dealer.py and emulator.py
- Seed postflop action from the seat left of the button (small blind for
3+ players, big blind heads-up)
- Seed preflop action from the seat left of the big blind (UTG for 3+
players, small blind/button heads-up)
- Guard the __publish_messages result in play_round before unpacking
- Update heads-up test expectations that encoded the old behavior; add
coverage for a 3-to-2 player transition into a correct heads-up round
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #82
Problem
Heads-up (2-player) games did not follow standard poker rules. The blind
search always assigned the small blind to the seat left of the button, and the
betting order was derived from that assumption. For 2 players this made the
non-button player the small blind and inverted the preflop/postflop action
order.
The blind logic is duplicated in
dealer.pyandemulator.py, so both codepaths were affected.
Changes
pypokerengine/engine/dealer.py,pypokerengine/api/emulator.py_steal_money_from_poor_playernow selects the small blind from the buttonseat in heads-up play, and from the seat left of the button otherwise:
pre_ante_activecounts players that still hold chips before ante zeroing.Using a count taken after ante zeroing would drop a 3-player game to 2 and
falsely trigger heads-up mode; counting beforehand also makes a tournament
that genuinely shrinks from 3 players to 2 switch to heads-up rules correctly.
pypokerengine/engine/round_manager.pyBetting order no longer assumes the 3+ player layout:
the small blind for 3+ players, the big blind heads-up.
UTG for 3+ players, the small blind/button heads-up.
These reduce to the previous behavior for 3+ player games (verified
algebraically and by the existing multi-player tests).
Defensive guard in
dealer.pyplay_roundnow asserts the__publish_messagesresult before unpacking it,documenting the invariant that an ongoing round always ends on an ask message.
Tests
game_test.py,dealer_test.pyandemulator_test.pythat had encoded the old (incorrect) behavior — swappedblind amounts, wrong first actor, and scripted action lists in the old order.
test_exclude_short_of_money_player_when_ante_onandtest_run_until_game_finish_when_one_player_is_leftnow also cover a gamethat shrinks from 3 players to a correct heads-up round.
python -m unittest discover -s tests -p "*_test.py"):232 tests, OK.
Compatibility / notes
the previous heads-up behavior should be retrained.
DataEncoder.__order_historiesstill ordersaction_historiesseat-wisefrom the small blind. This is a pre-existing display-only approximation and
is left as-is; every history entry carries a
uuid, so no information islost.