diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e19196b..74318bf 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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** diff --git a/docs/conf.py b/docs/conf.py index de5cbee..879d2f7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 diff --git a/pokerkit/hands.py b/pokerkit/hands.py index d09e3e5..34077b3 100644 --- a/pokerkit/hands.py +++ b/pokerkit/hands.py @@ -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): diff --git a/setup.py b/setup.py index edcbc6e..6b67ef3 100644 --- a/setup.py +++ b/setup.py @@ -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',