Really appreciate the effort you put on this code project. It's amazing how much of a difference look up tables can make in speeding up code - It makes sense that the pre-calculated data will speed code up. This article shows just a small amount of the code I wrote when I had nothing better to do than tinker. We may have ties sometimes, in which case we end up with more than one winner. Sign up or log in Sign up using Google. Keith Rule , 18 Apr I am usual visual studio13, with a quad-core computer.
The Porting Process
For each hold setting, the expected value is calculated by iterating through all possible 5 card hands and summing the winning amount. The expected value is simply the summed winnings divided by the total number of hands evaluated.
The best expected value and its associated hold mask is saved and printed out. The following code illustrates this. To modify this to handle a different video poker payout schedule, you need to replace the JacksOrBetterWinnings function with the alternate payout schedule. All of the card image code and controls that I've run across use bitmaps for card images. This has the advantage of being straightforward, but bitmap images don't scale well and have other issues.
He has a vector based card library that I was able to import into Adobe Illustrator. I took David Bellot's cards and emitted them as C code and wrapped that as a user control. This makes a very useful vector card control. The advantage of this control is that the cards look good regardless of their size.
The disadvantage is that the control is large about 7 Megs and the source code is even larger clocking in at a whopping Even though the control is large, it renders reasonably quickly. However, loading and JITing can take a few seconds. The usage is very straightforward. You load it as you would load any other control into the toolbox right click on the Toolbox, select "Choose Items Once loaded, you can drag it on to a form.
The property " Card " is an enumeration of the card faces and card backs that can be displayed. The values for the card faces correspond with the card values used by the Hand. This simplifies the assignment of card values to the control.
If you visit David Bellot's website, you will notice that he has a newer and nicer version of his SVG cards. However, for some reason, Adobe Illustrator doesn't load the new cards correctly. I haven't found a workaround for that. Until I do, this older version of his card library will have to do. All of the applications and libraries are written in C and can be compiled in Visual Studio or Visual C Express which is free. I've been working on this code for quite a while I was on sick leave for 5 months.
I'm sure there are several websites that gave me ideas. These are just the ones that I can document as making it into this software. I started this project because I was interested in doing some analysis of poker, and I wanted a real project to try out Visual Studio it was beta at the time. During the process of trying to speed things up, I discovered several things that surprised me.
The code that the hand evaluator is based on poker-eval is GPLed. He has also LGPLed his images. Since that covers most of the core pieces of the applications I've written, I also am GPLing my code. See each project for more information. This article shows just a small amount of the code I wrote when I had nothing better to do than tinker. Hopefully, it's interesting and useful to those poker players and bot writers out there.
Articles Quick Answers Messages. Keith Rule , 18 Apr Please Sign up or sign in to vote. Download executable - 2. A fast Texas Holdem hand evaluator class library with a benchmark application. A vector card image class for displaying high quality, scalable card faces.
An Odds Grid application that gives the chances of a hand winning against an average opponent. A Jacks or Better Video Poker trainer. This program helps to learn how to play Jacks or Better Video poker perfectly. Taking from the Best When analyzing poker hands, doing an exhaustive search quickly is much more straightforward and more accurate than having to do a Monte Carlo simulation or coming up with some clever heuristic. Ease of Use My second goal after making it fast was to make it easy to use this class for simple things.
The following example shows how to create instances of two Texas Holdem hands, prints out a description of each hand, and then compares the two hands: WriteLine " Player1 Hand: WriteLine " Player2 Hand: The Poker-eval Model The Poker-eval defines two basic kinds of masks. The following code snippet shows how to parse a string description of a hand into a hand mask and then evaluate the hand mask to create a hand value: There are two iterator functions defined: Hands ulong shared, ulong dead, int numberOfCards The Hand.
WriteLine " Total hands to check: The equivalent code with the iteration code inlined looks like the following: Building a Hand Odds Calculator If you've watched poker on TV, you've seen the on-screen display of the odds each player has for winning the hand.
The following code illustrates how this is calculated: The following code example shows how this calculation is made: WriteLine " Player Results" ; Console. WriteLine " High Card: WriteLine " Two Pair: WriteLine " Three of Kind: WriteLine " Four of a Kind: WriteLine " Straight Flush: WriteLine " Opponent Results" ; Console.
WriteLine " Best EV: Compatibility All of the applications and libraries are written in C and can be compiled in Visual Studio or Visual C Express which is free. Acknowledgements Poker-eval - a great C library for card evaluation that I used as a basis for my class library. Interesting Issues I started this project because I was interested in doing some analysis of poker, and I wanted a real project to try out Visual Studio it was beta at the time.
It's faster to lookup a single bit left shift from a table than it is to do a left shift directly - This one left me scratching my head. This shouldn't be true, but try for yourself and you'll see that a lookup table is faster. It's amazing how much of a difference look up tables can make in speeding up code - It makes sense that the pre-calculated data will speed code up.
But looking at poker. I've had the IDE crash and then crash again when trying to send the error report to Microsoft because of a heap corruption. Intellisense occasionally goes a bit bonkers, and load time is very long on big files. Vector Cards don't run correctly on the 64 bit version of. Most things worked as expected, but the vector card control is very slow.
I suspect this is an issue with the bit runtime and very large methods. History First version released - Dec 1 st Updated Feb 6 th , - Fixed table used for two card hand odds. Added random hand iterator for Monte Carlo analysis , included NUnit test, speeded up hand iterators by strongly typing the return value. Updated April 18 th - Fixed two reported bugs. Another issue was fixed related to stack overflow when the equal operator was used on a Hand instance.
License The code that the hand evaluator is based on poker-eval is GPLed. Conclusion This article shows just a small amount of the code I wrote when I had nothing better to do than tinker. Keith Rule Software Developer Senior. I work at Tektronix in Beaverton OR. I've been programming in C since and I've been working professionally since I really enjoy www.
It has saved me an incredible amount of time. I only hope my small contributions have given back some of what I've taken. First Prev Next Would do you help me? Member Dec 5: Keith Rule Oct 7: Skaeff A Jun Ben Record Sep Keith Rule Sep Nadir Muhammed Dec 3: Julio Pereira Mar 4: Article Alternatives Comments Add your own alternative version Tagged as.
Would do you help me? I want to have a program that has more advanced functionality. Please reply to me. Should it be this slow? UserControl1", it will calculate the percentages in about 1 second for my pocket cards, but when it is asked to evaluate my pocket cards plus 3 flop cards, the result takes about seconds.
I am usual visual studio13, with a quad-core computer. The program I wrote simply sets the card strings to 'UserControl1' as follows: I think part of my problem may of been that when I do another calculation because there has been a flop or turn card shown, that I re-assign my pocket cards even though the module already knows what they are.
Is there a setting anywhere for a quicker calculation with results that might be off by a percent or two? I could of sworn I saw something in the source code but darned if I can find it now.
I play a lot of cash games and because of this I have an idea for a software. I'd like to ask you some questions.
Different Hand Odds Result tiger Nov 2: However, running some sample with your Hand Odds App, I got some different result than your one and my one is the same as one of the texas hold tool. Just want to ask you if you can verify to see what is the difference between your one and my one.
Really appreciate the effort you put on this code project. Detailed Hand Odds Calculator - Against how many opponents? Got a quick question around the Detailed Hand Odds Calculator, for how many opponents is that against? The answer to that question is here: More Texas Holdem Analysis in C: Wrong two pair calculation Skaeff A Jun It is completely wrong - i've got only one pair 9c 9s.
Wrong two pair calculation Jul 4: You have a pair in your hand and a pair on the board, your best hand is 2 pair and a shot at FH. Chance of winning without knowing other players cards Oct 7: Shouldn't think calculate the chances of winning without knowing the other players cards?
Such as this pot odds calculator? Best 5 cards in 7-card hand Mar The last thing to explain is the card-bitfield word itself…it looks up the proper bit values for the different parts of our card representation, and then constructs the final 4-byte integer from those values. See the bitfield documentation for more details on its syntax.
This is where the languages start to noticibly deviate in their implementations…. These are all straight-forward arrays, and we have four to consider:. If the values are the same, the hands are tied. A simple comparison function can tell you which hand is best. The source word simply converts the provided text file into the format our evaluator expects and the hand comparisons are subsequently handled by the euler word and counted up! Since porting the initial version of the poker vocabulary, many improvements have been made to generalize the code for use beyond just solving Project Euler problems.
Problem 54 In order to solve Problem 54 , I needed to come up with a way to programatically determine the winner when comparing two poker hands.
Constants Now that we have an efficient means of representing individual cards, we need to establish some basic constants to align with the above bitfield representation and overall hand values… Constants In C: