0

I'm building a Texas-Hold'em computer program and I need to determine which hand is a winner.

Can I find a sorted list of all hands stored as a single file online?

For example:

Hand, Rank
AH KH QH JH TH, 1
AD KD QD JD TD, 1
AC KC QC JC TC, 1
AS KS QS JS TS, 1
KH QH JH TH 9H, 2
...

In this example text file, all 4 royal flushes have the highest rank 1, then the next 4 best straight flushes will have a rank 2, and so on. If I have this file, writing a function to determine a winner becomes trivial. But I can't find such (or similar) file online.

3
  • 1
    you could generate this with code. But at that point, you may as well write out the logic for comparing hand strength yourself instead of making a long file like this.
    – Clarko
    Commented May 21, 2021 at 19:10
  • shouldn't you be comparing 7 cards, assuming your programs goes to showdown? 5 cards is the flop situation for every user
    – GKozinski
    Commented Feb 14, 2023 at 10:42
  • @GKozinski I am comparing all choices of 5 cards out of the 7 cards. Commented Feb 14, 2023 at 10:56

2 Answers 2

1

http://www.suffe.cool/poker/7462.html

Contains a list of all 7,462 equivalence classes. If you want all 2+ million distinct hands instead, it would be quicker to write a program to generate them than it would be to download an already made list.

Using that list as a lookup table to evaluate hands wouldn't be very efficient; you'd either have to pre-sort the hand anyway to look up in the 2M list, or else make a list including all re-arrangements, which would be 311M. There are faster methods.

If you just want a blindingly fast poker hand evaluator, there are several available. Kevin's at the same site as above, mine at github.com/lcrocker/ojcardlib (website currently down), 2+2, etc. Mine only requires about 1Mb of lookup tables, and the actual evaluation function is

return ldc4[ ldc3[ ldc2[ ldc1[
    52 * (p->cards[0] - 1) + p->cards[1] ]
       + p->cards[2] ] + p->cards[3] ] + p->cards[4] ];

Can't get much faster than that (though I'm currently working on a Rust version that might). 2+2's is faster for 7 cards, but their lookup tables are much bigger.

1
  • This is exactly what will work for me, thx Commented May 21, 2021 at 19:25
0

That file would be 311.875.200 rows long. Probably not the most efficient way to solve your problem.

5
  • No, it's Choose 5 out of 52, which is less than 3 million. Commented May 20, 2021 at 20:59
  • Because the order does not matter, so you can divide 52 * 51 * 50 * 49 * 48 by 5 * 4 * 3 * 2 * 1 Commented May 20, 2021 at 21:02
  • You're correct. But still, is checking a several million row long file the best way to determine a winning hand?
    – David
    Commented May 20, 2021 at 21:03
  • Maybe not the best but definitely the simplest way. Just read a few MB of data into the RAM once at the start, and you don't need write a tricky function handling all the corner cases. Commented May 20, 2021 at 21:05
  • @David a lookup has been the most efficient method for at least fifteen years, crushing all other methods.
    – Corey
    Commented Oct 20, 2021 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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