101 lines
4.7 KiB
Rust
101 lines
4.7 KiB
Rust
use super::band_bounds::bounded;
|
|
use super::band_stretch::{stretch, stretched};
|
|
use super::range_guess::{top_fraction, DEFAULT_VPIP};
|
|
use super::range_spec::RangeSpec;
|
|
use super::role_band::role_band;
|
|
use super::role_from_history::role_of;
|
|
use super::street_continuation::continuations;
|
|
use super::style::{classify, station_trust, Style};
|
|
use crate::game::{Spot, Villain};
|
|
use crate::preflop::seat_position::seat_position;
|
|
|
|
/// Confidence weight for how much this villain's read may widen the modeled range: `1.0` for every
|
|
/// non-station and every genuine station (bit-identical to the binary gate), a fraction for a
|
|
/// misclassified aggressive "station" (loose width but postflop-aggressive — the CMA-ES nemesis-2,
|
|
/// aggr 0.41 → 0.16). A wide `vpip` read only widens the modeled betting range as far as the read is
|
|
/// trusted, so a wide-preflop-but-TIGHT-betting opponent is no longer modeled as an over-weak range
|
|
/// the engine then over-calls. See `station_trust` and BEFUND-nemesis-soft-trust.
|
|
fn range_trust(villain: &Villain) -> f64 {
|
|
match villain.profile.as_ref() {
|
|
Some(p) if classify(p) == Style::CallingStation => station_trust(p),
|
|
_ => 1.0,
|
|
}
|
|
}
|
|
|
|
/// Pull a read-driven value `x` toward its blind baseline by trust `c`: full read at `c = 1`, pure
|
|
/// blind at `c = 0`.
|
|
fn toward_blind(blind: f64, x: f64, c: f64) -> f64 {
|
|
blind + c * (x - blind)
|
|
}
|
|
|
|
/// Without a readable preflop role the band is the plain vpip share — trust-blended toward the
|
|
/// default (blind) vpip so a low-trust station does not over-widen the band.
|
|
fn unknown_role_band(villain: &Villain) -> (f64, f64) {
|
|
let vpip = villain
|
|
.profile
|
|
.and_then(|p| p.vpip)
|
|
.filter(|v| !v.is_nan())
|
|
.map_or(DEFAULT_VPIP, |v| v.clamp(0.02, 1.0));
|
|
(0.0, toward_blind(DEFAULT_VPIP, vpip, range_trust(villain)))
|
|
}
|
|
|
|
fn preflop_band(spot: &Spot, villain: &Villain) -> (f64, f64) {
|
|
match role_of(&spot.history, villain.seat) {
|
|
Some(role) => {
|
|
let (lo, hi) = role_band(spot, role, seat_position(spot, villain.seat));
|
|
// The read stretches the band by the villain's looseness; blind stretch is 1.0. Trust
|
|
// scales how far the band is stretched, so a misread station's wide vpip barely widens it.
|
|
let factor = toward_blind(1.0, stretch(role, villain.profile), range_trust(villain));
|
|
stretched(lo, hi, factor)
|
|
}
|
|
None => unknown_role_band(villain),
|
|
}
|
|
}
|
|
|
|
/// Estimated range of `villain`, narrowed by the observed action sequence
|
|
/// (`spot.history`).
|
|
///
|
|
/// - **No record of this seat in the history** (including an empty history): exactly the old
|
|
/// `RangeSpec::top(range_guess::top_fraction(spot, villain))`.
|
|
/// - Otherwise the **preflop band** comes from the villain role (`role_from_history`,
|
|
/// table in `role_band`, position from `seat_position`), stretched by the profile
|
|
/// (`band_stretch`), forced well-formed (`band_bounds`); the **postflop continuations**
|
|
/// from their bets and raises (`street_continuation`).
|
|
///
|
|
/// Output: `0 <= lo`, `hi <= 1`, `hi - lo >= 0.03`, continuations sorted, only for dealt
|
|
/// streets. Never panics, whatever the history looks like.
|
|
pub fn range_spec(spot: &Spot, villain: &Villain) -> RangeSpec {
|
|
if spot.history.iter().any(|r| r.seat == villain.seat) {
|
|
let (raw_lo, raw_hi) = preflop_band(spot, villain);
|
|
let (lo, hi) = bounded(raw_lo, raw_hi);
|
|
RangeSpec { lo, hi, continues: continuations(spot, villain), class_target: shown_tilt(spot, villain) }
|
|
} else {
|
|
RangeSpec::top(top_fraction(spot, villain))
|
|
}
|
|
}
|
|
|
|
/// Messschalter (einmal gelesen) `ZEIGT_KIPP=1`: thin the villain's river range per preflop class toward
|
|
/// what he showed on his river line (`Profile::shown_river`). Off = no tilt, bit-identical.
|
|
pub fn shown_tilt_on() -> bool {
|
|
use std::sync::OnceLock;
|
|
static ON: OnceLock<bool> = OnceLock::new();
|
|
*ON.get_or_init(|| std::env::var("ZEIGT_KIPP").as_deref() == Ok("1"))
|
|
}
|
|
|
|
/// The class target of the villain's range (`RangeSpec::class_target`): on the river, once he acted
|
|
/// there, the shown-hand distribution of his line (aggressive = he bet/raised the river, else passive).
|
|
fn shown_tilt(spot: &Spot, villain: &Villain) -> Option<[f64; super::range_spec::CLASSES]> {
|
|
use crate::game::SeenAction as A;
|
|
if !shown_tilt_on() || spot.street != crate::game::Street::River {
|
|
return None;
|
|
}
|
|
let shown = villain.profile.as_ref()?.shown_river?;
|
|
let mut acted = false;
|
|
let mut aggr = false;
|
|
for r in spot.history.iter().filter(|r| r.seat == villain.seat && r.street == crate::game::Street::River) {
|
|
acted = true;
|
|
aggr |= matches!(r.action, A::Bet | A::Raise | A::AllIn);
|
|
}
|
|
acted.then(|| shown[if aggr { 0 } else { 1 }])
|
|
}
|