Poker hand evaluator
This crate contains fast Texas hold'em poker hand equity evaluator.
Each of the 52 deck cards is attributed an integer key.
The 9 least significant bits encode the card suit, the others 23 the card face.
This encoding, based on keys precalculated by crate poker_keygen, in is such that it enables to uniquely identify a hand rank by a few simple operations (sums, bit mask, bit shift, and table lookups).
To use this crate as a server see poker_server.
Eval
Building the lookup is performed in sequence:
5-card hands
Build 5-card lookup tables: five::build_tables.
Which enables function get_rank_five.
use ;
// precalculate lookup tables
let t5 = build_tables;
// run the evaluation multiple times
let rank = get_rank_five;
assert_eq!
7-card hands
Build 7-card lookup tables: seven::build_tables using function [eval::seven::get_rank_seven] built on [eval::five::get_rank_five].
Which enables function get_rank.
This function is the entry point to evaluate a player hand.
use ;
// precalculate lookup tables
let arc_t7 = build_tables;
// run the evaluation multiple times
let rank = get_rank;
assert_eq!
Calc
From function get_rank, 2 calculation functions are implemented:
- deterministic, ie. exhaustive
- monte carlo
Deterministic
Function calc_equity_det:
- Calculate the equity of all players hands through exhaustive simulation.
- This requires all players cards to be known.
- This is feasible because in all cases, the number of simulations is small - and the evaluator fast.
use build_tables;
use calc_equity_det;
// precalculate lookup tables
let arc_t7 = build_tables;
// then you can call calc_equity_det multiple times
let equity = calc_equity_det;
println!;
//Ok([[0.23131312, 0.10707071], [0.55454546, 0.10707071]])
Monte carlo
Function calc_equity_mc:
- Calculate the equity of the first player though monte carlo simulation.
- This does not require all players to be known.
- Because the number of cases is potentially massive, a number of simlations must be specified.
use build_tables;
use calc_equity_monte_carlo;
// precalculate lookup tables
let arc_t7 = build_tables;
// then you can call calc_equity_monte_carlo multiple times
let equity = calc_equity_monte_carlo;
println!;
// Ok(HandEquity { win: 0.3167, tie: 0.0 })