33

I'm trying to write a simple game/utility to calculate poker odds. I know there's plenty of resources that talk about the formulas to do so, but I guess I'm having trouble translating that to code. Particularly, I'm interested in Texas Hold-em ...

I understand that there are several different approaches, one being that you can calculate the odds that you will draw some hand based on the cards you can see. The other approach is calculating the odds that you will win a certain hand. The second approach seems much more complex as you'd have to enter more data (how many players, etc.)

I'm not asking that you write it for me, but some nudges in the right direction would help :-)

2
  • Once you get it working will you add in calculating pot odds so it comes down to a binary decision for call/fold situations?
    – Ed.T
    Oct 17, 2008 at 13:07
  • Not an answer, making it a comment/nudge - an open source evaluator in Objective-C (primarily C) and Java can be found here: specialk-coding.blogspot.com/2010/04/… (link at the end of the article to Google Projects).
    – Ken
    Feb 23, 2011 at 3:27

7 Answers 7

23

Here are some links to articles, which could help as starting points: Poker Logic in C# and Fast, Texas Holdem Hand Evaluation and Analysis

"This code snippet will let you calculate poker probabilities the hard way, using C# and .NET."

The theoretical fundamentals are given in this Wikipedia article about Poker Probabilities and in this excellent statistical tutorial.

An example of a complete project written in Objective-C, Java, C/C++ or Python is found at SpecialKEval. Further links and reading can be found therein.

6

Monte carlo simulation is a common approach to get the odds calculation for poker hands. There are plenty of examples of implementing this kind of simulation for holdem on the net.

http://www.codeproject.com/KB/game/MoreTexasHoldemAnalysis1.aspx

1
  • 1
    I have built a hand evaluator and poker simulator and I used montecarlo for the simulation as well. I didn't attempted to calculate the odds of winning for each of the different hole cards combinations mathematically but I imagine it would be a devilishly difficult task.
    – DPM
    Feb 2, 2012 at 21:43
0

Take a look at pokersource if you have reasonably strong C abilities. It's not simple, I'm afraid, but some of the things you're looking for are complex. The poker-eval program that uses the library will probably do much of what you want if you can get the input format correct (not easy either). Sites such as this one or this also use this library AFAIK.

Still, it could be worse, you could be wanting to calculate something tricky like Omaha Hi-lo...

0

Pokersource and the statistical articles are not bad suggestions. But this is really best done with a Monte Carlo simulation, a useful, simple, and powerful approach to this type of difficult problem.

It works equally well with Omaha Hi-lo as it does with Hold'em

0

Complete source code for Texas hold'em poker game evaluator can be found here:

http://www.advancedmcode.org/poker-predictor.html

It is built for matlab, the GUI id m-coded but the computational engine is c++.

It allows for odds and probability calculation. It can deal, on my 2.4Ghz laptop, with a 100000 10 players game computation in 0,3 seconds.

An accurate real time computer:-)

1
  • 1
    This is fairly fast but not that fast - there are evaluators in the public domain that give exact answers (i.e. no sampling) at least ~10x faster.
    – Ken
    Feb 23, 2011 at 3:25
0

Have a look here as well:

http://specialk-coding.blogspot.com/2010/04/texas-holdem-7-card-evaluator_23.html

Monte Carlo simulation is often slower than the good exact evaluators.

-1

We may also be able use combinatorics, calculating the odds with combinations and the number of ways each combination can appear. This way we don't have to iterate over all the possible hands.

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