Expand description
§Pokers
A texas holdem poker library
Currently supports
- monte carlo range vs. range equity calculations
- full enumeration for exact equities
- fast hand evaluation
- individual hand and combo results
§Equity Calculator
use std::{io, io::Write};
use std::sync::{atomic::AtomicBool, Arc};
use pokers::{HandRange, get_card_mask};
use pokers::approx_equity;
let ranges = HandRange::from_strings(["AK,22+".to_string(), "AA,KK,QQ@50".to_string()].to_vec());
let board_mask = get_card_mask("2h3d4c5h6s");
let dead_mask = get_card_mask("");
let cancel_token = Arc::new(AtomicBool::new(false));
let callback = |x: u8| {
print!("\rProgress: {x}%");
io::stdout().flush().unwrap();
};
let std_dev_target = 0.01;
let n_threads = 4;
let result = approx_equity(&ranges, board_mask, dead_mask, n_threads, std_dev_target, cancel_token, callback).unwrap();
let equities = result.equities;§Hand Evaluator
use pokers::*;
// cards are indexed 0->51 where index is 4 * rank + suit
let hand = Hand::default() + CARDS[0] + CARDS[1];
let score = hand.evaluate();
let board = get_card_mask("AhTd9d");
let board = Hand::from_bit_mask(board);
let hole_cards = Hand::from_hole_cards(44, 45);
let final_hand = board + hole_cards;
let final_score = final_hand.evaluate();
let rank = final_score / 4096; // or final_score >> 12Structs§
- Combo
- A single player hand 0: index of card 1 1: index of card 2 2: weight of combo
- Hand
- 64 bit representation of poker hand for use in evaluator
- Hand
Range - A range of private player hands for texas holdem
- Simulation
Results - Stores total results of the simulation
- Unit
Results - This type can represent the results of a single hand or a single combo.
Enums§
Constants§
- CARD_
COUNT - Number of cards in standard deck
- CARD_
COUNT_ SHIFT - FLUSH
- FLUSH_
CHECK_ MASK32 - FLUSH_
CHECK_ MASK64 - FLUSH_
RANKS - Table of power of 2 flush ranks
- FOUR_
OF_ A_ KIND - FULL_
HOUSE - HAND_
CATEGORY_ OFFSET - HAND_
CATEGORY_ SHIFT - HIGH_
CARD - INDEX_
TO_ COMBO - INDEX_
TO_ HAND - PAIR
- PERF_
HASH_ ROW_ SHIFT - RANKS
- Tables of unique primes for hashing hands
- RANK_
COUNT - Number of ranks in a sandard deck (2 -> A)
- RANK_
MASK - RANK_
TO_ CHAR - char to u8 rank table
- STRAIGHT
- STRAIGHT_
FLUSH - SUITS_
SHIFT - SUIT_
COUNT - SUIT_
MASK - SUIT_
TO_ CHAR - char to u8 suit table
- THREE_
OF_ A_ KIND - TWO_
PAIR
Statics§
Functions§
- approx_
equity - Runs a monte carlo simulation to calculate range vs range equity
- card_
from_ str - card_
to_ string - Converts 0-52 card into String representation
- char_
to_ rank - Convert lowercase rank char to u8
- char_
to_ suit - Convert lowercase suit char to u8
- exact_
equity - Calculates exact range vs range equities
- flop_
from_ str - get_
card_ index - Return hole cards id Return usize::MAX if card are invalid
- get_
card_ mask - Converts a string into a 64bit card mask
- get_
draw - This function is very experimental. Usage not recommended. 1 - Straight Draw 2 - Gutshot Draw 4 - Double Gutshot Draw 8 - Backdoor Straight Draw 16 - Nut Straight 32 - Flush Draw 64 - Backdoor Flush Draw 128 - Nut (Backdoor) Flush (Draw)
- hole_
to_ string - holes_
to_ strings - mask_
to_ string - Converts 64 bit card mask to string representation