Files
pokerfreak/tests/short_deck_ranking_generate.rs
mmintel 04d5251acf Welt ohne fremden Namen: Pruefordner vollstaendig mitkopieren, Engine nur im eigenen Baum
Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete
Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
2026-11-01 23:37:11 +01:00

62 lines
2.5 KiB
Rust

//! Offline generator of `preflop::short_deck_ranking::RANKING` (ignored by default).
//!
//! Run: `cargo test --release --test short_deck_ranking_generate -- --ignored --nocapture`
//! It prints the table body, classes best first. Method: for every one of the 81 classes take one
//! representative hand (suits do not matter inside a class by symmetry), deal 10 000 000 seeded
//! Monte Carlo trials against one uniformly random short deck hand with a random 5-card board
//! (`equity::monte_carlo::estimate`, short deck rules: flush over full house, ace low in A-6-7-8-9),
//! rank by pot share (ties split). Seeds are the class index, so the output is reproducible.
use rechner::card::Card;
use rechner::equity::monte_carlo::estimate;
use rechner::equity::query::Query;
use rechner::equity::villain_range::VillainRange;
use rechner::rng::Rng;
use rechner::variant::{rules, Variant};
const RANKS: [char; 9] = ['A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6'];
const TRIALS: u32 = 10_000_000;
fn classes() -> Vec<(String, String)> {
let mut out = Vec::new();
for (i, high) in RANKS.iter().enumerate() {
for (j, low) in RANKS.iter().enumerate().skip(i) {
if i == j {
out.push((format!("{high}{low}"), format!("{high}h {low}d")));
} else {
out.push((format!("{high}{low}s"), format!("{high}h {low}h")));
out.push((format!("{high}{low}o"), format!("{high}h {low}d")));
}
}
}
out
}
fn share_of(index: usize, hand: &str) -> f64 {
let hole = Card::parse_list(hand).expect("cards");
let query = Query {
rules: rules(Variant::ShortDeck),
hero: &hole,
board: &[],
villains: &[VillainRange::Any],
trials: TRIALS,
};
estimate(&query, Rng::seeded(1_000 + index as u64)).expect("estimate").0.share
}
#[test]
#[ignore = "offline generator: prints the ranking table"]
fn print_the_ranking() {
let classes = classes();
assert_eq!(classes.len(), 81);
let mut scored: Vec<(String, f64)> = std::thread::scope(|scope| {
let handles: Vec<_> = classes
.iter()
.enumerate()
.map(|(i, (name, hand))| scope.spawn(move || (name.clone(), share_of(i, hand))))
.collect();
handles.into_iter().filter_map(|h| h.join().ok()).collect()
});
scored.sort_by(|a, b| b.1.total_cmp(&a.1).then_with(|| a.0.cmp(&b.0)));
scored.iter().for_each(|(name, share)| println!("RANK {name} {share:.5}"));
}