Files
pokerfreak/src/cfr/turn.rs
T
mmintelandClaude Opus 4.8 1492fb6a38 Synthetik-Labor: Population, Zwillings-Tor, adaptive Liga, Optimizer, Sim-to-Real
Ersetzt die irrefuehrende Oracle-Leiter durch eine ehrliche Messmethodik
(Oracle aus, Read via Memory/Posterior gegen eine gezogene Gegner-Population).

Stufen:
- 0 Exploitation-Luecke: +18.98 bb/100 gegen die gezogene Population
- 1 Kalibrierung an echte HUD-Daten (lesen/kalibrierung.py)
- 2 Zwillings-Tor (EGTA + Exploitability-Waechter): Offense +43.95,
  Boden gto -36.25 (verliert gegen Balancierte - die Oracle-verdeckte Wurzel)
- 3 Adaptive Liga L0-L3 (reaktiv / modellierend / Liga)
- 4 Sim-to-Real: HUD-Gap (sim::simreal) + Outcome-Abgleich (lesen/liveabgleich.py):
  real -266.75 vs Sim +43.95 => Gap -311; A/B-Pipeline + Runbook fertig,
  nur der geldechte Live-Lauf unter beiden Armen bleibt offen
- 5 Optimizer (Diagonal-CMA-ES, parallel): Nemesis -414.81 bb/100

Befunde und Architektur in docs/notizen/. Lab-Tests gruen
(Rust lib 92/0, python liveabgleich/kalibrierung/gegnersignal gruen).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-11 09:57:32 +01:00

176 lines
8.6 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.
//! Two-street (turn → river) best-response barrel value over abstract strength buckets.
//!
//! The single-street `engine::bluff::branches` values a bet as `P(fold)·pot + (1−P(fold))·
//! (called_share·final_pot − to)`, and the engine draws `P(fold)` from the villain's *global*
//! profile stat (`exploit::table_fold`, a HUD fold-to-bet). That is the over-barrel leak
//! (BEFUND-nit-read-leck): after the villain has already called a bet, the range that reaches the
//! next street is the strong, *continuing* subset — it folds far less than the global rate. Booking
//! the global fold equity on the river bluff books phantom profit; the narrowed range calls and the
//! barrel bleeds.
//!
//! The fix is to condition the fold equity on *reaching* the street: the river fold probability is
//! what the **narrowed** range actually folds (minimum-defence against the price), not the global
//! stat. Against that, a double-barrel with air is −EV, so best-response checks instead. This module
//! computes that conditioned value and demonstrates the leak as a test.
//!
//! Buckets are abstract strength ranks (higher = stronger) with a monotone showdown. Strength is
//! **static** across the river card in this v1 (no draws completing / board reshuffle); real board
//! runouts are a later refinement. The point proven here — conditioned vs global fold equity — does
//! not depend on reshuffle, because the leak is range *selection*, not the card.
/// A villain range as strength-bucket weights (mass still in play); index 0 = weakest.
pub type Range = Vec<f64>;
/// Total probability mass of a range.
fn mass(r: &[f64]) -> f64 {
r.iter().sum()
}
/// Hero's showdown share against `r`: mass strictly weaker than hero, plus half the ties, over the
/// total. Air (low bucket) against a strong range is ~0; the nuts ~1. Empty range splits (0.5).
fn showdown_share(hero: usize, r: &[f64]) -> f64 {
let total = mass(r);
if total <= 0.0 {
return 0.5;
}
let below: f64 = r.iter().take(hero).sum();
let tie = r.get(hero).copied().unwrap_or(0.0);
(below + 0.5 * tie) / total
}
/// Minimum-defence continue fraction against a bet of `bet` into `pot`: GTO defends `pot/(pot+bet)`
/// of the range (folds `alpha = bet/(pot+bet)`). `lean` scales it — a calling station over-defends
/// (`lean > 1`), a nit over-folds (`lean < 1`); `lean = 1` is the GTO defender. Clamped to [0, 1].
pub fn continue_fraction(bet: f64, pot: f64, lean: f64) -> f64 {
if bet <= 0.0 || pot < 0.0 {
return 1.0;
}
(lean * pot / (pot + bet)).clamp(0.0, 1.0)
}
/// The range that continues against the bet: the villain keeps its strongest hands up to
/// `continue_fraction` of its mass and folds the weak tail. Returns the narrowed weights (same
/// length), so a later street sees only the hands that actually called.
pub fn narrowed(r: &[f64], bet: f64, pot: f64, lean: f64) -> Range {
let keep = continue_fraction(bet, pot, lean) * mass(r);
let mut out = vec![0.0; r.len()];
let mut budget = keep;
// Fill from the strong end down; the last bucket may be partially kept.
for i in (0..r.len()).rev() {
if budget <= 0.0 {
break;
}
let take = r[i].min(budget);
out[i] = take;
budget -= take;
}
out
}
/// Hero's expected chips from the pot if the river checks through to showdown: `share · pot`.
fn check_value(hero: usize, r: &[f64], pot: f64) -> f64 {
showdown_share(hero, r) * pot
}
/// Hero's expected chips from betting `bet` into pot `pot` on the river, **given** the villain folds
/// with probability `fold_prob` and, when called, holds the narrowed continuing range. Matches the
/// `branches` convention: `fold_prob·pot + (1−fold_prob)·(share·final − bet)`, final pot = `pot+2bet`.
///
/// Pass `fold_prob` = the conditioned fold (`1 − continue_fraction` of the *current* range) for the
/// true value; pass a global stat to see the booked (phantom) value the single-street heuristic uses.
pub fn river_bet_value(hero: usize, r: &[f64], pot: f64, bet: f64, fold_prob: f64, lean: f64) -> f64 {
let called = narrowed(r, bet, pot, lean);
let share = showdown_share(hero, &called);
fold_prob * pot + (1.0 - fold_prob) * (share * (pot + 2.0 * bet) - bet)
}
/// Best-response river value for hero: the better of checking and a correctly-priced bet, where the
/// bet's fold equity is **conditioned** on the range that reached the river (minimum defence), not a
/// global stat. This is the value the two-street turn decision should see in its called branch.
pub fn river_best_response(hero: usize, r: &[f64], pot: f64, bet: f64, lean: f64) -> f64 {
let check = check_value(hero, r, pot);
let true_fold = 1.0 - continue_fraction(bet, pot, lean);
let bet_ev = river_bet_value(hero, r, pot, bet, true_fold, lean);
check.max(bet_ev)
}
/// Best-response value of barrelling the turn (vs folding now), river best-responded: the villain
/// folds the turn at the conditioned rate; when called, the pot grows and hero best-responds on the
/// river against the narrowed range (so an air hand checks rather than booking phantom fold equity).
pub fn turn_barrel_value(hero: usize, r: &[f64], pot: f64, turn_bet: f64, river_bet: f64, lean: f64) -> f64 {
let fold = 1.0 - continue_fraction(turn_bet, pot, lean);
let called_range = narrowed(r, turn_bet, pot, lean);
let pot_river = pot + 2.0 * turn_bet;
let river = river_best_response(hero, &called_range, pot_river, river_bet, lean);
fold * pot + (1.0 - fold) * (river - turn_bet)
}
#[cfg(test)]
mod tests {
use super::*;
/// A villain range that is uniform over 10 buckets before any betting.
fn uniform(buckets: usize) -> Range {
vec![1.0 / buckets as f64; buckets]
}
/// Conditioned fold equity fixes the over-barrel: hero holds air (bucket 0); after a turn-sized
/// river bet the continuing range is strong and folds little, so best-response CHECKS — the river
/// bet is −EV against the hands that got there.
#[test]
fn best_response_checks_air_on_the_river() {
let r = uniform(10);
let pot = 6.0; // a pot already swollen by earlier streets
let bet = 4.0; // two-thirds pot
let lean = 1.0; // GTO defender
let check = check_value(0, &r, pot);
let true_fold = 1.0 - continue_fraction(bet, pot, lean);
let bet_ev = river_bet_value(0, &r, pot, bet, true_fold, lean);
assert!(bet_ev < check, "air river bet {bet_ev:.3} must be worse than checking {check:.3}");
// Best-response takes the check.
assert!((river_best_response(0, &r, pot, bet, lean) - check).abs() < 1e-9);
}
/// The leak, reproduced: with the GLOBAL fold stat (a nit's 0.82) the river bluff BOOKS a profit
/// above checking, so the single-street heuristic barrels — but the REALIZED value, using the
/// true conditioned fold of the narrowed range, is below checking. Booked > check > realized.
#[test]
fn global_fold_stat_books_phantom_barrel_profit() {
let r = uniform(10);
let pot = 6.0;
let bet = 4.0;
let lean = 1.0;
let global_fold = 0.82; // the nit's unconditional fold-to-bet (BEFUND-nit-read-leck)
let check = check_value(0, &r, pot);
let booked = river_bet_value(0, &r, pot, bet, global_fold, lean);
let realized = river_bet_value(0, &r, pot, bet, 1.0 - continue_fraction(bet, pot, lean), lean);
assert!(booked > check, "the global stat must book a barrel (booked {booked:.3} > check {check:.3})");
assert!(realized < check, "but the realized barrel loses (realized {realized:.3} < check {check:.3})");
}
/// A value hand does the opposite: the nuts (top bucket) best-responds by betting, because the
/// narrowed calling range still pays off.
#[test]
fn best_response_value_bets_the_nuts() {
let r = uniform(10);
let pot = 6.0;
let bet = 4.0;
let lean = 1.2; // a slightly loose caller, so value gets paid
let check = check_value(9, &r, pot);
let br = river_best_response(9, &r, pot, bet, lean);
assert!(br > check + 1e-9, "the nuts should bet for value: br {br:.3} > check {check:.3}");
}
/// Narrowing keeps the strong end and conserves the kept mass.
#[test]
fn narrowing_keeps_the_strong_tail() {
let r = uniform(10);
let pot = 4.0;
let bet = 4.0; // alpha = 1/2, GTO defends half
let n = narrowed(&r, bet, pot, 1.0);
assert!((mass(&n) - 0.5).abs() < 1e-9, "half the mass continues, got {:.3}", mass(&n));
assert_eq!(n[0], 0.0, "the weakest bucket folds");
assert!(n[9] > 0.0, "the strongest bucket continues");
}
}