Skip to content

Commit

Permalink
Fix bug in getting best badugi hand combination
Browse files Browse the repository at this point in the history
  • Loading branch information
AussieSeaweed committed Sep 2, 2024
1 parent 298b58a commit 17bcb96
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ Changelog

All notable changes to this project will be documented in this file.

Version 0.5.3 (September 1, 2024)
---------------------------------

**Changed**

- Fix incorrect implementation of ``pokerkit.hands.StandardBadugi.from_game``.

Version 0.5.2 (June 13, 2024)
----------------------------
-----------------------------

**Changed**

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
project = 'PokerKit'
copyright = '2023, University of Toronto Computer Poker Student Research Group'
author = 'University of Toronto Computer Poker Student Research Group'
release = '0.5.2'
release = '0.5.3'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
40 changes: 28 additions & 12 deletions pokerkit/hands.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,24 +661,40 @@ def from_game(
>>> h0 == h1
True
>>> h0 = StandardBadugiHand.from_game('2s3d3c4d')
>>> h1 = StandardBadugiHand.from_game('2s3c3d4d')
>>> h0 == h1
True
:param hole_cards: The hole cards.
:param board_cards: The optional board cards.
:return: The strongest hand from possible card combinations.
"""
ranks = set()
suits = set()
cards = set()
cards = tuple(chain(Card.clean(hole_cards), Card.clean(board_cards)))
max_hand = None

for card in sorted(
chain(Card.clean(hole_cards), Card.clean(board_cards)),
key=lambda card: cls.lookup.rank_order.index(card.rank),
):
if card.rank not in ranks and card.suit not in suits:
ranks.add(card.rank)
suits.add(card.suit)
cards.add(card)
for count in range(4, 0, -1):
for combination in combinations(cards, count):
try:
hand = cls(combination)
except ValueError:
pass
else:
if max_hand is None or hand > max_hand:
max_hand = hand

if max_hand is not None:
break

if max_hand is None:
raise ValueError(
(
f'No valid {type(cls).__qualname__} hand can be formed'
' from the hole and board cards.'
),
)

return cls(cards)
return max_hand


class StandardBadugiHand(BadugiHand):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='pokerkit',
version='0.5.2',
version='0.5.3',
description='An open-source Python library for poker game simulations, hand evaluations, and statistical analysis',
long_description=open('README.rst').read(),
long_description_content_type='text/x-rst',
Expand Down

0 comments on commit 17bcb96

Please sign in to comment.