Fast poker ranges, evaluation, equity calculation
npm install poker-utilsReally fast poker hand evaluation in pure TypeScript
- NLHE and 4-6 card Omaha strength evaluation
- fast isomorphism and weighted isomorphic tree building
- 10x faster board/card sorting
- poker theory math like alpha, bluffEV, and catchEV
- range operations like combosVsRangeEquity
- site-specific rake information
- easily generate and access from a hash of every combo on every unique flop
_Update:_ if really fast isn't fast enough, check out
``js
import { PreflopRange, boardToInts, evaluate, iso } from 'poker-utils'
const preRange = new PreflopRange()
preRange.set('66')
preRange.set('AKs', 0.5)
preRange.toString() // "AKs:0.5,66"
preRange.getWeight('AKs') // 0.5
const { board, hand } = iso({
board: boardToInts('Kh9c4s3c5h'),
hand: boardToInts('3d3s')
})
console.log(formatCards(board)) // [ 'Ks', '9h', '4d', '3h', '5s' ]
console.log(formatCards(hand)) // [ '3d', '3c' ]
const evaluated = evaluate([...board, ...hand])
console.log(evaluated) /*{
handType: 4,
handRank: 118,
p: 16502,
value: 5113,
handName: 'Three of a Kind'
}*/
`
use new PokerRange() or PokerRange.fromPreflop(...)
Percentages are always 0-1 with no rounding
The deck is 0-indexed, ascending from 2c (0) to As (51). Most methods input/output a number[]. Use boardToInts(str): number[] and formatCards(number[]): str for conversion.
ahead methods don't compute each runout like the corresponding equity methods do
V8 is pretty fast, but the fastest algorithms (OMPEval) use SIMD which isn't available
Ran using mitata for poker-utils v13.1.7
clk: ~5.07 GHz
cpu: Intel(R) Core(TM) i5-14600K
runtime: node
arch: x64-linux
clk: ~5 GHz
Node.js v22.17.0
| Benchmark | Mean | p99 |
| --------------------------------------------------- | ---------- | ---------- |
| 2p2 range vs range river equity | 318.16µs | 507.69µs |56.05µs
| ...sparser ranges (random 100 combos) | | 151.04µs |110.31ns
| Node.js 7 cards .sort | | 186.67ns |8.18ns
| poker-utils 7 cards sortCards() | | 10.22ns |665.45µs
| full range to isomorphic | | 934.23µs |57.49µs
| generate turn+river runouts | | 156.86µs |140.81ns
| flop isomorphism | | 183.92ns |141.41ns
| phe rand 7 cards | | 170.25ns |86.71ns
| 2p2 rand 7 cards | | 133.12ns |11.30ns
| 2p2 random 2 cards on fixed river | | 13.03ns |53.93ms
| 2p2 all combos all runouts after flop (~7.3m evals) | | 54.26ms |12.48ms
| 2p2 turn equity vs range | | 12.99ms |
By default this package uses a modified version of PHE (
The 2p2 algorithm is basically this, where hr is an precomputed array of ~32m ints
`py`
p = 53
for card in cards
p = hr[p + card]
return p
Poker-Hand-Evaluator (phe) has lookup tables that are much smaller, so even though there's much more computation, it gets better optimized away and ends up similar to using 2p2 for performance
But for random evaluations on the same board, which is the case for the costliest operations (anything involving equity/multiple ranges), you can just store p, and now each hand only requires 2 lookups. Additionally, you're using much less of the lookup array resulting in better caching. The genBoardEval function implements this and leads to a 10-20x speedup: 91m random 7 card hands per second on 5 GHz
To load hr, which you can download here initFromPath/initFromPathSync, or init if you already have the file loaded
Maps original suits to new suits such that all strategically identical boards turn into the same board. This implementation matches PioSOLVER which sorts flop descending by rank and assigns suits descending alphabetically (s -> h -> d -> c)
For example, all monotone flops become 3 spades (Kh7h3h -> Ks7s3s)
- Breaking Equity/ahead methods now return an array [lose, tie, win], or [combo, lose, tie, win][] if evaluating a rangeequityVsRange
- Added to HoldemRange` which is 10-200x faster
- Deck now goes from 0-51, and ranks from 0-12
- representing omaha ranges well (AKQ9ss type)
- CLI commands for hash generation
- bucketing, or other ways to trade precision for speed
- Monte carlo is necessary for many preflop and 3+ players spots, and maybe for PLO flops
- webassembly OMPEval