Skip to content

Support exact suited combos (e.g. KhQh:1.0) in range strings - #227

Merged
bupticybee merged 2 commits into
bupticybee:consolefrom
RoieSalama:support-exact-suited-combos
Jul 13, 2026
Merged

bupticybee merged 2 commits into
bupticybee:consolefrom
RoieSalama:support-exact-suited-combos

Conversation

@RoieSalama

Copy link
Copy Markdown

PrivateRangeConverter::rangeStr2Cards currently accepts rank-class tokens (AA, AKs, AKo) with an optional weight, but rejects any 4-character token with range str X len not valid — there's no way to specify a single exact suited combo, only a whole rank class expanded across all 4 suits.

This comes up whenever a range needs to distinguish combos by suit — most commonly when constructing a range for a turn/river solve where only some suits of a given rank-class actually have relevant equity (e.g. only the two suits that make a flush should continue, not all four).

This was previously raised in #111, where the maintainer said they'd merge a fix if submitted as a proper PR with passing tests — the attached patch in that issue was never followed up as an actual PR, so it never landed. This PR is a clean implementation of the same idea:

  • Adds a range_len == 4 branch to rangeStr2Cards, following the exact pattern of the existing 2/3-character branches: parse the two 2-char card codes, validate they're not the same card, apply the existing dead-card interception check, push a single PrivateCards with the given weight.
  • Existing rank-class tokens (AKs, AA, etc.) are completely unaffected — this only adds a new branch, doesn't touch the existing ones.
  • Adds 3 unit tests in test/test.cpp:
    • test_converter_exact_combo — mixing an exact combo with a weight, another exact combo with a different weight, and a normal rank-class token in the same range string; verifies only the requested suits appear (e.g. KhQh/KcQc present, KdQd/KsQs absent).
    • test_converter_exact_combo_invalid — same card twice (AhAh) throws, matching existing behavior for AAs.
    • test_converter_exact_combo_dead_card — a combo colliding with a board card is silently dropped, matching existing boardsHasIntercept behavior in the other branches.

All 3 new tests pass; the existing (sole enabled) test test_poker_solver_bench is unaffected. Ran cmake .. && make install && make test clean end to end.

Happy to also add a line to the README's range example if useful.

Closes #111.

🤖 Generated with Claude Code

PrivateRangeConverter::rangeStr2Cards currently accepts rank-class tokens
(AA, AKs, AKo) with an optional weight, but rejects any 4-character token
with "range str X len not valid" - there's no way to specify a single
exact suited combo, only a whole rank class expanded across all 4 suits.

This comes up whenever a range needs to distinguish combos by suit - most
commonly when constructing a range for a turn/river solve where only some
suits of a given rank-class actually have relevant equity (e.g. only the
two suits that make a flush should continue, not all four).

This was previously raised in bupticybee#111, where the maintainer said they'd merge
a fix if submitted as a proper PR with passing tests. The attached patch
in that issue was never followed up as an actual PR, so it never landed.
This is a clean implementation of the same idea:

- Adds a range_len == 4 branch to rangeStr2Cards, following the exact
  pattern of the existing 2/3-character branches: parse the two 2-char
  card codes, validate they're not the same card, apply the existing
  dead-card interception check, push a single PrivateCards with the
  given weight.
- Existing rank-class tokens (AKs, AA, etc.) are completely unaffected.
- Adds 3 unit tests in test/test.cpp covering the happy path (mixed
  weights alongside a normal rank-class token), invalid input (same card
  twice), and dead-card collision handling.
@bupticybee

Copy link
Copy Markdown
Owner

I think this will break isomorphism calculation. Mind do a few more tests? One thing can do is to disable isomorphism when using KhQh:1.0 kind of string.

An exact suited combo (e.g. "KhQh:1.0") only ever produces the one
suit-pair requested, never its siblings in the other 3 suits. Suit
isomorphism assumes every rank-class is symmetric across all 4 suits, so
this breaks it: exchange_color()'s missing-entry lookup silently defaults
to index 0 when a combo has no sibling in the swapped suit, corrupting an
unrelated hand's value.

Verified both in isolation (exchange_color corrupts values for an
asymmetric range but not a symmetric one) and end-to-end against a real
solve with a real pending chance node: leaving isomorphism on for an
asymmetric-combo range produces up to 0.99 absolute strategy divergence
vs. isomorphism off, versus ~0.0006 for a symmetric control range.

PokerSolver::train() now detects exact combos via a new optional
has_exact_combo out-param on PrivateRangeConverter::rangeStr2Cards, and
silently disables isomorphism (with a warning) rather than producing
corrupted results. Added PokerSolver::usedIsomorphism() so callers can
detect the override.

Addresses maintainer feedback on bupticybee#227:
bupticybee#227 (comment)
@RoieSalama

Copy link
Copy Markdown
Author

Confirmed — you were right, this does break isomorphism. Pushed a fix.

Root cause: exchange_color() (include/tools/utils.h) builds a lookup table mapping each combo's color-swapped identity back to its index in the range. When the swapped combo (e.g. KcQc for a KhQh:1.0 combo with no clubs sibling) doesn't exist in the range, the lookup silently defaults to index 0 (zero-initialized array) instead of "no match" — so it swaps the exact combo's value with whatever unrelated hand happens to sit at index 0.

Verified two ways against the unpatched code:

  1. Isolated: called exchange_color directly on a range with KhQh:1.0 and no KcQc — confirmed it corrupts both the combo's value and an unrelated hand's value. A control range with both KhQh:1.0 and KcQc:1.0 present swaps correctly.
  2. End-to-end: ran the real PCfrSolver::train() on resources/gametree/part_tree_turn_depthinf.km (a real pending river deal) with an asymmetric-combo range, comparing use_isomorphism=true vs false. Max strategy divergence was 0.99 (essentially flipped) for the asymmetric range, vs. 0.0006 (normal float noise) for a symmetric control range.

Fix: went with your suggested approach — disable isomorphism when an exact combo is present, rather than trying to make isomorphism itself suit-aware (bigger, riskier change). PrivateRangeConverter::rangeStr2Cards gets an optional bool* has_exact_combo out-param; PokerSolver::train() (the entry point used by CommandLineTool and the Python bindings) checks it for both ranges and force-disables use_isomorphism with a warning if either range has an exact combo. Added PokerSolver::usedIsomorphism() so callers can detect the silent override.

Added tests: detection-flag correctness, a direct exchange_color corruption test (with a passing symmetric control case), and two end-to-end PokerSolver tests confirming the override fires only when needed.

🤖 Generated with Claude Code

@bupticybee

Copy link
Copy Markdown
Owner

Yeah I think it's good to merge now.

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