I am trying to develop a scoring function for 5-card draw poker hands. The scoring function must produce a partial ordering over hands, so that the score of hand 1 is less than the score of hand 2 if and only if hand 2 beats hand 1.

An example scoring function:

  1. Assign each hand a base score determined by the type of hand alone (e.g. pair, straight, four of a kind).
  2. Add additional points to the base score determined by the rank of the cards involved in the hand
  3. Add more points based on the side cards.

Note that each scoring tier in the above 1, 2, 3 must be less than the previous to keep the tiers seperate. So for instance, let's compare a straight and a flush.

Hand A: 3S 4C 5D 6D 7H
Hand B: 2H 6H KH 4H 10H
  1. The Flush (hand A) will receive a base score of say 500 or 5000, and the straight will receive a 400 or 4000.
  2. Square each rank based on numerical value (3 = 3, 7 = 7, K = 13, A = 14) and sum (will this prevent duplicate score for different hands?)
  3. Since flushes use all the cards in the hand, step 3 is irrelevant.

Now let's compare two hands with 2 pairs.

Hand A: KS KH 7S 7H 3S
Hand B: KC KD 7C 7D 2D
  1. Both hands will receive the same base score of say 200 or 2000 for the hand type (2 pairs).
  2. Both hands will receive the same bonus for a pair of kings and a pair of 7s (but how to make sure that the higher pair always controls and the lower pair only breaks ties).
  3. Hand A will receive a higher tie-breaker bonus for a 3 instead of a 2.

What algorithm will work and account for all known hands of value?

  • Two straight flushes are not possible in texas holdem as all players share 5 cards and only have two unique cards so I am not sure what you are asking about.
    – Joe W
    Feb 27, 2017 at 0:52
  • Please provide a citation on suite ordering.
    – paparazzo
    Feb 27, 2017 at 10:48
  • @Paparazzi: I think it's a somewhat common house rule; here's one reference. Feb 27, 2017 at 16:53
  • @ruds: Your edit made the question a lot clearer, but you're in the grey zone of "conflicts with author's intent" by removing the suit stuff - sure it's a non-canonical house rule, but if OP wants it who are we to say no? Feb 27, 2017 at 16:57
  • @BenjaminCosman Common house rule? Any single casino play that way? You cannot even have flushes of different suits without wild cards. Depending on the wild cards you even change the order of the hand ranks.
    – paparazzo
    Feb 27, 2017 at 17:02

2 Answers 2


I can't tell why you'd want to do this, but it's easy enough to do. There are 2598960 (= 52 choose 5) different 5-card poker hands, a small enough number that a computer program can quickly sort them all and assign consecutive scores, though they wouldn't be very readable by humans. If you want scores you can interpret yourself, here's one method:

First assign a score 1-9 for the type of hand (only singles = 1; straight flush = 9). Then put the cards in descending order but with key hand elements like pairs in front, write each number as two digits (with aces as 14), and concatenate the results. So for example, the hand 6 6 A K 2 is a pair, the second lowest kind of hand, so it becomes 20606141302 as an integer (that's 2-06-06-14-13-02). Unless I'm forgetting something about poker rules, a higher integer should now always represent a better hand.

Note that suits are not ranked in standard poker, but it would be easy enough to extend this kind of scoring to include suit information if you wanted to, e.g. by adding a digit between 1 and 4 to the end for a suit tiebreaker. In standard poker, not every hand should end up with a different score because two hands can be tied.

  • Thank you, this is along the lines of what I was looking for. One last question: you mention that you can't tell why I'd want to do this... sure, most hands are ranked by humans and done without much thought. But for fast processing, or where computer logic is used, having a score for a hand will allow the quick comparison of two integers representing the strength of the hand. I had already began working on somethings along the lines of what you suggest, but posted here to make sure I wasn't ignoring any rules that would contradict the scoring system...
    – user58446
    Mar 3, 2017 at 17:34
  • ...Is there really no system like this for poker (common variants) already in use? I was not able to find anything that directly spelled out the 'scoring' part, mostly how to 'evaluation' of actual hands.
    – user58446
    Mar 3, 2017 at 17:36
  • There may well be a system like this in use but I don't know; my guess is that many computer adaptations skip 'scoring' entirely and just implement a comparator for hands. Mar 4, 2017 at 0:24
  • What? Don't they need some system for comparing/scoring/ranking hands in order to implement a comparator?
    – user58446
    Mar 18, 2017 at 20:15
  • Yes, but for example, the first thing any comparator should probably do is figure out what type hand each is. Now if the types are different, why do any further analysis of the hands when you can just immediately return which is better? And if the hands have the same type, then type is not going to affect which hand is better so why keep track of it? So my guess is that writing something that just gives an answer of better/equal/worse at its first opportunity may be easier than first canonicalizing each hand to an integer. Mar 18, 2017 at 21:10

This is for standard rule book hands. If you have some custom game then spell it out (and I will just delete this answer).

Terms are a little confusing in poker as you have hand rank and card rank. A card also has a suite.

On no pair or flush all five cards can come into play so you need to allow for hand rank + 5 card rank.

Square and sum does not work for like a full house as 5 5 5 2 2 would lose to 4 4 4 A A

There is no purpose to scoring suite as all suite are equal. It is a flush or not.

0 - high card - 5 cards 
1 - one pair - 4 cards - start with pair
2 - two pair - three cards - start pairs 
3 - trips - three cards - start with trip 
4 - straight - one card 
5 - flush - 5 cards 
6 - boat - 2 cards - start with the trips  
7 - straight flush - card

4 4 7 5 J would be 10411070500
1 is the hand
04 is the 4
11 is the jack
07 is the 7
05 is the 5
00 is you only need 4 numbers for pair

3 3 3 J J would be 60311000000 notice the 3 is first as it is the trips

so the worse possible hand is


best possible hand is


Int32 (2^32) goes up to 4294967296 which is just short so you have to use Int64

There are 2,598,960 unique hands but there are only 7,462 distinct hands. So if you do it smart can just go from 1 - 7,462. WIKI poker probability

  • Down vote what is the problem?
    – paparazzo
    Feb 28, 2017 at 6:59

Not the answer you're looking for? Browse other questions tagged .