Hand percentiles (169-class equity ranking, Omaha-5 structural score with empirical CDF), position/situation inference, position x situation charts, all-in-or-fold charts, pot-odds all-in calls, advise(); exploit style classification, threshold adjustment and villain range guess. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
3.2 KiB
Rust
107 lines
3.2 KiB
Rust
use pokerfreak::card::Card;
|
|
use pokerfreak::preflop::hand_percentile::percentile;
|
|
use pokerfreak::preflop::plo5_score::score;
|
|
use pokerfreak::variant::Variant;
|
|
|
|
fn hand(text: &str) -> Vec<Card> {
|
|
Card::parse_list(text).expect("valid cards")
|
|
}
|
|
|
|
fn pct(text: &str) -> f64 {
|
|
percentile(Variant::Plo5, &hand(text))
|
|
}
|
|
|
|
/// Deterministic pseudo-random 5-card hands (LCG), independent of the crate's Rng.
|
|
fn sample_hands(count: usize) -> Vec<Vec<Card>> {
|
|
let mut state: u64 = 0x2545_F491_4F6C_DD1D;
|
|
let mut next = move || {
|
|
state = state
|
|
.wrapping_mul(6364136223846793005)
|
|
.wrapping_add(1442695040888963407);
|
|
(state >> 33) as u8
|
|
};
|
|
(0..count)
|
|
.map(|_| {
|
|
let mut picked: Vec<u8> = Vec::new();
|
|
while picked.len() < 5 {
|
|
let c = next() % 52;
|
|
if !picked.contains(&c) {
|
|
picked.push(c);
|
|
}
|
|
}
|
|
picked.into_iter().filter_map(Card::from_index).collect()
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
#[test]
|
|
fn double_suited_big_pairs_beat_rainbow_junk() {
|
|
let strong = pct("Ah Ad Kh Kd Jc");
|
|
let junk = pct("2c 7d 4h 9s 3c");
|
|
assert!(strong < 0.05, "strong {strong}");
|
|
assert!(junk > 0.8, "junk {junk}");
|
|
assert!(strong < junk);
|
|
}
|
|
|
|
#[test]
|
|
fn double_suited_beats_single_suited_with_same_ranks() {
|
|
assert!(pct("Ah Kh Qd Jd Tc") < pct("Ah Kd Qc Js Ts"));
|
|
}
|
|
|
|
#[test]
|
|
fn trips_and_quads_are_penalised() {
|
|
assert!(pct("Ah Ad Kh Kd Qc") < pct("Ah Ad Ac Kh Qd"));
|
|
assert!(pct("Ah Ad Ac Kh Qd") < pct("Ah Ad Ac As Kd"));
|
|
}
|
|
|
|
#[test]
|
|
fn connected_rundowns_beat_scattered_cards_of_same_top() {
|
|
assert!(pct("Jh Td 9c 8s 2h") < pct("Jh 8d 5c 3s 2h"));
|
|
}
|
|
|
|
#[test]
|
|
fn bigger_pairs_beat_smaller_pairs() {
|
|
assert!(pct("Ah Ad Kc Qs Jh") < pct("7h 7d Kc Qs Jh"));
|
|
}
|
|
|
|
#[test]
|
|
fn suit_permutation_does_not_change_the_value() {
|
|
assert_eq!(pct("Ah Ad Kh Kd Jc"), pct("As Ac Ks Kc Jd"));
|
|
assert_eq!(pct("Ah Ad Kh Kd Jc"), pct("Jc Kd Kh Ad Ah"));
|
|
}
|
|
|
|
#[test]
|
|
fn percentile_is_monotone_in_score() {
|
|
let hands = sample_hands(1500);
|
|
for a in &hands {
|
|
for b in hands.iter().take(40) {
|
|
let (sa, sb) = (score(a).expect("score"), score(b).expect("score"));
|
|
let (pa, pb) = (percentile(Variant::Plo5, a), percentile(Variant::Plo5, b));
|
|
if sa > sb {
|
|
assert!(pa <= pb);
|
|
}
|
|
if sa == sb {
|
|
assert_eq!(pa, pb);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn random_hands_spread_evenly_over_the_unit_interval() {
|
|
let hands = sample_hands(20_000);
|
|
let values: Vec<f64> = hands.iter().map(|h| percentile(Variant::Plo5, h)).collect();
|
|
assert!(values.iter().all(|p| (0.0..=1.0).contains(p)));
|
|
let mean = values.iter().sum::<f64>() / values.len() as f64;
|
|
assert!((mean - 0.5).abs() < 0.02, "mean {mean}");
|
|
let top_decile = values.iter().filter(|p| **p < 0.1).count() as f64 / values.len() as f64;
|
|
assert!((top_decile - 0.1).abs() < 0.03, "top decile {top_decile}");
|
|
}
|
|
|
|
#[test]
|
|
fn score_rejects_wrong_card_counts() {
|
|
assert_eq!(score(&hand("Ah Kd")), None);
|
|
assert_eq!(score(&hand("Ah Kd Qc Js Th 9h")), None);
|
|
assert_eq!(score(&hand("Ah Ah Qc Js Th")), None);
|
|
}
|