Files
pokerfreak/src/exploit/style.rs
T
mmintelandClaude Opus 4.8 b360796d2e Soft-Trust: konfidenz-gewichtetes Stations-Trust schliesst den Nemesis-Rest
Leak 2 war mit dem 0.45-Aggressions-Tor grob gefixt (classify liest den
aggressiven Vielfalter als Regular, nicht Station). Die CMA-ES gegen die
reparierte Engine fand aber nemesis-2 knapp unter dem Tor (aggr 0.41) ->
voll getrustete Station -> -87.63 bb/100.

Wurzel: das binaere earned_trust (1.0/0.0) gibt einem Grenzfall den vollen
Exploit oder gar keinen. read_gate nennt die Loesung selbst - ein f64 fuer
"partial, confidence-weighted trust". station_trust() ist jetzt eine Rampe:
1.0 fuer echte passive Station (bit-identisch zu vorher, keine Regression),
linear auf 0 Richtung 0.45-Grenze.

Vier gemessene Kanaele, die das Stations-Profil lesen, je per toward_blind
mit dem Trust skaliert (bit-identisch bei c=1): adjust (Schwellen), style_rung
(Boden-Sprosse), range_model (Band-Stretch), fold_chance (Fold-Equity, der
dominante). nemesis-2 Memory -87.63 -> +83.72 bb/100 (Blind-Decke +114.01).

Beweis: Zwillings-Tor Gate::passes (OFFENSE +50.58, Boden gto -23.93 und
Exploitability 77.03 bit-identisch), Boden-Archetypen unregressiert,
101 Lib-Tests gruen. Der neue Worst-Case nemesis-3 (-26.59) ist read-invariant
(Oracle=Blind=Memory, classify Regular) - ein vorbestehendes River-Overbet-
Defense-Loch fuer den River-Solver, von diesem Fix unberuehrt.

Befunde: BEFUND-nemesis-soft-trust.md, BEFUND-nemesis-station-fehllabel.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-11 19:58:59 +01:00

196 lines
9.2 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! Classifies an opponent profile into a playing style.
use super::profile::Profile;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Style {
/// No usable numbers at all.
Unknown,
/// Plays very few hands and folds to pressure.
Nit,
/// Plays many hands and raises a lot.
LooseAggressive,
/// Plays many hands passively, or almost never folds to a bet.
CallingStation,
/// Everything in between.
Regular,
}
const LOOSE_VPIP: f64 = 0.35;
const AGGRESSIVE_PFR: f64 = 0.20;
const NIT_VPIP: f64 = 0.15;
const NIT_FOLD_TO_BET: f64 = 0.65;
/// Fold-to-bet claims about a "nit" only count if the player is not clearly loose.
const NIT_MAX_VPIP_WITH_FOLDS: f64 = 0.25;
const STATION_FOLD_TO_BET: f64 = 0.30;
const STATION_MIN_VPIP: f64 = 0.28;
/// A calling station is loose AND postflop-passive. Above this postflop aggression frequency a
/// loose-but-not-raising player is not a station — it only looks loose preflop. Sits between the
/// reg archetype's measured 0.31 and the maniac's ~0.49; the CMA-ES nemesis measures 0.62. See the
/// `an_aggressive_loose_folder_is_not_a_station` regression test and BEFUND-nemesis-station-fehllabel.
const STATION_MAX_AGGRESSION: f64 = 0.45;
/// At or below this postflop aggression a loose-path station is trusted in FULL (`station_trust`
/// 1.0). Between here and `STATION_MAX_AGGRESSION` the station exploit is scaled down linearly — a
/// confidence ramp, not a cliff. Set above the real stations (fish 0.11, oracle 0.02) so they stay
/// bit-identical, and below the reg archetype (0.31) so a misread aggressive "station" (nemesis-2
/// aggr 0.41 → trust 0.16) barely exploits. See `station_trust` and BEFUND-nemesis-soft-trust.
const STATION_FULL_TRUST_AGGRESSION: f64 = 0.20;
/// A frequency in `[0, 1]`; NaN means "not known".
fn frequency(x: Option<f64>) -> Option<f64> {
x.filter(|v| !v.is_nan()).map(|v| v.clamp(0.0, 1.0))
}
/// Thresholds (vpip/pfr/foldToBet/aggression are all clamped to `[0, 1]` first, NaN counts as missing):
/// - all missing: `Unknown`
/// - vpip >= 35 % and pfr >= 20 %: `LooseAggressive`
/// - (vpip >= 35 % AND aggression < 45 % or unknown), or foldToBet <= 30 % with vpip >= 28 % (or
/// unknown): `CallingStation`
/// - vpip <= 15 %, or foldToBet >= 65 % with vpip <= 25 % (or unknown): `Nit`
/// - else `Regular`
///
/// A station is loose AND passive: the `loose` → `CallingStation` path is gated on postflop
/// aggression (`STATION_MAX_AGGRESSION`) so a loose-preflop but aggression-heavy frequent-folder
/// (the CMA-ES nemesis: vpip 0.53, pfr 0.14, foldToBet 0.65, aggression 0.62) reads `Regular` — gated
/// to blind by `read_gate`, the proven-safe baseline — instead of being handed `earned_trust 1.0`
/// and the station exploit it then bled −448 bb/100 to. The `sticky` path (fold ≤ 30 %) is a real
/// non-folder and stays a station regardless of aggression.
pub fn classify(profile: &Profile) -> Style {
let (vpip, pfr, fold, aggr) = (
frequency(profile.vpip),
frequency(profile.pfr),
frequency(profile.fold_to_bet),
frequency(profile.aggression),
);
let loose = vpip.is_some_and(|v| v >= LOOSE_VPIP);
// Postflop-passive: a station does not fire back. Unknown aggression keeps the old behaviour.
let passive = aggr.is_none_or(|a| a < STATION_MAX_AGGRESSION);
let sticky = fold.is_some_and(|b| b <= STATION_FOLD_TO_BET)
&& vpip.is_none_or(|v| v >= STATION_MIN_VPIP);
let tight = vpip.is_some_and(|v| v <= NIT_VPIP)
|| (fold.is_some_and(|b| b >= NIT_FOLD_TO_BET)
&& vpip.is_none_or(|v| v <= NIT_MAX_VPIP_WITH_FOLDS));
if vpip.is_none() && pfr.is_none() && fold.is_none() {
Style::Unknown
} else if loose && pfr.is_some_and(|f| f >= AGGRESSIVE_PFR) {
Style::LooseAggressive
} else if (loose && passive) || sticky {
Style::CallingStation
} else if tight {
Style::Nit
} else {
Style::Regular
}
}
/// How much to trust a `CallingStation` read, in `[0, 1]` — the confidence-weighted generalization
/// of the binary `earned_trust` gate (`engine::read_gate` keeps a station's profile or drops it; this
/// says HOW MUCH of the station exploit to apply to what it keeps). Only meaningful for a profile
/// that already classifies `CallingStation`; the station-exploit channels (`adjust`'s value shift,
/// `style_rung`'s made-floor rung) scale their deviation from blind by this weight.
///
/// A station earns full trust on either signal: it does not fold (sticky, `fold_to_bet` ≤ 30 %) —
/// value-betting it thin is always right — OR it is postflop-passive (low `aggression`). The
/// aggression ramp governs only the loose-WIDTH path, where a high `vpip` alone made the old binary
/// gate hand full trust to aggressive frequent-folders (the CMA-ES nemesis-2, aggr 0.41, folds 56 %)
/// that then bled to the over-call. Unknown aggression keeps the old full trust (no postflop sample
/// to doubt). A genuine station (fish, oracle) returns exactly `1.0` → bit-identical to the old gate.
pub fn station_trust(profile: &Profile) -> f64 {
// A real non-folder is a station on the strongest signal; aggression does not weaken that.
if frequency(profile.fold_to_bet).is_some_and(|b| b <= STATION_FOLD_TO_BET) {
return 1.0;
}
match frequency(profile.aggression) {
None => 1.0,
Some(a) => ((STATION_MAX_AGGRESSION - a)
/ (STATION_MAX_AGGRESSION - STATION_FULL_TRUST_AGGRESSION))
.clamp(0.0, 1.0),
}
}
#[cfg(test)]
mod tests {
use super::*;
fn profile(vpip: f64, pfr: f64, fold: f64, aggr: f64) -> Profile {
Profile {
vpip: Some(vpip),
pfr: Some(pfr),
fold_to_bet: Some(fold),
aggression: Some(aggr),
..Profile::default()
}
}
/// The CMA-ES nemesis read: loose preflop (vpip 0.53) but a hyper-aggressive frequent-folder
/// (aggression 0.62, foldToBet 0.65). Width alone made the old `loose` path label it a station,
/// handing it earned_trust and the station exploit it bled −448 bb/100 to. It must read `Regular`
/// (gated to blind), not `CallingStation`.
#[test]
fn an_aggressive_loose_folder_is_not_a_station() {
let p = profile(0.53, 0.14, 0.65, 0.62);
assert_eq!(classify(&p), Style::Regular);
}
/// A genuinely loose-passive opponent (low aggression) is still a `CallingStation` — the fix
/// gates on aggression, not on preflop width, so the real station is untouched.
#[test]
fn a_loose_passive_opponent_is_still_a_station() {
let p = profile(0.70, 0.05, 0.25, 0.10);
assert_eq!(classify(&p), Style::CallingStation);
}
/// A sticky non-folder (foldToBet ≤ 30 %) stays a station regardless of aggression — not folding
/// is itself the station signal; the aggression gate applies only to the `loose` path.
#[test]
fn a_sticky_non_folder_stays_a_station_even_if_aggressive() {
let p = profile(0.40, 0.10, 0.20, 0.60);
assert_eq!(classify(&p), Style::CallingStation);
}
/// Aggression unknown (not yet measured) keeps the old width-based station read, so nothing
/// regresses for profiles without a postflop sample.
#[test]
fn unknown_aggression_keeps_the_width_based_station() {
let p = Profile { vpip: Some(0.50), pfr: Some(0.10), fold_to_bet: Some(0.45), ..Profile::default() };
assert_eq!(classify(&p), Style::CallingStation);
}
/// A genuine passive station (fish: aggr 0.11) and a non-folder earn FULL trust — the soft gate
/// is bit-identical to the old binary gate for the stations that were always right to exploit.
#[test]
fn a_passive_station_earns_full_trust() {
let fish = profile(0.55, 0.08, 0.40, 0.11); // loose path (folds 40 %), very passive
assert_eq!(station_trust(&fish), 1.0);
let non_folder = profile(0.40, 0.10, 0.20, 0.60); // sticky: never folds → full trust despite aggression
assert_eq!(station_trust(&non_folder), 1.0);
}
/// A misclassified aggressive loose "station" (nemesis-2: loose width, folds 56 %, aggr 0.41)
/// earns only a sliver of trust, so the station exploit barely fires on it.
#[test]
fn a_misread_aggressive_station_earns_little_trust() {
let nemesis2 = profile(0.65, 0.15, 0.56, 0.41);
let c = station_trust(&nemesis2);
assert!(c > 0.0 && c < 0.25, "expected a small trust, got {c}");
}
/// Trust falls monotonically as the loose-path station gets more aggressive, reaching 0 at the
/// classify boundary — a smooth handoff to `Regular` (gated blind), no cliff.
#[test]
fn loose_station_trust_ramps_down_with_aggression() {
let at = |a: f64| station_trust(&profile(0.55, 0.10, 0.50, a));
assert_eq!(at(0.20), 1.0);
assert!((at(0.325) - 0.5).abs() < 1e-9);
assert_eq!(at(0.45), 0.0);
assert!(at(0.25) > at(0.35));
}
/// Unknown aggression keeps full trust: no postflop sample is no reason to doubt the read.
#[test]
fn unknown_aggression_keeps_full_station_trust() {
let p = Profile { vpip: Some(0.50), pfr: Some(0.10), fold_to_bet: Some(0.45), ..Profile::default() };
assert_eq!(station_trust(&p), 1.0);
}
}