Calculating Strength of Poker Hand

Started by
20 comments, last by Daddy-O 19 years, 7 months ago
Hey guys, was wondering if there is a standard formula for expressing strength of a poker hand as a number within a certain range? Let's say 1.0 representing the best possible hand, and 0.0 representing the worst possible hand. For instance... 10 J Q K A = 1.0 2 3 4 5 7 = 0.0 The comparer should account for strength of pairs, kicker cards etc. So basically you can boil down any hand to a number. It would also be very helpful if the formula would accurately reflect the relative strength of the hand. Bit of background... I'm working on a small poker game in C# and am implementing IComparer for a 'Hand' Object.
Advertisement
If you ever watch poker games on tv they always talk about who has the better hand based on the probability of drawing the cards they need. I'm sure there is a formula roaming around the Internet that covers it. Of course a lot of it has to do with the kind of poker you are playing.


This website looks like it might help with what you are doing but in order to make it really flexible you would have to do some probability and statistics calculations.
"Pfft, Facts! Facts can be used to prove anything!" -- Homer J. Simpson
I've found lots of information about probabilities vs other hands.

What I'm looking for specificly, is just being able to express any 5 card hand as a number.

Like... (and I just made up these numbers)

a pair of 10's with an ace kicker is worth 0.34
three 5's is worth 0.41
a royal flush is worth 1.0

etc.


How about just using the methods outlined in the website above to compare to other hands. And compare your hands to a static "perfect hand", like a royal flush of hearts. Would that work?
A simple solution: Use the probability of beating a random hand as the score.
No, the correct way of doing this is to calculate the so called "pot odds". It's basically the part of the pot you have to put in to make a call, combined with the odds that you'll make one of your hands. This holds true for any kind of poker, but im mostly talking about Texas Hold'em here.
An example:

On the flop, there's $5 in the pot. The player to your right bets $1, and now the pot's $6. It would cost you $1 to call, which makes it 6:1. You're sitting on an open-ended straight draw, giving you 8 possible "outs", 8 cards that will complete your straight. You've seen 5 cards (2 pockets, plus 3 communitycards), making it 47 unseen. Out of these, 8 are favourable. This makes the odds 39:8, rougly 5:1. This number, 5:1, is your odds for completing your hand, and as that, a rating.
The reason i covered the entire odds-system is because this rating will often be used to decide when to bet, call and raise, and it's as simple as if the odds for you making your hand is higher than the pot odds, it's worth it to call. If not, fold.
It struck me while writing this mini-essay (;) on pot-odds that you may actually want to rate a complete 5-card hand, and not rate it while drawing? In that case, this in fact is heavily dependent on the kind of poker you're playing.
In a game like 5-card draw, it's mostly about having the highest possible hand. In Hold'em, you'd need to take into account the nr of players left, which communitycards are out, their suits, their straight-building possibilities, and so on.
One way for 5-card draw would be to simply assign a base-strength according to where on the ladder you are (1 pair=1, 2 pairs=2, trips=4, straight=8 and so on), and then add a number depending on the highcard, and a smaller number depending on the kicker.

Turns out to be lot of pokertheory inhere that's not necessarily involved into this particular case of rating, but the poster was very diffuse on what kind of rating he wanted, and im sure a lot of people will find this useful for implementing cardgames in general :)
Okay, I found this solution more difficult to explain than to just write out, so I'm just going to write it out

#define HIGH_CARD 0#define PAIR 1#define TWO_PAIR 2#define TRIP 3(etc)float encodeStrength(int handRank, int basis1, int basis2, int basis3, int basis4, int basis5){  float val = 0;  val += handRank / 10;  val += basis1 / 1000;  val += basis2 / 100000;  val += basis3 / 10000000;  val += basis4 / 1000000000;  val += basis5 / 100000000000;  return val;}


Then you also have to write code that a) figures out what the hand actually is, and b) figures out which are the high cards in that hand (like for two pair, which pair is higher?)

So for the hand 2 3 4 5 7
the call would be encodeStrength(HIGH_CARD, 7, 5, 4, 3, 2)
for the hand 4 4 6 6 A
the call would be encodeStrength(TWO_PAIR, 6, 4, ACE, 0, 0)
for the hand 4 5 6 7 8
the call would be encodeStrength(STRAIGHT, 8, 0, 0, 0, 0)

With that solution, you won't actually get the hand 2 3 4 5 7 having a 0.0, its value will be slightly higher than 0. But you ARE guaranteed that a higher value represents a better hand.
How about simply using the ranking tweaked a bit?

Lets take the 10 ranks (as listed all over the place including here:
http://www.pagat.com/vying/pokerrank.html )

Call a royal flush 1.0, A straight flush a 0.9, four of a kind 0.8, etc etc.

Then use the next two digits of percision for comparing within each set. A king high straight would be a 0.913 where as a 7 high straight would be a 0.907

Three of a kind or 1 or 2 pairs would use a similar method but use an extra two digits for the accompaning kicker (or 4 extra digits for two pair sorted high pair, low pair, kicker)
Example: two pair; jacks and fives with a ace kicker would be a 0.3110514

If you play with a ranking of suits you can just append a 0,1,2, or 3 to differentiate.

This won't give a perfectly uniform distrobution, but it's enough for comparing hands.
Ooo - I see my method is SIMILAR to pinacolada's
I was playing poker last week actually, and after a hand I managed to get, I think you should change the following:

10 J Q K A = 1.0

to

A A A A K = 1.0


royal flush does beat a 4 of a kind, but how can you get a royal flush if I have all the aces?

This topic is closed to new replies.

Advertisement