pypokertools icon indicating copy to clipboard operation
pypokertools copied to clipboard

Fix/isomorphism dictionary logic

Open jjailer opened this issue 11 months ago • 0 comments

This pull request fixes a bug in get_translation_dict() where it returns incorrect mappings for certain flop patterns, specifically when handling flops like 'Qs Ts Tc'. The issue occurs when a noncanonical flop follows an ABB pattern (like c,s,s when sorted) but its canonical form follows an ABA ('Tc Td Qc') pattern.

To demonstrate the bug, I've added a test case:

@pytest.mark.parametrize(
    "flop, expected_result",
    [
        # pre-existing tests here
        (('Qs Ts Tc'), {'c': 'd', 'd': 'h', 'h': 's', 's': 'c'}),
    ]
)
def test_get_translation_dict(flop, expected_result):
    assert get_translation_dict(cards(flop)) == expected_result

The original implementation attempted to derive the translation dictionary by analyzing patterns in the input flop (the noncanonical form). This approach led to errors because the input pattern doesn't always match the canonical pattern. This fix reorients the logic to work off the specific structure of canonical flops: they are zero-trailing 3-part weak compositions. This means the suits of a canonical flop can be represented as:

  • exactly 3 nonnegative integers that sum to 3
  • zeroes occur only to the right of any positive values

Additionally, I've modernized the testing framework by migrating to pytest and I've updated requirements.txt to ensure compatibility with current Python versions.

jjailer avatar Jan 27 '25 22:01 jjailer