# Calculating Strength of Poker Hand

## Recommended Posts

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.

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites
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?

#### Share this post

##### Share on other sites
A simple solution: Use the probability of beating a random hand as the score.

#### Share this post

##### Share on other sites
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 :)

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites
Ooo - I see my method is SIMILAR to pinacolada's

#### Share this post

##### Share on other sites
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?

#### Share this post

##### Share on other sites
any straight flush beats 4 of a kind

#### Share this post

##### Share on other sites
Damn! This is tough! Determining what the hand is from an array of cards is a lot more difficult than I thought it would be. It's gonna be even harder when the best 5 have to be picked from 7.

Anyways, thanx for all the useful suggestions guys!

#### Share this post

##### Share on other sites
Just picking the best one isn't hard. Just make functions that checks for the different kinds of hands. First check for a royal, then for a straight flush, four of a kind, and so on, downwards. Once you've found the kind of hand, you break.
After that, it's simply a matter of storing the highcard, and for two pairs, the lower pair aswell.
I thought you needed this for some sort of poker AI, which is why i gave the whole rundown upthere.

#### Share this post

##### Share on other sites
Hi,

what your are doing is artificial intelligence.

What i can advise you to do create an evaluation function with some parameters.

like F(a,b,c,d) = a * Number of pairs + b * number of Aces ....

and do a RRHC algorithm to find the optimum (a,b,c,d) value that match the best evaluation function.
RRHC = Random-Restart Hill-Climbing.

I used this method for a project to develop à tetris AI.

I search the space of solution for a maximum.
You need to play for example 10 games to do the average of the score. But for this you need first an opponent with another alogorithm. It can be a simple one.

IN my project i did a distributed version of teh learning algoritm because i had to play 100 games of 10 000-15 000 lines to have a value, which took a lot of time.
It took me 2 weeks with somes computers to find a good value.

I found the following links :
see for the evaluation function for tetris.

and for the learning algorithm.

the harder thing is to design the evaluation function because it will take you a lot of time to find maximum extrema. Yes carefull, with such function the space of soltion is very big and there are a lot of local maxima.

hope that helps (and hope that's clear)

neyna

#### Share this post

##### Share on other sites
Quote:
 Original post by Neynawhat your are doing is artificial intelligence.

He's not, really, even though that's what I thought at first.
I think he's just trying to decide the winning hand at a hold'em showdown.

#### Share this post

##### Share on other sites
Errr

So you want a sytem that maps each poker hand into a real number, so that you can, in the end, compare who was better?

Well... we all know that the hand types do have a certain kind of order in their strength... pair / two pairs / three of a kind / straight / flush / four of a kind / five of a kind / royal flush

(I might have made an error somewhere, but the idea remains)

Anyway, a good idea for your algorithm is to start from the best one, and go for the worst one. Something like this:

int ValueOfHand( Hand& hand ) {
if( IsRoyalFlush(hand) ) return 5;
if( IsFiveOfAKind(hand) ) return 4;
if( IsFourOfAKind(hand) ) return 3;
if( Flush(hand) ) return 2;
...
}

and so on... it should be obvious why this works.

Then there are, of course, some exceptions... for example, if two players have the same kind of hand (for example, a pair), the one with higher pair wins. Luckily, these are just special cases for each hand type.

- Mikko

#### Share this post

##### Share on other sites
Quote:
 Original post by uuteeWell... we all know that the hand types do have a certain kind of order in their strength... pair / two pairs / three of a kind / straight / flush / four of a kind / five of a kind / royal flush

Five of a kind? If we ever play poker, remind me to check your shirtsleeves ;)

#### Share this post

##### Share on other sites
Quote:
Original post by tok_junior
Quote:
 Original post by uuteeWell... we all know that the hand types do have a certain kind of order in their strength... pair / two pairs / three of a kind / straight / flush / four of a kind / five of a kind / royal flush

Five of a kind? If we ever play poker, remind me to check your shirtsleeves ;)

He means playing with wildcards I think ;)

#### Share this post

##### Share on other sites
Probably, but you're not playing with wildcards if you're playing with standard international poker-rules :)

#### Share this post

##### Share on other sites
Quote:
 Original post by uutee these are just special cases for each hand type. - Mikko

And if you want to cover more variants, check tips etc...
you can check this place out

#### Share this post

##### Share on other sites
The goal of the project is to create a poker playing AI. But before I do that, I need to make a poker game! When I first posted this my intent was to be able to have the absolute strength of each hand be represented by a real number. However after getting into some of the link people have provided, I'm gonna get the probabilities going for the AI based on the hole cards and public cards. All I need now is to be able to determine the best hand from 7 cards. I was hoping to find some nice elegant solution, but now I'm just doin one of these...

bool hasPair(Hand hand);
bool hasTwoPair(Hand hand);
bool hasThree(Hand hand);

etc.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now

• ### Forum Statistics

• Total Topics
628327
• Total Posts
2982089

• 22
• 9
• 9
• 13
• 11