Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_poker_hand evaluates all 5-card combinations, but doesn't return all the winning cards #14

Open
grahambrown1 opened this issue Apr 3, 2022 · 2 comments

Comments

@grahambrown1
Copy link
Contributor

It would be nice if it could return the 5 winning cards after evaluating each 5-card combination from the list of eg 7 cards passed.
Would it work to return the tuple of PokerHand followed by all 5 cards in the significant order to maintain the ability to sort? We'd need to make Card sortable, so High vs low Ace may catch us out here unless we supported a specific Ace Card instance being assigned a value of 1 or 14?
I don't mind putting a bit of work into it if you let me know if and how you'd like it implemented.
Thanks.

@zooba
Copy link
Owner

zooba commented May 12, 2022

In an older version I returned all the cards with the resulting hand and tried to make it sort like that, but it didn't work for a few cases - hence the current approach of just returning the relevant values.

However, what you want is doable with itertools.

import deck, itertools
d = deck.Deck(include_jokers=False)
d.shuffle()
hand, = d.deal_hands(1, 7)
candidates = itertools.combinations(hand, 5)
for cards in sorted(candidates, key=deck.get_poker_hand, reverse=True):
    print(deck.get_poker_hand(cards)[0], deck.Hand(cards))

It's not necessarily obvious, so it'd make a great example for the README (probably cleaned up a bit). My goal with this library was always to demonstrate how "transparently" you can reuse Python's builtins, rather than having to always define your own API for every single operation.

(As you point out, not being able to sort cards kind of goes against this ideal, but then it isn't actually possible to sort cards without specifying the rules. key= is how you do that, though if you look at the Hand class you'll see I've been playing with ways to make the contents of a given hand sortable.)

@zooba
Copy link
Owner

zooba commented May 12, 2022

(Also, my apologies for not seeing your posts sooner. Github "unwatched" my own repo for me for some reason.)

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

No branches or pull requests

2 participants