10 releases (4 breaking)

0.5.1 Jul 27, 2024
0.5.0 Jul 13, 2024
0.4.0 Jun 8, 2024
0.3.4 May 19, 2024
0.1.0 May 6, 2024

#43 in Simulation

Download history 115/week @ 2024-07-23 24/week @ 2024-07-30 10/week @ 2024-09-10 5/week @ 2024-09-17 21/week @ 2024-09-24 2/week @ 2024-10-01

965 downloads per month

MIT license

1MB
11K SLoC

Pokers

docs.rs crates.io

A poker library written in rust.

  • Multithreaded range vs range equity calculation
  • Fast hand evaluation
  • Efficient hand indexing
  • Individual hand and combo results

Installation

Add this to your Cargo.toml:

[dependencies]
pokers = "0.5.1"

Hand Evaluator

Evaluates the strength of any poker hand using up to 7 cards.

Usage

use pokers::{Hand, CARDS};
// cards are indexed 0->51 where index is 4 * rank + suit
let hand = Hand::empty() + CARDS[0] + CARDS[1];
let score = hand.evaluate();
println!("score: {}", score);

Equity Calculator

Calculates the range vs range equities for up to 6 different ranges specified by equilab-like range strings. Supports monte-carlo simulations and exact equity calculations

Usage

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("2h3d4c");
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;
println!("player 1 equity: {}", equities[0]);

Credit

This library is a fork of Kyle Murphy's rust rewrite (rust_poker) of zekyll's C++ equity calculator, OMPEval. Differences with the original repo:

  • Fixes an issue that's been in the library for years without update. Impacts exact_equity()
  • It stores the results for the individual hands and then aggregates them into combos at the end of the simulation.
  • Only 1 dependency (rand).
  • Uses hardcoded arrays for lookups, so no need to read and write from files, use vectors, or lazy_static. This speeds up compilation significantly.
  • Adds a cancel token to the simulator to stop it at any time from another thread.
  • Uses a callback that takes the progress of the simulation.

License

This project is MIT Licensed

Copyright (c) 2020 Kyle Murphy

Copyright (c) 2024 Eduardo Mata Ewy

Dependencies

~1.4–2MB
~37K SLoC