Crates.io | poker_eval |
lib.rs | poker_eval |
version | 0.1.0 |
source | src |
created_at | 2024-02-05 09:11:28.198652 |
updated_at | 2024-02-05 09:11:28.198652 |
description | Texas Hold'em poker hand equity evaluator |
homepage | |
repository | https://github.com/oscar6echo/poker5 |
max_upload_size | |
id | 1127412 |
size | 89,416 |
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.
Building the lookup is performed in sequence:
Build 5-card lookup tables: five::build_tables.
Which enables function get_rank_five.
use poker_eval::eval::five::{build_tables, get_rank_five};
// precalculate lookup tables
let t5 = build_tables(false);
// run the evaluation multiple times
let rank = get_rank_five(&t5, [31, 26, 50, 16, 49]);
assert_eq!(rank, 3971)
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 poker_eval::eval::seven::{build_tables, get_rank};
// precalculate lookup tables
let arc_t7 = build_tables(false);
// run the evaluation multiple times
let rank = get_rank(&arc_t7, [5, 4, 18, 31, 34, 48, 22]);
assert_eq!(rank, 1689)
From function get_rank, 2 calculation functions are implemented:
Function calc_equity_det:
use poker_eval::eval::seven::build_tables;
use poker_eval::calc::equity_det::calc_equity_det;
// precalculate lookup tables
let arc_t7 = build_tables(true);
// then you can call calc_equity_det multiple times
let equity = calc_equity_det(
// clone of Arc<TableSeven>
arc_t7.clone(),
// players cards
vec![[7, 8], [22, 27]],
// table cards
vec![51, 30, 41],
// verbose
true
);
println!("equity = {:?}", equity);
//Ok([[0.23131312, 0.10707071], [0.55454546, 0.10707071]])
Function calc_equity_mc:
use poker_eval::eval::seven::build_tables;
use poker_eval::calc::equity_mc::calc_equity_monte_carlo;
// precalculate lookup tables
let arc_t7 = build_tables(true);
// then you can call calc_equity_monte_carlo multiple times
let equity = calc_equity_monte_carlo(
// clone of Arc<TableSeven>
arc_t7.clone(),
// player cards
vec![vec![8, 9], vec![11, 28], vec![]],
// table cards
vec![15, 47, 23, 33],
// number of game
100_000_000,
);
println!("equity = {:?}", equity);
// Ok(HandEquity { win: 0.3167, tie: 0.0 })