The Felt
Poker Tools & Software

Build Your Own Poker Equity Calculator in Python

Build a poker equity calculator in Python: Monte Carlo vs exact enumeration, the core loop, trial counts for accuracy, and porting to Android.

On this page · 5 sections

To build a poker equity calculator in Python you need four steps: represent the deck, deal the known cards, simulate the unknown ones many times, and count how often each hand wins. That’s the whole algorithm, and a working heads-up version fits in well under a hundred lines. Writing it yourself is one of the best ways to actually understand equity, because you can’t fake a result you had to compute from scratch.

The two algorithms

There are exactly two ways to compute equity, and picking between them is the first design decision.

Exact enumeration deals every remaining board, evaluates each one, and averages. It’s precise, and preflop heads-up it’s cheap enough to run instantly. But the number of runouts explodes as you add unknown cards and extra players.

Monte Carlo deals random runouts thousands of times and converges on the true equity as trials grow. It’s the practical choice for multiway pots and range-vs-range spots where full enumeration is far too slow.

A good calculator enumerates when the space is small and falls back to Monte Carlo when it isn’t.

The core loop

The structure is the same in any language:

1. Build a 52-card deck; remove all known cards (hole + board).
2. Repeat N times:
     a. Shuffle the remaining deck.
     b. Deal any missing board cards.
     c. Evaluate each player's best 5-card hand.
     d. Credit 1 to the winner, or split among ties.
3. equity = (wins + 0.5 x ties) / N   for each player.

Step (c), the hand evaluator, is what makes or breaks it. A naive evaluator scores every five-card combination and works fine for study; production tools use lookup tables that turn a seven-card hand into an integer rank in a single array read.

How many trials you need

Monte Carlo error shrinks with the square root of the sample, so it roughly halves each time you quadruple the trials:

TrialsApprox. error (±)
10,000~0.5%
100,000~0.15%
1,000,000~0.05%

For most study, 100,000 trials is the sweet spot — well within a fraction of a percent and near-instant on a modern CPU. Preflop heads-up, skip sampling and enumerate all 1,712,304 possible boards for an exact answer.

Validate against known spots

Test on results you can look up. AhAs versus KdKc preflop should return roughly 82% / 18%. AhKh versus QsQd — the classic race — should land near 46% / 54%. If your numbers match, your evaluator and loop are correct. If they don’t, the bug is almost always in tie handling or in forgetting to remove the known cards from the deck before dealing.

From hands to ranges

Real analysis is hand-versus-range. Extend the loop: before each trial, deal the villain a random combo from their range — say {QQ+, AKs} — rejecting any combo that collides with the known cards, then average across the range. That’s exactly what a solver does under the hood, and it’s where the project stops being a toy and starts teaching real poker math from odds and equity fundamentals.

If you later want speed, the two standard tricks are precomputed lookup tables (encode a hand as an integer, store its rank in a flat array so evaluation is one memory read) and bitmask representation (store a hand as a 52-bit integer and detect flushes and straights with bit tricks). You don’t need either to learn — a slow, obviously correct evaluator is better for that — but they’re why production calculators feel instant.

Porting to Android changes nothing about the math — deck, deal, evaluate, tally. You port the evaluator and loop into Kotlin or Java (or wrap a compiled C core via JNI for speed), keep the trial count modest so it stays responsive, and put a card-picker UI on top. When you’re ready to see how others structured it, study the open-source poker tools and compare your output against a reference equity calculator in the wider poker tools ecosystem.

Frequently asked

How do you build a poker equity calculator in Python?

Represent the deck, remove the known cards, then either enumerate every possible runout for an exact answer or deal random runouts thousands of times for Monte Carlo. Each trial, evaluate every player's best five-card hand and credit the winner, then divide wins plus half of ties by total trials to get each hand's equity.

How many Monte Carlo trials do you need?

Accuracy improves with the square root of trials, so error roughly halves each time you quadruple the count. Around 100,000 trials puts you within a few tenths of a percent for most spots, and a million tightens it further. Preflop heads-up you can enumerate every board exactly instead of sampling.

Can you build a poker equity calculator on Android?

Yes — the algorithm is identical to Python: deck, deal, evaluate, tally. You port the hand evaluator and Monte Carlo loop into Kotlin or Java, or wrap a compiled core, keep the trial count modest so it stays responsive on a phone CPU, and add a card-picker UI on top.

About the author

Solver-driven study, quantitative background · Reviewed by Elena Fowler, managing editor
Last updated 2025-12-11