Files
pokerfreak/src/exploit/range_model.rs
T
mmintelandClaude Opus 5.5 cf32fb2c1d Postflop im 3-Bet-Topf: Kandidat DREIBET_TOPF=real=0.15,oop (aus)
Im heads-up 3-Bet-Topf wird ein Flop-/Turn-Call ausser Position mit Stack
dahinter zum Fold, wenn die Equity unter Break-even + 0,15 liegt. Echte
NL2-Spots (Open + 3-Bet, beide Haende offen): Dev +15 746 bb [+8 769,
+23 126], Holdout einmal +15 340 [+7 167, +23 596] (tatsaechlicher
Ausgang). Pflichtfaelle 35/43, Replay 1 anders, LBR bitgleich, 6-max-Leiter
-0,15 +-0,25. MDF-Untergrenze im 3-Bet-Topf schon zu (0 Faelle);
Teil band (3-Bettor nach Paarung) gebaut, gemessen, verworfen. Nicht live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 13:17:42 +01:00

150 lines
6.8 KiB
Rust

use super::band_bounds::bounded;
use super::band_stretch::{stretch, stretch_upto, 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;
/// Upper read stretch of the measured blind-vs-blind band (`band_stretch::stretch_upto`).
const VORFLOP_MAX_STRETCH: f64 = 4.0;
/// 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) => {
// VORFLOP_BAND: Small Blind gegen Big Blind aus gemessenen Frequenzen (exploit::vorflop_band) als
// Pool-Band; der Read streckt es wie das Rollen-Band (eine Station limpt nicht nur die Pool-Hände).
let vpip = villain.profile.and_then(|p| p.vpip);
let gemessen = super::vorflop_band::band(spot, villain.seat, role, vpip);
// DREIBET_TOPF=band: im heads-up 3-Bet-Topf das gemessene NL2-Band je Paarung (aus = None).
let dreibet = gemessen.is_none().then(|| super::dreibet_band::band(spot, villain.seat)).flatten();
let (lo, hi) = gemessen.map_or_else(
|| dreibet.unwrap_or_else(|| role_band(spot, role, seat_position(spot, villain.seat))),
|(b, _)| b,
);
// 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.
// A band from the villain's vpip tier holds the read already.
let roh = match gemessen {
Some((_, true)) => 1.0,
Some((_, false)) => stretch_upto(role, villain.profile, VORFLOP_MAX_STRETCH),
None => stretch(role, villain.profile),
};
let factor = toward_blind(1.0, roh, 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`: 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.
/// `1` both lines either way; `richtung` the aggressive line only stronger, the passive line only
/// weaker (shown hands never argue a checking/calling range stronger = never against a station read);
/// `aggr` / `passiv` one line only (diagnosis).
#[derive(Clone, Copy, PartialEq)]
enum TiltMode {
Off,
Both,
Direction,
AggrOnly,
PassiveOnly,
}
fn tilt_mode() -> TiltMode {
use std::sync::OnceLock;
static MODE: OnceLock<TiltMode> = OnceLock::new();
*MODE.get_or_init(|| match std::env::var("ZEIGT_KIPP").as_deref() {
Ok("1") => TiltMode::Both,
Ok("richtung") => TiltMode::Direction,
Ok("aggr") => TiltMode::AggrOnly,
Ok("passiv") => TiltMode::PassiveOnly,
_ => TiltMode::Off,
})
}
pub fn shown_tilt_on() -> bool {
tilt_mode() != TiltMode::Off
}
/// 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<super::range_spec::ClassTilt> {
use crate::game::SeenAction as A;
let mode = tilt_mode();
if mode == TiltMode::Off || 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);
}
if !acted || (mode == TiltMode::AggrOnly && !aggr) || (mode == TiltMode::PassiveOnly && aggr) {
return None;
}
let dir = match mode {
TiltMode::Direction if aggr => 1,
TiltMode::Direction => -1,
_ => 0,
};
Some(super::range_spec::ClassTilt { target: shown[if aggr { 0 } else { 1 }], dir })
}