-1

Given a hand, I am trying to determine the value of that hand, and implement this in a programming language for fun. Would the following work? I am not a poker player, so I don't know for sure.

Input is 7 cards --> check if there is a straight --> if there is a straight, then check if there is also a flush, in which case the hand's value must be straight flush --> if there is a straight, but not a flush, then the hand's value most be a straight --> if there wasn't a straight at all, then check if it is quads. If true, then the hand's value is quads --> if not true, check if its a full house --> if not true, check if its a flush --> if not true, check set --> if not true, check two pair --> if not true, check pair --> if not true, it's just a kicker.

  • No. It won't. Learn poker first, then you can think about some simulations about it. – asAguest Jan 11 '17 at 21:09
  • Over in the programming stacks there are good questions and answers about shuffling cards, and other things concerning poker programming.. – Jon Jan 13 '17 at 6:10
1

Even if it did "work" (as Paparazzi points out, it wouldn't, because you can hold both a straight and a flush in 7 cards without also holding a straight flush), it's not going to be the most efficient way by a long stretch.

There's a bunch online about this and some contributors here like Paparazzi have created their own evaluation code.

Check out this page for one example of a histogram based evaluation method for example.

1

The general method you describe (that is, check-for-hand-x, then check-for-hand-y, ...) is what poker programmers would call a "naive" or "basic" evaluator. Not that there's anything wrong with it, it's just simple, straightforward, and probably slow.

To write one of these, I suggest the following:

  1. Start with 5 cards. Once you have that written, you can evaluate 7-card hands by evaluating the 20 5-card combinations of each set of 7, then picking the best of those 20.

  2. Start your evaluator by sorting the hand by rank, A...2. It's helpful for this if you choose to represent cards in a way that makes this the natural order--that depends on the language.

  3. Then, check for hands in reverse strength order: i.e., check for straight flushes, then quads, the full houses, etc., down to one pair.


After you've done this, you might want to look at more sophisticated (and faster) approaches. For example, "Cactus Kev"'s prime-based algorithm, Pokersource's bitmap-based code, or my own OneJoker library, which uses a optimized directed acyclic graph to get what I believe is the fastest 5-card evaluator anywhere (The "2+2" evaluator uses the same approach and is faster for 7 cards, but takes a lot more memory).

This is a much more difficult programming exercise than one might think, but a very challenging puzzle.

0

For one it can be a straight and a flush and not be a straight flush.

This is a 5 card evaluator here. 7 is like twice as complex. This is bit much for a hobby project.

As you describe would be very slow.

Do all the rank match counts once. Then flush, then straight, and then if straight and flush check for a straight flush.

Even with 7 you cannot have quads or boat and have either a straight of flush. Since they are cheap to run you do that first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.