Files
pokerfreak/tests/range_model_profile.rs
T
mmintelandClaude Opus 5.5 9a9c6c946d Range narrowing from action history, position from inferred button
Wire: optional history decoding. exploit::range_model: role band + postflop
continuations. preflop::button / seat_position: button inference from blinds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 12:41:03 +01:00

119 lines
4.0 KiB
Rust

mod range_model_fixture;
use pokerfreak::exploit::profile::Profile;
use pokerfreak::game::SeenAction::{Bet, Call, Raise};
use pokerfreak::game::Street;
use range_model_fixture::*;
fn preflop_width(history: Vec<pokerfreak::game::ActionRecord>, seat: u8, p: Option<Profile>) -> f64 {
let s = spot(0, hand(history), p);
let r = spec(&s, seat);
assert!(well_formed(&r, 0), "{r:?}");
width(&r)
}
const LOOSE_TO_TIGHT_VPIP: [f64; 6] = [0.9, 0.6, 0.45, 0.30, 0.18, 0.06];
#[test]
fn looser_vpip_widens_a_calling_band() {
let widths: Vec<f64> = LOOSE_TO_TIGHT_VPIP
.iter()
.map(|v| preflop_width(vec![pre(MIDDLE, Raise), pre(BUTTON, Call)], BUTTON, vpip(*v)))
.collect();
assert!(widths.windows(2).all(|w| w[0] >= w[1]), "{widths:?}");
assert!(widths[0] > widths[5] + 0.05, "{widths:?}");
}
#[test]
fn looser_vpip_widens_a_limping_band() {
let widths: Vec<f64> = LOOSE_TO_TIGHT_VPIP
.iter()
.map(|v| preflop_width(vec![pre(CUTOFF, Call)], CUTOFF, vpip(*v)))
.collect();
assert!(widths.windows(2).all(|w| w[0] >= w[1]), "{widths:?}");
assert!(widths[0] > widths[5], "{widths:?}");
}
#[test]
fn higher_pfr_widens_an_opening_band() {
let widths: Vec<f64> = [0.40, 0.28, 0.18, 0.10, 0.04]
.iter()
.map(|f| {
preflop_width(vec![pre(CUTOFF, Raise)], CUTOFF, profile(Some(0.3), Some(*f), None))
})
.collect();
assert!(widths.windows(2).all(|w| w[0] >= w[1]), "{widths:?}");
assert!(widths[0] > widths[4], "{widths:?}");
}
#[test]
fn opening_without_pfr_falls_back_on_vpip_at_half_strength() {
let wide = preflop_width(vec![pre(BUTTON, Raise)], BUTTON, vpip(0.6));
let none = preflop_width(vec![pre(BUTTON, Raise)], BUTTON, None);
let tight = preflop_width(vec![pre(BUTTON, Raise)], BUTTON, vpip(0.1));
assert!(wide > none && none > tight);
}
#[test]
fn a_profile_without_numbers_is_neutral() {
for (seat, history) in [
(CUTOFF, vec![pre(CUTOFF, Raise)]),
(BUTTON, vec![pre(MIDDLE, Raise), pre(BUTTON, Call)]),
] {
let plain = preflop_width(history.clone(), seat, None);
let empty = preflop_width(history.clone(), seat, profile(None, None, None));
let nan = preflop_width(history, seat, profile(Some(f64::NAN), Some(f64::NAN), Some(f64::NAN)));
assert_eq!(plain, empty);
assert_eq!(plain, nan);
}
}
#[test]
fn extreme_numbers_stay_well_formed() {
for v in [-3.0, 0.0, 1.0, 7.5, f64::INFINITY, f64::NEG_INFINITY] {
for (seat, history) in [
(CUTOFF, vec![pre(CUTOFF, Raise)]),
(BUTTON, vec![pre(MIDDLE, Raise), pre(BUTTON, Call)]),
(BUTTON, vec![pre(MIDDLE, Raise), pre(BUTTON, Raise), pre(MIDDLE, Raise)]),
] {
preflop_width(history, seat, profile(Some(v), Some(v), Some(v)));
}
}
}
fn flop_bet_min(p: Option<Profile>) -> pokerfreak::read::made::Made {
let history = hand(vec![
pre(CUTOFF, Raise),
post(Street::Flop, CUTOFF, Bet),
]);
let s = spot(3, history, p);
continuation(&spec(&s, CUTOFF), 3).expect("bet continuation").min_made
}
#[test]
fn looser_player_never_gets_a_higher_min_made() {
let mins: Vec<_> = LOOSE_TO_TIGHT_VPIP.iter().map(|v| flop_bet_min(vpip(*v))).collect();
assert!(mins.windows(2).all(|w| w[0] <= w[1]), "{mins:?}");
assert!(mins[0] < mins[5], "{mins:?}");
}
#[test]
fn calling_station_loosens_and_nit_tightens_the_postflop_floor() {
let regular = flop_bet_min(profile(Some(0.25), Some(0.15), Some(0.5)));
let station = flop_bet_min(profile(Some(0.45), Some(0.08), Some(0.2)));
let nit = flop_bet_min(profile(Some(0.10), Some(0.08), Some(0.7)));
assert!(station < regular && regular < nit, "{station:?} {regular:?} {nit:?}");
}
#[test]
fn low_fold_to_bet_alone_loosens() {
let sticky = flop_bet_min(profile(None, None, Some(0.1)));
let plain = flop_bet_min(None);
assert!(sticky < plain);
}
#[test]
fn no_profile_matches_the_regular_floor() {
assert_eq!(flop_bet_min(None), flop_bet_min(profile(Some(0.25), Some(0.15), Some(0.5))));
}