use super::preflop_role::PreflopRole; use super::profile::Profile; use super::range_guess::DEFAULT_VPIP; /// A regular preflop raise frequency (six-max). pub const DEFAULT_PFR: f64 = 0.18; const MIN_STRETCH: f64 = 0.5; const MAX_STRETCH: f64 = 1.8; fn frequency(x: Option) -> Option { x.filter(|v| !v.is_nan()).map(|v| v.clamp(0.0, 1.0)) } /// How much looser (> 1) or tighter (< 1) than the reference player this villain is, for /// the kind of action the role is made of. Clamped to `[0.5, 1.8]`; 1.0 without data. /// /// - raising roles: `pfr / 0.18`; without pfr, `sqrt(vpip / 0.30)` (half-strength vpip) /// - calling, limping and blind roles: `vpip / 0.30` pub fn stretch(role: PreflopRole, profile: Option) -> f64 { stretch_upto(role, profile, MAX_STRETCH) } /// `stretch` with the upper clamp at `max`. The measured blind-vs-blind band (`vorflop_band`) is a share of /// the whole range, not a chart: a calling station (vpip 0.9) defends all of it, three times the pool, so /// that band stretches up to 4. pub fn stretch_upto(role: PreflopRole, profile: Option, max: f64) -> f64 { let profile = profile.unwrap_or_default(); let (vpip, pfr) = (frequency(profile.vpip), frequency(profile.pfr)); let raw = if role.is_raising() { pfr.map(|f| f / DEFAULT_PFR) .or_else(|| vpip.map(|v| (v / DEFAULT_VPIP).sqrt())) } else { vpip.map(|v| v / DEFAULT_VPIP) }; raw.unwrap_or(1.0).clamp(MIN_STRETCH, max.max(MIN_STRETCH)) } /// A band `[lo, hi]` for a player `factor` times as loose as the reference: the upper /// edge moves out by `factor`, the lower edge in by `1 / factor` (looser players raise /// less often with their best hands, so fewer hands are excluded at the top). /// Width is non-decreasing in `factor`. pub fn stretched(lo: f64, hi: f64, factor: f64) -> (f64, f64) { (lo / factor, hi * factor) }