D1d: Lesen breit (engine::read_exploit, GEGNER_BREIT aus) + Gedaechtnis-Draht profile.reads

- read_exploit: Reads der blind gespielten Stile (Nit/Reg/Maniac) ueber fuenf schmale Kanaele:
  c C-Bet vs Folder, b Bluff-Veto vs Caller, r River fold->call, w River-Duennwert (nur Equity >= 0,5),
  3 Light-3-Bet; jeder Read in KL-Vertrauensregion um den Blind-Wert, Stationen/Multiway/Turnier bitgleich.
- river_br (aus pausiertem WIP 1033e80 uebernommen): node-locked BR, Worst-Case ueber Belief-Box, KL-Budget;
  dient als r/w. river_subgame: ladder_chance, belief_combos.
- decode_villain: profile.reads {n,k,prior} -> Posterior + Vertrauen; neue Felder flop_aggression,
  fold_to_steal, fold_to_raise. Kein reads = bitgleich.
- Replay 1345 echte Zuege: Lesen aendert 0,67 % -> 0,74 % (breit), 1,04 % mit Gedaechtnis-Reads.
- Arme eingereiht (eintraege_breit.txt): Leiter breit-basis/-alle/-c/-b/-rw/-3, LBR typ/nit/maniac.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 22:42:05 +01:00
co-authored by Claude Opus 5.5
parent 2b50e8300d
commit faa29b3a1b
20 changed files with 1096 additions and 12 deletions
+298
View File
@@ -0,0 +1,298 @@
//! Bounded exploitation of the opponents `read_gate` plays blind (switch `GEGNER_BREIT`, default off).
//!
//! `read_gate` hands the heuristic a read only for calling stations: acting on a nit's, a reg's or a
//! maniac's read through the single-street bluff EV bled on the ladder (nit −50, maniac −148, reg −176
//! bb/100), because the read flowed into EVERY offensive channel at full strength (BEFUND-nit-read-leck:
//! flop check → bluff-RAISE into a nutted continuing range). This module re-opens the read for the
//! other styles, but only through a few narrow channels, each a single, local change to the blind
//! decision that the read can price completely:
//!
//! | letter | channel | change | read |
//! |---|---|---|---|
//! | `c` | c-bet pressure | flop check → small c-bet (hero preflop aggressor, heads-up) | `fold_to_cbet` |
//! | `b` | bluff veto | a pure-bluff bet → check | street fold-to-bet |
//! | `r` | bluff-catch | river fold → call facing a bet | river gearbox (aggression / shown bluffs) |
//! | `w` | thin value | river check → bet with a made hand | river gearbox |
//! | `3` | light 3-bet | preflop call / top fold → 3-bet vs the lone opener | `fold_to_three_bet` |
//!
//! Every read passes the same trust region before it is used (`bounded`): it is pulled toward the
//! blind default by its confidence, then capped so the Bernoulli KL divergence from the blind default
//! stays within `KL_PER_CONFIDENCE · confidence` nats. A thin read is the blind default; a strong
//! read moves the parameter, never past the KL ball. The river channels'
//! check is the node-locked best response of `river_br` (taken over from the paused WIP branch
//! `worktree-agent-a3f0fb40e48710d66`): worst-case gain over a belief box, KL-capped deviation weight.
//!
//! Untouched: calling stations (already exploited by the heuristic, bit-identical), multiway pots,
//! tournament spots (the caller applies this only with no ICM premium), and every decision the switch
//! does not name. `GEGNER_BREIT=1` turns on all channels; otherwise its value lists the letters.
use super::bluff::is_bluff_hand;
use super::read_gate::exploit_worthy;
use super::river_br;
use crate::exploit::fold_chance::DEFAULT_FOLD_TO_BET;
use crate::exploit::profile::Profile;
use crate::exploit::sample::FOLD_TO_THREE_BET_ANCHOR;
use crate::exploit::style::classify;
use crate::game::{line, ActionKind, Choice, Decision, Spot, Street, Villain};
use crate::read::hand_read::HandRead;
use crate::read::tier::{tier, Tier};
use crate::sizing::candidates::candidates;
/// Below this confidence a read is not used at all (as the river gearbox's `CONFIDENCE_FLOOR`).
pub const CONFIDENCE_FLOOR: f64 = 0.25;
/// Trust-region radius per unit of confidence, in nats of Bernoulli KL from the blind default.
pub const KL_PER_CONFIDENCE: f64 = 0.15;
/// C-bet pressure: bet size as a pot fraction (small: cheap to be wrong, the folder folds anyway).
pub const CBET_FRACTION: f64 = 0.33;
/// C-bet pressure: the bet must beat checking by this share of the pot.
pub const CBET_EDGE: f64 = 0.05;
/// Thin value (`w`): least equity vs the range for the river check -> bet.
pub const THIN_VALUE_EQUITY: f64 = 0.5;
/// C-bet pressure: the trust-bounded fold-to-c-bet must exceed the blind default by this much.
pub const CBET_READ_LIFT: f64 = 0.15;
/// C-bet pressure: only hands up to this equity (strong hands keep the heuristic's own line).
pub const CBET_MAX_EQUITY: f64 = 0.5;
/// Equity a called c-bet keeps relative to the hand's equity against the full range.
pub const CALLED_EQUITY_SHARE: f64 = 0.8;
/// The channels the switch turns on.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Channels {
pub cbet: bool,
pub bluff_veto: bool,
pub bluff_catch: bool,
pub thin_value: bool,
pub light_three_bet: bool,
}
impl Channels {
pub fn parse(value: &str) -> Channels {
let v = value.trim();
if v == "1" || v.eq_ignore_ascii_case("alle") {
return Channels { cbet: true, bluff_veto: true, bluff_catch: true, thin_value: true, light_three_bet: true };
}
Channels {
cbet: v.contains('c'),
bluff_veto: v.contains('b'),
bluff_catch: v.contains('r'),
thin_value: v.contains('w'),
light_three_bet: v.contains('3'),
}
}
}
/// The channels from `GEGNER_BREIT` (read once).
pub fn channels() -> Channels {
static ON: std::sync::OnceLock<Channels> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var("GEGNER_BREIT").map(|v| Channels::parse(&v)).unwrap_or_default())
}
/// Bernoulli KL divergence `KL(p ‖ q)` in nats.
pub fn kl(p: f64, q: f64) -> f64 {
let p = p.clamp(1e-9, 1.0 - 1e-9);
let q = q.clamp(1e-9, 1.0 - 1e-9);
p * (p / q).ln() + (1.0 - p) * ((1.0 - p) / (1.0 - q)).ln()
}
/// The trust region: `read` pulled toward `anchor` by `confidence`, then capped at KL radius
/// `KL_PER_CONFIDENCE · confidence` from `anchor`. Below `CONFIDENCE_FLOOR` (or a non-finite input)
/// the anchor itself.
pub fn bounded(read: f64, anchor: f64, confidence: f64) -> f64 {
if !(read.is_finite() && anchor.is_finite() && confidence.is_finite()) || confidence < CONFIDENCE_FLOOR {
return anchor;
}
let c = confidence.min(1.0);
let target = anchor + c * (read.clamp(0.0, 1.0) - anchor);
let radius = KL_PER_CONFIDENCE * c;
if kl(target, anchor) <= radius {
return target;
}
let (mut lo, mut hi) = (0.0f64, 1.0f64);
for _ in 0..50 {
let mid = 0.5 * (lo + hi);
if kl(anchor + mid * (target - anchor), anchor) <= radius {
lo = mid;
} else {
hi = mid;
}
}
anchor + lo * (target - anchor)
}
/// The lone live villain whose read the gate drops (a non-station with a profile), else `None`.
fn blind_read_villain(spot: &Spot) -> Option<(&Villain, Profile)> {
let mut live = spot.live_villains();
let (Some(v), None) = (live.next(), live.next()) else { return None };
let p = v.profile?;
if exploit_worthy(classify(&p)) {
return None; // the heuristic already exploits it; leave it bit-identical
}
Some((v, p))
}
fn confidence(p: &Profile) -> f64 {
p.confidence.filter(|c| c.is_finite()).unwrap_or(0.0)
}
fn finite(x: Option<f64>) -> Option<f64> {
x.filter(|v| v.is_finite())
}
/// The legal bet nearest `fraction · pot` (a total street amount), if any.
fn bet_near(spot: &Spot, fraction: f64) -> Option<f64> {
let target = fraction * spot.pot;
candidates(spot)
.into_iter()
.filter(|to| *to > 0.0 && *to <= spot.hero_stack)
.min_by(|a, b| (a - target).abs().total_cmp(&(b - target).abs()))
}
fn street_index(street: Street) -> Option<usize> {
match street {
Street::Flop => Some(0),
Street::Turn => Some(1),
Street::River => Some(2),
Street::Preflop => None,
}
}
fn tagged(base: Decision, choice: Choice, tag: &str, why: String) -> Decision {
Decision { choice, reason: format!("breit:{tag}: {why} | {}", base.reason), ..base }
}
/// Postflop: apply the switched-on channels to the heuristic's final decision (`base`, after floor and
/// veto) on the RAW (ungated) spot. Returns `base` unchanged whenever no channel fires.
pub fn postflop(raw: &Spot, hand: &HandRead, base: Decision) -> Decision {
postflop_with(channels(), raw, hand, base)
}
pub fn postflop_with(ch: Channels, raw: &Spot, hand: &HandRead, base: Decision) -> Decision {
if ch == Channels::default() || raw.street == Street::Preflop {
return base;
}
let Some((_, p)) = blind_read_villain(raw) else { return base };
let conf = confidence(&p);
let equity = base.equity.unwrap_or(0.5);
let can_bet = raw.to_call == 0.0 && raw.is_legal(ActionKind::Raise);
// c: c-bet pressure against a folder.
if ch.cbet && base.choice == Choice::Check && can_bet && line::cbet_spot(&raw.history, raw.hero_seat, raw.street) {
if let (Some(read), Some(b)) = (finite(p.fold_to_cbet), bet_near(raw, CBET_FRACTION)) {
let anchor = finite(p.fold_to_bet).unwrap_or(DEFAULT_FOLD_TO_BET).min(DEFAULT_FOLD_TO_BET);
let f = bounded(read, anchor, conf);
let pot = raw.pot;
let called = CALLED_EQUITY_SHARE * equity;
let gain_at = |f: f64| f * pot + (1.0 - f) * (called * (pot + 2.0 * b) - b) - equity * pot;
let gain = gain_at(f);
// The heuristic checked blind for its own (multi-street) reasons, although this one-street
// sum already pays at the blind default; so the read must lift the fold rate clearly
// (`CBET_READ_LIFT` after the trust region) and the bet must gain over that default too.
let lift = gain - gain_at(anchor);
if equity <= CBET_MAX_EQUITY && f >= anchor + CBET_READ_LIFT && gain >= CBET_EDGE * pot && lift > 0.0 {
let why = format!("fold to c-bet {read:.2} -> {f:.2} (conf {conf:.2}), +{:.2} pot", gain / pot);
return tagged(base, Choice::Raise { to: b }, "c", why);
}
}
}
// b: no pure bluff into a caller.
if ch.bluff_veto && raw.to_call == 0.0 && is_bluff_hand(hand, raw) && raw.is_legal(ActionKind::Check) {
if let Choice::Raise { to } = base.choice {
let i = street_index(raw.street);
let read = if line::cbet_spot(&raw.history, raw.hero_seat, raw.street) {
finite(p.fold_to_cbet)
} else {
None
}
.or_else(|| i.and_then(|i| finite(p.street_fold_to_bet[i])))
.or(finite(p.fold_to_bet));
if let Some(read) = read {
let f = bounded(read, DEFAULT_FOLD_TO_BET, conf);
let ev_at = |f: f64| f * raw.pot - (1.0 - f) * to;
let ev = ev_at(f);
// Only where the read flips the blind verdict (the blind fold rate pays the bluff).
if ev < 0.0 && ev_at(DEFAULT_FOLD_TO_BET) >= 0.0 {
let why = format!("fold {read:.2} -> {f:.2} (conf {conf:.2}), bluff EV {:.2} pot", ev / raw.pot);
return tagged(base, Choice::Check, "b", why);
}
}
}
}
// r / w: the node-locked river best response (`engine::river_br`, worst case over a belief box
// around the read, deviation weight capped by a KL budget in the confidence), anchored at the
// heuristic's own decision. Only its promote pieces: fold -> call, check -> bet.
if raw.street == Street::River && (ch.bluff_catch || ch.thin_value) {
let mut mask = 0u8;
if ch.bluff_catch {
mask |= river_br::PIECE_PROMOTE_CALL;
}
// Thin VALUE only: a made hand at least even against the range. Replay 14.11. without this:
// 23 of 111 real river spots, nearly all air/board-only check -> small bet into a high HUD
// fold-to-bet - the nit-leak pattern (a read fold rate turned into bluffs), not value.
let value = tier(hand.made) != Tier::Weak && base.equity.is_some_and(|e| e >= THIN_VALUE_EQUITY);
if ch.thin_value && value {
mask |= river_br::PIECE_VALUE_BET;
}
let before = base.choice;
let refined = river_br::refine_with(raw, base, mask);
if refined.choice != before {
let tag = if refined.choice == Choice::Call { "r" } else { "w" };
let why = refined.reason.clone();
return Decision { reason: format!("breit:{tag}: {why}"), ..refined };
}
return refined;
}
base
}
/// Preflop `3`: the opener's fold-to-3-bet, trust-bounded, for an opener the gate plays blind. `None`
/// when the channel is off, the opener is a station (its gated profile already carries the read) or
/// has no usable read.
pub fn fold_to_three_bet(raw: &Spot, seat: u8) -> Option<f64> {
fold_to_three_bet_with(channels(), raw, seat)
}
pub fn fold_to_three_bet_with(ch: Channels, raw: &Spot, seat: u8) -> Option<f64> {
if !ch.light_three_bet {
return None;
}
let v = raw.villains.iter().find(|v| v.seat == seat && !v.folded)?;
let p = v.profile?;
if exploit_worthy(classify(&p)) {
return None;
}
let read = finite(p.fold_to_three_bet)?;
let conf = confidence(&p);
(conf >= CONFIDENCE_FLOOR).then(|| bounded(read, FOLD_TO_THREE_BET_ANCHOR, conf))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_trust_region_holds_the_kl_ball() {
assert_eq!(bounded(0.9, 0.45, 0.1), 0.45, "below the floor: blind default");
let f = bounded(0.95, 0.45, 0.8);
assert!(f > 0.45 && f < 0.95);
assert!(kl(f, 0.45) <= KL_PER_CONFIDENCE * 0.8 + 1e-9);
// a small move inside the ball is just the confidence pull
let g = bounded(0.50, 0.45, 0.8);
assert!((g - (0.45 + 0.8 * 0.05)).abs() < 1e-12);
// monotone in confidence
assert!(bounded(0.95, 0.45, 0.5) < bounded(0.95, 0.45, 0.9));
assert_eq!(bounded(f64::NAN, 0.45, 0.9), 0.45);
}
#[test]
fn the_switch_names_its_channels() {
assert_eq!(Channels::parse(""), Channels::default());
assert_eq!(Channels::parse("0"), Channels::default());
let all = Channels::parse("1");
assert!(all.cbet && all.bluff_veto && all.bluff_catch && all.thin_value && all.light_three_bet);
let some = Channels::parse("cb");
assert!(some.cbet && some.bluff_veto && !some.bluff_catch && !some.thin_value && !some.light_three_bet);
assert!(Channels::parse("3").light_three_bet);
}
}