1 unstable release

Uses new Rust 2024

new 0.1.2 May 13, 2025

#377 in GUI

Download history 53/week @ 2025-05-07

53 downloads per month
Used in 5 crates (3 directly)

Apache-2.0

120KB
839 lines

Freezeout Poker Cards

This crate implements types for poker cards and provides functionality for dealing, sampling, and iterating over cards in a deck.

With the egui feature enabled it exports texture types to paint cards in an egui application, see the board example in the eval crate for a simple egui app that uses the textures.


lib.rs:

Freezeout Poker cards types.

This crate define types to create cards:

let ah = Card::new(Rank::Ace, Suit::Hearts);
let kd = Card::new(Rank::Ace, Suit::Diamonds);

and a [Deck] type for shuffling, sampling, and iterating cards in the deck.

For example to iterate through all 7 cards hands:

let mut counter = 0;
Deck::default().for_each(7, |hand| {
    counter += 1;
});
assert_eq!(counter, 133_784_560);

to sample 10 random 5-cards hands:

let mut counter = 0;
Deck::default().sample(10, 5, |hand| {
    assert_eq!(hand.len(), 5);
    counter += 1;
});
assert_eq!(counter, 10);

The parallel feature enables parallel sampling and iteration with a given number of tasks, the following example uses 4 tasks to iterate all 7 cards hands, the closure task_id can be used to store per task data to reduce contention:

let counter = atomic::AtomicU64::new(0);
Deck::default().par_for_each(4, 7, |task_id, hand| {
    assert_eq!(hand.len(), 7);
    counter.fetch_add(1, atomic::Ordering::Relaxed);
});
assert_eq!(counter.load(atomic::Ordering::Relaxed), 133_784_560);

for parallel sampling the following uses 4 tasks and sample 10 7-cards hand for each task:

let counter = atomic::AtomicU64::new(0);
Deck::default().par_sample(4, 10, 7, |task_id, hand| {
    assert_eq!(hand.len(), 7);
    counter.fetch_add(1, atomic::Ordering::Relaxed);
});
assert_eq!(counter.load(atomic::Ordering::Relaxed), 40);

The egui feature enables the Textures type that gives access to the card images, see the board.rs example for a simple egui app that uses this crate cards to compute hands probabilities.

Dependencies

~1–20MB
~303K SLoC