Expand description
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.