Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
63 lines
2.7 KiB
Rust
63 lines
2.7 KiB
Rust
//! Complete enumeration of all C(36,5) = 376 992 five-card hands of the short deck.
|
|
//!
|
|
//! Reference: the published short deck (six-plus) five-card frequencies, Wikipedia
|
|
//! "Six-plus hold'em": straight flush 24, quads 288, flush 480, full house 1 728,
|
|
//! straight 6 120, trips 16 128, two pair 36 288, pair 193 536, high card 122 400.
|
|
//! They also follow from counting: 4 suits x 6 straights = 24 straight flushes, 9 x 32 = 288 quads,
|
|
//! 9 x 4 x 8 x 6 = 1 728 full houses, 4 x C(9,5) - 24 = 480 flushes.
|
|
//! The flush is rarer than the full house, which is why the short deck ranks it higher.
|
|
use rechner::card::{deck, Card};
|
|
use rechner::hand::category::Category;
|
|
use rechner::hand::five::evaluate_in;
|
|
use rechner::hand::strength::Strength;
|
|
use rechner::variant::{DeckRule, HandRanking};
|
|
|
|
fn counts(ranking: HandRanking) -> ([u32; 9], Vec<Strength>) {
|
|
let cards = deck::of(DeckRule::SHORT);
|
|
let n = cards.len();
|
|
let mut counts = [0u32; 9];
|
|
let mut straight_flushes = Vec::new();
|
|
for a in 0..n {
|
|
for b in a + 1..n {
|
|
for c in b + 1..n {
|
|
for d in c + 1..n {
|
|
for e in d + 1..n {
|
|
let five: [Card; 5] = [cards[a], cards[b], cards[c], cards[d], cards[e]];
|
|
let s = evaluate_in(DeckRule::SHORT, ranking, &five);
|
|
counts[s.category as usize] += 1;
|
|
if s.category == Category::StraightFlush {
|
|
straight_flushes.push(s);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
(counts, straight_flushes)
|
|
}
|
|
|
|
#[test]
|
|
fn five_card_frequencies_match_the_published_table() {
|
|
let (counts, straight_flushes) = counts(HandRanking::FlushOverFullHouse);
|
|
assert_eq!(counts[Category::StraightFlush as usize], 24);
|
|
assert_eq!(counts[Category::FourOfAKind as usize], 288);
|
|
assert_eq!(counts[Category::Flush as usize], 480);
|
|
assert_eq!(counts[Category::FullHouse as usize], 1_728);
|
|
assert_eq!(counts[Category::Straight as usize], 6_120);
|
|
assert_eq!(counts[Category::ThreeOfAKind as usize], 16_128);
|
|
assert_eq!(counts[Category::TwoPair as usize], 36_288);
|
|
assert_eq!(counts[Category::Pair as usize], 193_536);
|
|
assert_eq!(counts[Category::HighCard as usize], 122_400);
|
|
assert_eq!(counts.iter().sum::<u32>(), 376_992);
|
|
// the lowest straight flush is the ace-low one, nine high
|
|
let lowest = straight_flushes.iter().min().expect("some");
|
|
assert_eq!(lowest.ranks[0], 9);
|
|
}
|
|
|
|
#[test]
|
|
fn the_ranking_choice_changes_how_hands_compare_not_what_they_are() {
|
|
let (standard, _) = counts(HandRanking::Standard);
|
|
let (flush_first, _) = counts(HandRanking::FlushOverFullHouse);
|
|
assert_eq!(standard, flush_first);
|
|
}
|