Does anyone know a fast algorithm for evaluating 7 card poker hands? Something which is more efficient than simply brute-force checking a every 21 5-card combination of hands from a set of 7.
Cheers,
Pete
Does anyone know a fast algorithm for evaluating 7 card poker hands? Something which is more efficient than simply brute-force checking a every 21 5-card combination of hands from a set of 7.
Cheers,
Pete
Glad you asked :) Yes, here's a brand new solution that may be just the ticket:
Code: http://code.google.com/p/specialkpokereval/
Blog: http://specialk-coding.blogspot.com/2010/04/texas-holdem-7-card-evaluator_23.html
A commercial-grade evolution of this evaluator is available for the iPhone/iPod Touch via iTunes Store. It's called "Poker Ace".
An excellent summary of various solutions complete with links is found on James Devlin's blog "Coding The Wheel".
One evaluator not yet discussed there is Klaatu's.
Good luck!
I developed an algorithm for 7-card hand evaluation without iterating all 21 combinations.
Basically, it splits the 7-card hand into two categories: flush and not a flush. If it's a flush, it would be easy to look up the value in a table of 8192 entries. If it's not a flush, it'll run a hash function with techniques of dynamic programming, and then look up the value in a hash table of 49205 entries.
If you are interested, please check my work at github.
https://github.com/HenryRLee/PokerHandEvaluator
I developed a simulator Texas hold'em and during this development I found the number of 7462 unique combinations (52 - 5/5 cards) on the flop. In turn, this number drops to 6075 (5/6) and in the river to 4824 (5/7). This is because 1 or 2 cards are irrelevant in classifying the poker hand. An example is: 76543QK = 7654332 a straight (3 to 7)
My simulator is called Easy Poker and is available in my site http://crvltda.webs.com
Ref. Pokersoftware.com/forum
May I recommend https://github.com/chenosaurus/poker-evaluator/
It is written in JavaScript and uses a 128 MB HandRanks.dat file.
The code is just a few lines and very easy to port to any other language.
I've created a testbed for poker evaluators in C here. Of the evaluators I tested, the poker-eval library was the winner. Steve Brecher's Holdem Showdown was also quite fast and had significantly less memory requirements. My own ACE_Eval held it's own.
I'd welcome help adding other evaluators, and contributions of test results from other machines.
Of course, if you want to do it very fast. The algorithm i put before is too slow.
The table7462 shoul be in an array, not in a file.
Then, you should precalculate every different 7cards hands and store it to a database. There are 133.784.560 different 7cards combinations.
You should use this format (alphabeticall order):
"2c2d2h2s3c3d3h" and rank it
Store every 133.784.560 different combinations. You do 52C7 cicles, rank it and store it in a database. Maybe in a few days you have it ready. When you have it ready, you don´t need 21 combinations anymore, just put your hand sorted alphabetically and search for it in your database.
If you do that, you´ll see that you can calculate your odds against your opponents in real time whenever you need.
Believe me. I am not a programmer and i can do it. I know my odds at the flop in 3 seconds.