use super::fold_equity_scale::{MAX_SCALE, MIN_SCALE}; use super::profile::Profile; use super::style::{classify, station_trust, Style}; use super::style_shift::shift_for; use super::thresholds::Thresholds; /// Output ranges: whatever the inputs, the engine never sees thresholds outside these. const CALL_MARGIN: (f64, f64) = (0.0, 0.15); const VALUE_RAISE: (f64, f64) = (0.52, 0.85); const ABSTAIN_BAND: (f64, f64) = (0.0, 0.05); const RANGE_WIDTH: (f64, f64) = (0.6, 1.4); fn bounded(x: f64, (low, high): (f64, f64)) -> f64 { if x.is_nan() { low } else { x.clamp(low, high) } } /// `base` as seen against one profile; `None` when the profile says nothing. /// /// A `CallingStation` shift is scaled by `station_trust`: a misclassified aggressive "station" /// (loose width but postflop-aggressive — nemesis-2) gets a fraction of the value-bet-thinner shift, /// not all of it. Every other style, and a genuine station (trust 1.0), is bit-identical to before. fn against(base: Thresholds, profile: &Profile) -> Option { let style = classify(profile); let c = if style == Style::CallingStation { station_trust(profile) } else { 1.0 }; shift_for(style).map(|shift| Thresholds { call_margin: bounded(base.call_margin + shift.call_margin * c, CALL_MARGIN), value_raise: bounded(base.value_raise + shift.value_raise * c, VALUE_RAISE), abstain_band: bounded(base.abstain_band, ABSTAIN_BAND), fold_equity_scale: base.fold_equity_scale.clamp(MIN_SCALE, MAX_SCALE), range_width_scale: bounded(base.range_width_scale * (1.0 + (shift.range_width - 1.0) * c), RANGE_WIDTH), }) } /// Conservative merge of two opponents: keep the harder-to-continue value of each /// threshold (higher margins, lower fold equity, narrower ranges). fn conservative(a: Thresholds, b: Thresholds) -> Thresholds { Thresholds { call_margin: a.call_margin.max(b.call_margin), value_raise: a.value_raise.max(b.value_raise), abstain_band: a.abstain_band.max(b.abstain_band), fold_equity_scale: a.fold_equity_scale.min(b.fold_equity_scale), range_width_scale: a.range_width_scale.min(b.range_width_scale), } } /// Shift thresholds for the given opponents' profiles. No profiles → `base` unchanged. /// /// Each profile is classified (`style::classify`) and moves `base` by its style /// (`style_shift`). `fold_equity_scale` stays as given: how often each opponent folds is /// estimated per opponent (`fold_chance`), so the profile is not counted here a second time. /// Profiles with no usable numbers are ignored; with several informative ones the /// results are merged conservatively. Outputs are clamped to sane ranges. pub fn adjust(base: Thresholds, profiles: &[Profile]) -> Thresholds { profiles .iter() .filter_map(|p| against(base, p)) .reduce(conservative) .unwrap_or(base) }