Skip to content

fix(calpoker): correct kicker selection with 3+ pairs#256

Open
MrDennisV wants to merge 2 commits intoChia-Network:mainfrom
MrDennisV:main
Open

fix(calpoker): correct kicker selection with 3+ pairs#256
MrDennisV wants to merge 2 commits intoChia-Network:mainfrom
MrDennisV:main

Conversation

@MrDennisV
Copy link

When a hand contains 3 or more pairs, the kicker was incorrectly selected from the third pair instead of the highest singleton.

Example with cards: 2♣, 4♠, 5♥, 4♥, 5♣, 9♥, 9♣, K♦ (3 pairs + K + 2)

  • Before: Two Pair (9s & 5s) with 4 as kicker
  • After: Two Pair (9s & 5s) with K as kicker

The bug occurred because truncate 5 blindly took the first 5 cards after sorting by (count DESC, rank DESC), meaning cards with count=2 (pairs) always came before count=1 (singletons).

The fix adds two helper functions:

  • best_singleton_index: finds highest singleton in sorted list
  • select_group_indices: detects incomplete pairs and fixes kicker

Edge case handled: when no singleton exists (e.g., 4 pairs), the original behavior is preserved.

Performance: ~0.2% overhead for normal hands, similar cost for the bug case (3+ pairs).

When a hand contains 3 or more pairs, the kicker was incorrectly
selected from the third pair instead of the highest singleton.

Example with cards: 2♣, 4♠, 5♥, 4♥, 5♣, 9♥, 9♣, K♦ (3 pairs + K + 2)
- Before: Two Pair (9s & 5s) with 4 as kicker
- After: Two Pair (9s & 5s) with K as kicker

The bug occurred because truncate 5 blindly took the first 5 cards
after sorting by (count DESC, rank DESC), meaning cards with count=2
(pairs) always came before count=1 (singletons).

The fix adds two helper functions:
- best_singleton_index: finds highest singleton in sorted list
- select_group_indices: detects incomplete pairs and fixes kicker

Edge case handled: when no singleton exists (e.g., 4 pairs),
the original behavior is preserved.

Performance: ~0.2% overhead for normal hands, similar cost for
the bug case (3+ pairs).
@aqk
Copy link
Contributor

aqk commented Dec 16, 2025

Thank you. I'll read these changes today!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants