Files
pokerfreak/src/engine/read_gate.rs
T

127 lines
7.3 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.
//! "Never worse than blind." Measured on the ladder, the exploit logic only beats solid blind play
//! against opponents whose read it has EARNED. Acting on a read of a competent or aggressive
//! opponent (reg / maniac) makes the engine play WORSE than blind - it bleeds to a heads-up reg
//! (−102 bb/100 with a truthful read). Until a style's read is proven on the ladder (fed by real
//! data), the engine keeps a read ONLY for the earned styles and plays everyone else blind.
//!
//! The gate is a per-style table (`earned_trust`), not a single hard-coded class: each style is
//! turned on only once its `... (blind)` twin in `sim::benchmark` proves the read never costs. This
//! can never make a read harmful: it only ever acts where acting is known to help, and falls back to
//! the solid baseline everywhere else. Same spirit as the price/commitment floor - a read, like a
//! loose table, may never tip us into a worse decision.
use crate::exploit::style::{classify, Style};
use crate::exploit::profile::Profile;
use crate::game::{Spot, Villain};
/// How much of a read's adjustment each opponent style has EARNED on the ladder — the measured right
/// to deviate from blind play. `1.0` = exploit in full, `0.0` = keep playing blind (the read is
/// dropped at the gate). This generalizes the old CallingStation-only gate into a per-style table,
/// so a style is turned on only once its read is proven never worse than blind (the `... (blind)`
/// twins in `sim::benchmark` / `benchmarks/baseline.txt`).
///
/// Only `> 0.0` is consumed today (keep-or-drop at the gate); the shift shapes themselves live in
/// `exploit::style_shift` and apply in full to whatever survives the gate. The value is an `f64`,
/// not a bool, to leave room for a partial, confidence-weighted trust later without changing this
/// seam.
pub fn earned_trust(style: Style) -> f64 {
match style {
// Over-callers (fish, station): value-bet thinner, never bluff. Earned since Stage 0 — the
// `heads-up ... (blind)` twins show a large recaptured prize.
Style::CallingStation => 1.0,
// Measured on the ladder (Stage 3, every non-style run at full trust against the blind
// baseline): acting on a strong-player read only ever COSTS. Heads-up, a truthful read is
// worse than blind by reg −176, maniac −148, nit −50 bb/100 — the nit turns a +38 blind
// winner into a loser. The decision-trace diagnostic (Stage 5, `sim_blind::
// diagnose_nit_full_read_leak`) localized the nit leak: it is not under-barrelling but the
// OPPOSITE — the read turns flop CHECKS into bluff-RAISES (140 hands, −436 of −596 bb total),
// because `table_fold` now sees the nit's true 0.82 fold rate and the single-street bluff-EV
// books `0.82 × pot` as near-pure profit. The 18 % that continue hold a nutted range and
// bleed across turn and river, a multi-street cost the single-street called branch never
// models. The DEFENSIVE adjustments of the same read all GAIN (fold more thin value / bluff
// catchers into a proven non-bluffer) and are already harvested by the ungated MDF floor
// (`mdf_floor::floor` on the raw spot in `engine::decide`); this gate governs only the
// OFFENSIVE adjustments, which over-fire into strong ranges. So every non-over-caller stays
// blind until the bluff-EV models the multi-street cost of a called barrel (BEFUND-nit-read-leck).
// `LESE_VERTRAUEN` (measuring switch, off = bit-identical) opens the gate per style once the
// bluff-EV prices the later streets (`engine::fortsetzung`, `FORTSETZUNG`).
Style::Regular => trusted_by_switch("reg"),
Style::Nit => trusted_by_switch("nit"),
Style::LooseAggressive => trusted_by_switch("lag"),
// No usable read.
Style::Unknown => 0.0,
}
}
/// Messschalter (einmal gelesen): `LESE_VERTRAUEN=nit,reg,lag` (eine beliebige Teilmenge) gibt
/// diesen Stilen volles Vertrauen. Vorgabe: leer (alt, bit-identisch).
fn trusted_by_switch(tag: &str) -> f64 {
use std::sync::OnceLock;
static LIST: OnceLock<Vec<String>> = OnceLock::new();
let list = LIST.get_or_init(|| {
std::env::var("LESE_VERTRAUEN")
.map(|s| s.split(',').map(|t| t.trim().to_ascii_lowercase()).filter(|t| !t.is_empty()).collect())
.unwrap_or_default()
});
if list.iter().any(|t| t == tag) { 1.0 } else { 0.0 }
}
/// A read is acted on only when its style has earned trust on the ladder - the classes the exploit
/// logic is measured to beat blind play against. Every other style falls back to blind.
pub fn exploit_worthy(style: Style) -> bool {
earned_trust(style) > 0.0
}
/// The spot with every opponent read the engine is not (yet) proven to use profitably dropped to
/// `None`, so the decision plays blind against competent and aggressive opponents and only exploits
/// the earned styles.
///
/// `POOL_PRIOR` (off = bit-identical): a villain left blind gets the stake's pool baseline instead
/// (`exploit::pool::baseline`): passive axes only, faded by his own sample, never for an aggressor.
pub fn gate_reads(spot: &Spot) -> Spot {
let pool = crate::exploit::pool::prior_mode()
.and_then(|m| crate::exploit::pool::pool_for(spot.big_blind).map(|p| (p, m)));
let villains = spot
.villains
.iter()
.map(|v| {
let kept = v.profile.and_then(|p| if exploit_worthy(classify(&p)) { Some(p) } else { fold_reads(&p) });
let trusted = v.profile.is_some_and(|p| exploit_worthy(classify(&p)));
let profile = match &pool {
Some((pool, mode)) if kept.is_none() && !trusted => crate::exploit::pool::baseline(pool, v.profile.as_ref(), *mode),
_ => kept,
};
Villain { profile, ..v.clone() }
})
.collect();
Spot { villains, ..spot.clone() }
}
/// Messschalter (einmal gelesen): `ANGRIFF_FOLD=1` laesst von einem nicht verdienten Stil (Regular,
/// Nit, LAG) die Fold-Reads durch - foldToBet (gepoolt und je Strasse) und foldToCbet - als
/// stilloses Profil (`Profile::fold_only`, `classify` = Unknown): kein Stil-Shift, nur die
/// Fold-Wahrscheinlichkeit von Heros Einsaetzen (`exploit::table_fold`). Gegen die Mehrstrassen-Kosten
/// starker Caller (Befund Nit-Leck) spielt der Called-Zweig dann gegen die staerksten 1 - fold der
/// Range (`exploit::call_floor`). Befund 15.11. (`diag_welt DIAG_READ=1`): jeder NL2-Read klassiert
/// Regular und lief im Angriff blind (pool-nl2 Read − blind +1,4 bb/100, C-Bet bitgleich bei jedem
/// Fold-Read). Vorgabe: aus (alt, bit-identisch).
pub fn fold_attack_enabled() -> bool {
use std::sync::OnceLock;
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| std::env::var("ANGRIFF_FOLD").as_deref() == Ok("1"))
}
/// The fold reads of an untrusted profile as a style-less profile, when `ANGRIFF_FOLD` is on and it
/// carries one; otherwise `None` (blind, as before).
fn fold_reads(p: &Profile) -> Option<Profile> {
let any = p.fold_to_bet.is_some() || p.fold_to_cbet.is_some() || p.street_fold_to_bet.iter().any(Option::is_some);
(fold_attack_enabled() && any).then(|| Profile {
fold_to_bet: p.fold_to_bet,
street_fold_to_bet: p.street_fold_to_bet,
fold_to_cbet: p.fold_to_cbet,
confidence: p.confidence,
fold_only: true,
..Profile::default()
})
}