Skip to main content

Crate pokers

Crate pokers 

Source
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 >> 12

Structs§

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
HandRange
A range of private player hands for texas holdem
SimulationResults
Stores total results of the simulation
UnitResults
This type can represent the results of a single hand or a single combo.

Enums§

SimulatorError

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§

CARDS
COMBO_TO_INDEX
HAND_TO_INDEX

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