Merge Live-Stand b4995f0 (engine-lecks) in gedaechtnis-pokerintel

zaehler: Zaehlung von nemesis3-river (raiseToBet + reraiseToRaise) behalten, Specs gruen.
ReadMode::Hud auch in lerner/Diagnose (dort wie Memory). hud_read traegt raiseToBet/reraiseToRaise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 18:08:25 +01:00
co-authored by Claude Opus 5.5
1441 changed files with 3404216 additions and 990 deletions
+17
View File
@@ -25,5 +25,22 @@ pub fn call_continuation(villain: &Villain, street: Street, ratio: f64, facing_r
min_draw: crate::read::draw::Draw::Gutshot,
bluff_share: 0.0,
continue_share: Some(1.0 - fold_chance(villain.profile.as_ref(), ratio, facing_raise)),
top_share: None,
}
}
/// `call_continuation` against a style-less fold read (`Profile::fold_only`, `ANGRIFF_FOLD`): whoever
/// calls holds the strongest `1 - fold` of the range (Bayes for a caller who continues by strength),
/// not the calling floor topped up with random hands - the multi-street cost of a called bluff into
/// a strong range (Befund Nit-Leck) is priced into the called branch.
pub fn top_call_continuation(villain: &Villain, street: Street, ratio: f64, facing_raise: bool) -> Continuation {
Continuation {
board_len: street.board_len(),
min_made: crate::read::made::Made::Air,
draws_continue: true,
min_draw: crate::read::draw::Draw::None,
bluff_share: 0.0,
continue_share: None,
top_share: Some(1.0 - fold_chance(villain.profile.as_ref(), ratio, facing_raise)),
}
}
+14
View File
@@ -28,6 +28,13 @@ const WEAK_PLAYER: Profile = Profile {
aggression_confidence: None,
river_bluff_share: None,
river_bluff_shown: None,
flop_aggression: None,
fold_to_steal: None,
fold_to_raise: None,
raise_to_bet: None,
reraise_to_raise: None,
size_gain: None,
fold_only: false,
};
fn prior(mark: &str) -> Option<Profile> {
@@ -60,5 +67,12 @@ pub fn with_mark(measured: Option<Profile>, mark: &str) -> Option<Profile> {
aggression_confidence: known.aggression_confidence,
river_bluff_share: known.river_bluff_share,
river_bluff_shown: known.river_bluff_shown,
flop_aggression: known.flop_aggression,
fold_to_steal: known.fold_to_steal,
fold_to_raise: known.fold_to_raise,
raise_to_bet: known.raise_to_bet,
reraise_to_raise: known.reraise_to_raise,
size_gain: known.size_gain,
fold_only: known.fold_only,
})
}
+1
View File
@@ -12,6 +12,7 @@ pub mod fold_equity_scale;
pub mod made_ladder;
pub mod mark;
pub mod mdf_floor;
pub mod pool;
pub mod posterior;
pub mod pot_trace;
pub mod preflop_role;
+264
View File
@@ -0,0 +1,264 @@
//! The stake's player pool as an exploit source (switch `GEGNER_POOL=<d2_priors.json>`, default off).
//!
//! Best practice at micro stakes: against an opponent with few hands, play the POOL of the stake, not a
//! GTO-shaped blind default. The pool is the empirical-Bayes table of `lesen/priors.py`
//! (`messung_gedaechtnis/d2_priors.json`): per stake (`stufen`) and read a Beta prior `mu, kappa`, plus
//! the held-out cross-validation against the core's anchors (`cv_delta_heute = [mean, lo, hi]`, log-loss
//! gain per chance). Only reads that are
//!
//! * **passive axes** (fold rates, `PASSIVE`): the uniform-median prior of `sim::memory` masked the
//! aggressive outliers (maniac −32, `mem-prior-loser`), so aggression, pfr and vpip never come from
//! the pool, and
//! * **proven at that stake**: the CV lower bound beats the anchor (`lo > 0`) with at least
//! `MIN_PLAYERS` players behind it
//!
//! enter. The pool is a read with its own confidence `kappa / (kappa + S)` (S = the core's prior strength
//! for that read); the individual read takes over as its sample grows: the pool replaces the core's
//! anchor inside the individual posterior (`r' = r + (1 − c)(mu − anchor)`), and the combined
//! confidence is `1 − (1 − c)(1 − c_pool)`.
//!
//! **Aggressor guard.** Before the pool applies, a villain whose own sample already reads aggressive
//! (`aggression ≥ AGGRESSOR_AGGRESSION` with `aggression_confidence ≥ AGGRESSOR_CONFIDENCE`, or
//! `pfr ≥ AGGRESSOR_PFR`) keeps only his own reads: a maniac must never be priced as the passive pool.
//!
//! The stake comes from `GEGNER_POOL_STUFE` (forced, for the ladder arms) or from the big blind
//! (0.02 → `NL0.01-0.02`, 0.10 → `NL0.05-0.1`); no stake, no pool (bit-identical).
use crate::exploit::fold_chance::DEFAULT_FOLD_TO_BET;
use crate::exploit::profile::Profile;
use crate::exploit::sample::{FOLD_TO_THREE_BET_ANCHOR, PRIOR_HANDS};
use crate::json::value::Value;
/// Fold-rate reads the pool may supply (wire names of `lesen/zaehler.py`).
pub const PASSIVE: [&str; 7] =
["foldToBet", "foldToCbet", "flopFoldToBet", "turnFoldToBet", "riverFoldToBet", "foldToThreeBet", "foldToSteal"];
/// A stake's read counts only with this many players behind its fit.
pub const MIN_PLAYERS: f64 = 50.0;
/// Aggressor guard: own aggression at least this (the nemesis-fix line, `classify`'s 0.45) ...
pub const AGGRESSOR_AGGRESSION: f64 = 0.45;
/// ... read with at least this aggression confidence,
pub const AGGRESSOR_CONFIDENCE: f64 = 0.25;
/// or a preflop raise rate at least this.
pub const AGGRESSOR_PFR: f64 = 0.30;
/// Prior strength of the per-line reads in the core (`decode_villain` LINE_PRIOR / STREET_PRIOR).
const LINE_STRENGTH: f64 = 15.0;
/// Fold-to-steal prior strength in the core.
const STEAL_STRENGTH: f64 = 30.0;
/// One proven pool read.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct PoolRead {
pub mu: f64,
pub kappa: f64,
}
impl PoolRead {
/// The pool's own confidence against the core's prior strength `s`.
pub fn confidence(&self, s: f64) -> f64 {
self.kappa / (self.kappa + s)
}
}
/// The proven passive reads of one stake.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Pool {
pub stage: String,
pub reads: Vec<(String, PoolRead)>,
}
impl Pool {
pub fn get(&self, name: &str) -> Option<PoolRead> {
self.reads.iter().find(|(n, _)| n == name).map(|(_, r)| *r)
}
}
fn member<'a>(v: &'a Value, key: &str) -> Option<&'a Value> {
match v {
Value::Object(m) => m.iter().find(|(k, _)| k == key).map(|(_, x)| x),
_ => None,
}
}
fn number(v: Option<&Value>) -> Option<f64> {
match v {
Some(Value::Number(x)) if x.is_finite() => Some(*x),
_ => None,
}
}
/// A stake entry's `format`: absent (older tables) or `"cash"`. Tournament and play-money stakes have
/// their own gates and never enter the cash pool.
fn is_cash(format: Option<&Value>) -> bool {
match format {
None => true,
Some(Value::String(f)) => f == "cash",
Some(_) => false,
}
}
/// The proven passive reads of `stage` from a parsed `d2_priors.json` or per-stake pool export.
pub fn from_table(table: &Value, stage: &str) -> Pool {
let mut reads = Vec::new();
if let Some(all) = member(table, "reads") {
for name in PASSIVE {
let Some(s) = member(all, name).and_then(|r| member(r, "stufen")).and_then(|s| member(s, stage)) else {
continue;
};
let (Some(mu), Some(kappa)) = (number(member(s, "mu")), number(member(s, "kappa"))) else { continue };
let players = number(member(s, "spieler")).unwrap_or(0.0);
let lo = match member(s, "cv_delta_heute") {
Some(Value::Array(x)) if x.len() == 3 => number(x.get(1)),
_ => None,
};
// The per-stake export (`archiv/lauf/pool/kandidat.json` / `aktuell.json`) carries its own gate
// `tor` (Holm p < 0.05 over the stake's reads, delta > 0 against the Rust anchors, finite kappa)
// and a `format`; only a cash stake feeds this (cash) pool. Without `tor` (the older
// `d2_priors.json`) the CV lower bound decides as before.
let proven = match member(s, "tor") {
Some(Value::Bool(t)) => *t && is_cash(member(s, "format")),
Some(_) => false,
None => lo.is_some_and(|lo| lo > 0.0),
};
if proven && players >= MIN_PLAYERS && (0.0..=1.0).contains(&mu) && kappa > 0.0 {
reads.push((name.to_string(), PoolRead { mu, kappa }));
}
}
}
Pool { stage: stage.to_string(), reads }
}
/// All stakes' pools from `GEGNER_POOL` (read once); empty when the switch is off or the file unusable.
fn table() -> &'static Option<Value> {
static T: std::sync::OnceLock<Option<Value>> = std::sync::OnceLock::new();
T.get_or_init(|| {
let path = std::env::var("GEGNER_POOL").ok()?;
let text = std::fs::read_to_string(path.trim()).ok()?;
crate::json::parse::parse(&text).ok()
})
}
/// The stake name for a big blind (or the forced `GEGNER_POOL_STUFE`).
pub fn stage_for(big_blind: f64) -> Option<String> {
if let Ok(s) = std::env::var("GEGNER_POOL_STUFE") {
let s = s.trim();
if !s.is_empty() {
return Some(s.to_string());
}
}
let near = |x: f64| (big_blind - x).abs() <= 1e-6;
if near(0.02) {
Some("NL0.01-0.02".into())
} else if near(0.10) || near(0.1) {
Some("NL0.05-0.1".into())
} else {
None
}
}
/// The live pool for this big blind (`None`: switch off, no stake, or nothing proven there).
pub fn pool_for(big_blind: f64) -> Option<Pool> {
let table = table().as_ref()?;
let stage = stage_for(big_blind)?;
let pool = from_table(table, &stage);
(!pool.reads.is_empty()).then_some(pool)
}
/// The aggressor guard: the villain's own sample says aggressive.
pub fn aggressor(p: &Profile) -> bool {
let aggr = p.aggression.filter(|a| a.is_finite());
let aconf = p.aggression_confidence.or(p.confidence).filter(|c| c.is_finite()).unwrap_or(0.0);
aggr.is_some_and(|a| a >= AGGRESSOR_AGGRESSION) && aconf >= AGGRESSOR_CONFIDENCE
|| p.pfr.filter(|x| x.is_finite()).is_some_and(|x| x >= AGGRESSOR_PFR)
}
/// `p` (or no profile) with the pool's proven fold reads blended in; `None` for an aggressor (guard),
/// or when nothing changes. The returned profile's `confidence` is the combined one.
pub fn pooled(pool: &Pool, p: Option<Profile>) -> Option<Profile> {
let base = p.unwrap_or_default();
if p.is_some_and(|p| aggressor(&p)) {
return None;
}
let c = base.confidence.filter(|c| c.is_finite()).unwrap_or(0.0).clamp(0.0, 1.0);
let mut out = base;
let mut c_pool: f64 = 0.0;
let mut blend = |slot: &mut Option<f64>, name: &str, anchor: f64, strength: f64| {
let Some(r) = pool.get(name) else { return };
let own = slot.filter(|x| x.is_finite());
*slot = Some(match own {
Some(x) => (x + (1.0 - c) * (r.mu - anchor)).clamp(0.0, 1.0),
None => r.mu,
});
c_pool = c_pool.max(r.confidence(strength));
};
blend(&mut out.fold_to_bet, "foldToBet", DEFAULT_FOLD_TO_BET, PRIOR_HANDS);
blend(&mut out.fold_to_cbet, "foldToCbet", DEFAULT_FOLD_TO_BET, LINE_STRENGTH);
blend(&mut out.street_fold_to_bet[0], "flopFoldToBet", DEFAULT_FOLD_TO_BET, LINE_STRENGTH);
blend(&mut out.street_fold_to_bet[1], "turnFoldToBet", DEFAULT_FOLD_TO_BET, LINE_STRENGTH);
blend(&mut out.street_fold_to_bet[2], "riverFoldToBet", DEFAULT_FOLD_TO_BET, LINE_STRENGTH);
blend(&mut out.fold_to_three_bet, "foldToThreeBet", FOLD_TO_THREE_BET_ANCHOR, LINE_STRENGTH);
blend(&mut out.fold_to_steal, "foldToSteal", 0.65, STEAL_STRENGTH);
if out == base {
return None;
}
out.confidence = Some(1.0 - (1.0 - c) * (1.0 - c_pool));
Some(out)
}
#[cfg(test)]
mod tests {
use super::*;
fn table() -> Value {
crate::json::parse::parse(
r#"{"reads": {
"foldToBet": {"stufen": {"NL0.01-0.02": {"mu": 0.55, "kappa": 19, "spieler": 229, "cv_delta_heute": [0.015, 0.005, 0.02]}}},
"foldToCbet": {"stufen": {"NL0.01-0.02": {"mu": 0.49, "kappa": 8.3, "spieler": 171, "cv_delta_heute": [0.57, 0.40, 0.77]}}},
"riverFoldToBet": {"stufen": {"NL0.01-0.02": {"mu": 0.63, "kappa": 6, "spieler": 142, "cv_delta_heute": [0.03, -0.03, 0.07]}}},
"aggression": {"stufen": {"NL0.01-0.02": {"mu": 0.32, "kappa": 25, "spieler": 260, "cv_delta_heute": [0.001, 0.0001, 0.002]}}}
}}"#,
)
.unwrap()
}
/// The per-stake export: `tor` decides (not the CV bound), and only a cash stake enters.
#[test]
fn the_export_gate_and_format_decide() {
let t = crate::json::parse::parse(
r#"{"reads": {
"foldToBet": {"stufen": {"NL0.01-0.02": {"mu": 0.554, "kappa": 19, "spieler": 229, "cv_delta_heute": [0.0127, 0.0041, 0.0218], "tor": true, "format": "cash"},
"uebung": {"mu": 0.50, "kappa": 12, "spieler": 408, "cv_delta_heute": [0.004, 0.001, 0.007], "tor": true, "format": "spielgeld"}}},
"foldToCbet": {"stufen": {"NL0.01-0.02": {"mu": 0.49, "kappa": 8, "spieler": 171, "cv_delta_heute": [0.01, 0.002, 0.02], "tor": false, "format": "cash"}}}
}}"#,
)
.unwrap();
let nl2 = from_table(&t, "NL0.01-0.02");
assert_eq!(nl2.reads.len(), 1, "{nl2:?}");
assert!(nl2.get("foldToBet").is_some() && nl2.get("foldToCbet").is_none(), "tor=false wins over a positive CV bound");
assert!(from_table(&t, "uebung").reads.is_empty(), "play money never enters the cash pool");
}
#[test]
fn only_proven_passive_reads_enter() {
let pool = from_table(&table(), "NL0.01-0.02");
assert!(pool.get("foldToBet").is_some() && pool.get("foldToCbet").is_some());
assert!(pool.get("riverFoldToBet").is_none(), "CV lower bound below zero");
assert!(pool.get("aggression").is_none(), "never an aggression axis");
assert!(from_table(&table(), "NL0.05-0.1").reads.is_empty());
}
#[test]
fn the_individual_read_takes_over_and_the_aggressor_is_guarded() {
let pool = from_table(&table(), "NL0.01-0.02");
let none = pooled(&pool, None).unwrap();
assert_eq!(none.fold_to_bet, Some(0.55));
let thin = Profile { fold_to_bet: Some(0.30), confidence: Some(0.1), ..Profile::default() };
let thick = Profile { confidence: Some(0.9), ..thin };
let (a, b) = (pooled(&pool, Some(thin)).unwrap(), pooled(&pool, Some(thick)).unwrap());
assert!(a.fold_to_bet.unwrap() > b.fold_to_bet.unwrap(), "pool pull shrinks with the sample");
assert!((b.fold_to_bet.unwrap() - (0.30 + 0.1 * 0.10)).abs() < 1e-12);
let maniac = Profile { aggression: Some(0.7), aggression_confidence: Some(0.5), ..thin };
assert_eq!(pooled(&pool, Some(maniac)), None);
let raiser = Profile { pfr: Some(0.35), ..thin };
assert_eq!(pooled(&pool, Some(raiser)), None);
}
}
+22
View File
@@ -68,6 +68,28 @@ pub struct Profile {
pub river_bluff_share: Option<f64>,
/// How many river bets/raises `river_bluff_share` rests on.
pub river_bluff_shown: Option<f64>,
/// Aggression frequency on the FLOP only (memory handover `reads.flopAggression`). `None` without it.
pub flop_aggression: Option<f64>,
/// How often the player, in a blind, folds to a steal raise (`reads.foldToSteal`).
pub fold_to_steal: Option<f64>,
/// How often the player folds after betting/raising a postflop street and being raised (`reads.foldToRaise`).
pub fold_to_raise: Option<f64>,
/// How often the player RAISES when facing a postflop bet (raises over folds + calls + raises facing
/// a bet). Sim memory only so far (`RERAISE_TIEFE` gate); `None` without it.
pub raise_to_bet: Option<f64>,
/// How often the player RE-RAISES when raised after their own postflop bet/raise on that street
/// (aggressive over fold + call + aggressive in that spot). Drives the `RERAISE_TIEFE` narrowing
/// per raise level; `None` without it (pool value).
pub reraise_to_raise: Option<f64>,
/// How strongly the player's bet size tells their strength, as a gain on the population's
/// size notch (`exploit::size_notch`): 1 = the population (bigger is stronger, as assumed), 0 = no
/// tell, negative = reverse sizing, 2 = a pure value-sizer. From the shown (size, strength) pairs,
/// shrunk toward 1. Sim memory only so far; used under `GROESSE_LESEN=1`.
pub size_gain: Option<f64>,
/// Set by `engine::read_gate` (switch `ANGRIFF_FOLD`) on the reduced profile of an untrusted style:
/// only the fold reads were kept, so the profile has no style (`exploit::style::classify` =
/// Unknown) and only the fold chance of hero's bets uses it. Never on the wire.
pub fold_only: bool,
}
/// Equity vs a random hand on the river below which a shown river bet counts as air (a bluff): the
+8 -1
View File
@@ -58,6 +58,13 @@ pub struct RangeRead {
pub bluff_confidence: f64,
}
/// Measurement switch (read once): `GEGNER_RANGE=1` lets the river gearbox (`engine::river_subgame`)
/// apply the read layer. Default off: bit-identical to before.
pub fn on() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var("GEGNER_RANGE").as_deref() == Ok("1"))
}
fn ok(x: Option<f64>) -> Option<f64> {
x.filter(|v| v.is_finite())
}
@@ -85,7 +92,7 @@ impl RangeRead {
let fold_pooled = ok(p.fold_to_bet);
Some(RangeRead {
tilt,
aggression_ratio: [ratio(None), ratio(p.turn_aggression), ratio(p.river_aggression)],
aggression_ratio: [ratio(p.flop_aggression), ratio(p.turn_aggression), ratio(p.river_aggression)],
shown,
fold: [0, 1, 2].map(|i| ok(p.street_fold_to_bet[i]).or(fold_pooled).map(|f| f.clamp(0.0, 1.0))),
confidence,
+4
View File
@@ -29,6 +29,10 @@ pub struct Continuation {
pub min_draw: Draw,
pub bluff_share: f64,
pub continue_share: Option<f64>,
/// `top_share`, when set, keeps only the strongest that share of the hands still in the range at
/// this step (by made hand, then draw, `engine::range_filter`) as value; `bluff_share` is admitted
/// below it as usual. A re-raise narrows the range this way per raise level (`RERAISE_TIEFE`).
pub top_share: Option<f64>,
}
impl RangeSpec {
+14
View File
@@ -39,6 +39,13 @@ pub const PRIOR: Profile = Profile {
aggression_confidence: None,
river_bluff_share: None,
river_bluff_shown: None,
flop_aggression: None,
fold_to_steal: None,
fold_to_raise: None,
raise_to_bet: None,
reraise_to_raise: None,
size_gain: None,
fold_only: false,
};
/// Postflop moves at which an aggression read and the population weigh the same — the session
@@ -87,6 +94,13 @@ pub fn shrink(profile: &Profile, hands: f64) -> Profile {
aggression_confidence: profile.aggression_confidence,
river_bluff_share: profile.river_bluff_share,
river_bluff_shown: profile.river_bluff_shown,
flop_aggression: profile.flop_aggression,
fold_to_steal: profile.fold_to_steal,
fold_to_raise: profile.fold_to_raise,
raise_to_bet: profile.raise_to_bet,
reraise_to_raise: profile.reraise_to_raise,
size_gain: profile.size_gain,
fold_only: profile.fold_only,
}
}
+5
View File
@@ -10,6 +10,11 @@ const BOUNDS: (f64, f64) = (0.7, 1.4);
/// steal, calling stations narrow it; no villain or no profiles: 1.0.
pub fn steal_width(spot: &Spot) -> f64 {
let folds: Vec<f64> = spot.live_villains().map(|v| fold_base(v.profile.as_ref())).collect();
width_from_folds(&folds)
}
/// The opening-width multiplier from the fold bases of the players behind (see `steal_width`).
pub fn width_from_folds(folds: &[f64]) -> f64 {
if folds.is_empty() {
return 1.0;
}
+171 -8
View File
@@ -93,6 +93,146 @@ fn raise_draw_floor() -> Draw {
})
}
/// Messschalter (einmal gelesen): `TURN_RAISE_BLUFF=<f>` macht die Range einer TURN-ERHOEHUNG enger:
/// nur starke Draws (Open-Ender, Flush, Kombi) zaehlen als Draws, und der Bluff-Anteil wird mit `f`
/// multipliziert (0 = keine reinen Bluffs; die Semi-Bluffs sind die Draws). Nemesis-3 15.11.: Hero setzt
/// den Turn, der Gegner erhoeht (Overbet), Hero callt Middle Pair / Two Pair mit Engine-Equity 59 %, echt
/// 2,4 % (41 Calls) - die Range hielt jeden Gutshot plus 24 % Bluffs. Ungesetzt: bit-identisch (alt).
fn turn_raise_bluff() -> Option<f64> {
use std::sync::OnceLock;
static F: OnceLock<Option<f64>> = OnceLock::new();
*F.get_or_init(|| std::env::var("TURN_RAISE_BLUFF").ok().and_then(|v| v.parse::<f64>().ok()).filter(|f| f.is_finite() && *f >= 0.0))
}
/// Messschalter (einmal gelesen): `TURN_RAISE_NUR=gelesen` beschraenkt `TURN_RAISE_BLUFF` auf GELESENE
/// Gegner (Profil vorhanden). Ungelesen (auch auf blind gegatet) bleibt die alte Range samt Pop-Prior:
/// Tor 15.11. mit TURN_RAISE_BLUFF=0 fuer alle verlor nemesis-2@blind -11,02 +-7,65, LBR +36,5 +-39,8.
/// `TURN_RAISE_NUR=roh`: wie `gelesen`, aber gegen den UNGEGATETEN Read (der Gate streift Regular/Unknown
/// ab, Nemesis-3 ist Regular). `decide_with` merkt sich je Entscheidung, welche Sitze einen rohen Read haben.
#[derive(Clone, Copy, PartialEq)]
enum NurModus {
Alle,
Gelesen,
Roh,
/// `TURN_RAISE_NUR=xr:<s>`: nur wenn der ROHE Check-Raise-Read unter `s` liegt (ein seltener Raiser
/// erhoeht eng; Sonde 15.11. Memory: nemesis-2 0,286 erhoeht weit, nemesis-3 0,075, maniac 0,029).
Xr(f64),
/// `TURN_RAISE_NUR=rtb:<s>`: nur wenn der ROHE Raise-gegen-Einsatz-Read (`Profile::raise_to_bet`,
/// immer gezaehlt, Pool-Anker 0,30) unter `s` liegt. Sonde 15.11. Memory: nemesis-2 0,452 (erhoeht
/// weit), nemesis-3 0,251, maniac 0,220. Ohne Evidenz steht der Read auf dem Anker, also aus.
Rtb(f64),
}
fn nur_modus() -> NurModus {
use std::sync::OnceLock;
static M: OnceLock<NurModus> = OnceLock::new();
*M.get_or_init(|| match std::env::var("TURN_RAISE_NUR").as_deref() {
Ok("gelesen") => NurModus::Gelesen,
Ok("roh") => NurModus::Roh,
Ok(v) if v.starts_with("rtb:") => v[4..].parse::<f64>().ok().filter(|x| x.is_finite()).map_or(NurModus::Alle, NurModus::Rtb),
Ok(v) if v.starts_with("xr:") => v[3..].parse::<f64>().ok().filter(|x| x.is_finite()).map_or(NurModus::Alle, NurModus::Xr),
_ => NurModus::Alle,
})
}
thread_local! {
/// Sitze (Bitmaske) mit rohem Read in der laufenden Entscheidung; nur fuer `TURN_RAISE_NUR=roh`.
static ROH: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
}
/// Von `decide_with` vor dem Gate aufgerufen: merkt die Sitze mit rohem (ungegatetem) Read. Ohne
/// `TURN_RAISE_NUR=roh` ein No-op.
pub fn note_raw_reads(spot: &Spot) {
let pass: Box<dyn Fn(&crate::exploit::profile::Profile) -> bool> = match nur_modus() {
NurModus::Roh => Box::new(|_| true),
NurModus::Xr(s) => Box::new(move |p| p.check_raise.is_some_and(|x| !x.is_nan() && x < s)),
NurModus::Rtb(s) => Box::new(move |p| p.raise_to_bet.is_some_and(|x| !x.is_nan() && x < s)),
_ => return,
};
let mask = spot.villains.iter().filter(|v| v.seat < 64 && v.profile.as_ref().is_some_and(|p| pass(p))).fold(0u64, |m, v| m | 1 << v.seat);
ROH.with(|r| r.set(mask));
}
fn tighten_for(villain: &Villain) -> bool {
match nur_modus() {
NurModus::Alle => true,
NurModus::Gelesen => villain.profile.is_some(),
NurModus::Roh | NurModus::Xr(_) | NurModus::Rtb(_) => villain.seat < 64 && ROH.with(|r| r.get()) >> villain.seat & 1 == 1,
}
}
/// Messschalter (einmal gelesen): `RERAISE_TIEFE=1` verengt die Range bei jeder weiteren Aggression des
/// Gegners auf einer Strasse (zweite Erhoehung, dritte ...) stetig nach seiner gemessenen Frequenz, gegen
/// einen Einsatz zu erhoehen (`Profile::raise_to_bet`, Bayes je Linie): nach der k-ten Aggression bleibt
/// der staerkste Anteil r^(k-1) dessen, was nach der ersten noch in der Range war, plus Bluffs. Ohne Read
/// gilt der Pool-Wert. Befund 15.11. (diag_welt cbet-folder): gegen reine Wert-Erhoehungen blieb die Equity
/// ueber drei Erhoehungen bei 0,64 (Top Pair + Gutshot 5-bettet all-in), weil `level` jede Erhoehung gleich
/// zaehlte; Erhoehungskriege kosteten dort rund 58 bb/100. Vorgabe: aus (alt, bit-identisch).
fn reraise_depth_enabled() -> bool {
use std::sync::OnceLock;
static ON: OnceLock<bool> = OnceLock::new();
RERAISE_OVERRIDE.with(|o| o.get()).unwrap_or_else(|| *ON.get_or_init(|| std::env::var("RERAISE_TIEFE").as_deref() == Ok("1")))
}
/// Messschalter (einmal gelesen) `GROESSE_LESEN=1`: the floor of a villain's bet moves by the size notch
/// times their size tell (`Profile::size_gain`, shown size vs strength): a value-sizer's big bets are
/// stricter and small ones looser, a reverse sizer's the other way, no tell no move. Off: the plain notch.
fn size_read_enabled() -> bool {
use std::sync::OnceLock;
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| std::env::var("GROESSE_LESEN").as_deref() == Ok("1"))
}
/// `size_notch(ratio)`, plus under `GROESSE_LESEN` the villain's extra tell `(gain - 1)` times a
/// continuous notch `1.4 * log2(ratio / 0.6)` (about -1 at 0.4 pot, +1 at 0.9, +2 at 1.8: the steps of
/// `size_notch`), rounded to rungs. Gain 1 (the population, or no shown pairs) is the plain notch.
fn read_notch(villain: &Villain, ratio: Option<f64>) -> i32 {
let notch = size_notch(ratio);
let gain = villain.profile.as_ref().and_then(|p| p.size_gain).filter(|g| g.is_finite() && size_read_enabled());
match (gain, ratio.filter(|r| r.is_finite() && *r > 0.0)) {
(Some(g), Some(r)) => notch + ((g - 1.0) * 1.4 * (r / 0.6).log2()).round() as i32,
_ => notch,
}
}
/// Messschalter (einmal gelesen) `RERAISE_BLUFF=erst`: the deeper continuation keeps the bluff share of
/// the first (with its population prior) instead of the plain size share. The strength cut removes the
/// air first, so the deeper step alone sets how many bluffs a re-raise range holds (nemesis-1, 15.11.).
fn reraise_bluff_first() -> bool {
use std::sync::OnceLock;
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| std::env::var("RERAISE_BLUFF").as_deref() == Ok("erst"))
}
thread_local! {
static RERAISE_OVERRIDE: std::cell::Cell<Option<bool>> = const { std::cell::Cell::new(None) };
}
/// Diagnostics only (`diag_welt DIAG_SCHALTER=reraise`): force `RERAISE_TIEFE` on or off on this thread,
/// `None` = the environment switch.
pub fn set_reraise_depth_override(on: Option<bool>) {
RERAISE_OVERRIDE.with(|o| o.set(on));
}
/// Raise-facing-a-bet frequency without a read: the pool value (anchor of the counted read,
/// `wire::decode_villain` and `sim::memory`: 0.30), so zero hands mean the pool's narrowing.
pub const RAISE_TO_BET_POOL: f64 = 0.30;
/// The share of the range that continues after the villain's `k`-th aggression on one street
/// (`k >= 2`): `r^(k-1)` with `r` the raise-to-bet read (shrunk to the pool in the read), clamped to
/// `[0.02, 1]`. Since 15.11. `r` is the CONDITIONAL re-raise read (`Profile::reraise_to_raise`, raised
/// after an own bet/raise on the street): the plain raise-facing-a-bet rate narrowed a threshold raiser
/// (same strength bar on every level, nemesis-1) far too much - ladder -11,40 +-9,05 bb/100.
pub fn reraise_share(villain: &Villain, k: usize) -> f64 {
let r = villain.profile.as_ref().and_then(|p| p.reraise_to_raise).filter(|a| a.is_finite()).unwrap_or(RAISE_TO_BET_POOL);
r.clamp(0.02, 1.0).powi(k.saturating_sub(1) as i32)
}
/// How many times the villain bet or raised on `street`.
fn aggressions_on(history: &[ActionRecord], street: Street, seat: u8) -> usize {
history.iter().filter(|r| r.street == street && r.seat == seat && level(r.action).is_some()).count()
}
/// Did the villain already bet or raise on an earlier postflop street? Such a line is a sustained
/// barrel - value-weighted even in the micro pool - so it earns no population over-bluff prior.
fn aggressed_earlier(history: &[ActionRecord], street: Street, seat: u8) -> bool {
@@ -110,18 +250,26 @@ fn on_street(
ratios: &[Option<f64>],
villain: &Villain,
street: Street,
) -> Option<Continuation> {
) -> Vec<Continuation> {
let slot = street as usize - 1;
let sustained = aggressed_earlier(&spot.history, street, villain.seat);
let made_bet =
own_aggression(&spot.history, ratios, street, villain.seat).map(|(lvl, ratio)| {
let base = [BET_RUNG, RAISE_RUNG][lvl][slot];
let bluff = bluff_share(villain.profile.as_ref(), ratio, street);
let tight = (lvl == 1 && street == Street::Turn && tighten_for(villain))
.then(turn_raise_bluff)
.flatten();
let bluff = with_pop_prior_on(villain.profile.as_ref(), street, sustained, lvl == 1, bluff);
let base = [BET_RUNG, RAISE_RUNG][lvl][slot];
(
rung(base, size_notch(ratio) + style_rung(villain)),
rung(base, read_notch(villain, ratio) + style_rung(villain)),
DRAWS[slot],
if lvl == 1 { raise_draw_floor() } else { Draw::Gutshot },
with_pop_prior_on(villain.profile.as_ref(), street, sustained, lvl == 1, bluff),
match (lvl, tight) {
(1, Some(_)) => Draw::OpenEnded,
(1, None) => raise_draw_floor(),
_ => Draw::Gutshot,
},
tight.map_or(bluff, |f| (bluff * f).min(bluff)),
)
});
let made_call = called_big_bet(&spot.history, ratios, street, villain.seat).then(|| {
@@ -136,14 +284,29 @@ fn on_street(
0.0,
)
});
merge(made_bet, made_call).map(|(min_made, draws_continue, min_draw, bluff_share)| Continuation {
let first = merge(made_bet, made_call).map(|(min_made, draws_continue, min_draw, bluff_share)| Continuation {
board_len: street.board_len(),
min_made,
draws_continue,
min_draw,
bluff_share,
continue_share: None,
})
top_share: None,
});
// Each further aggression on the street keeps the strongest r^(k-1) of what the first left, with
// the plain size bluff share below it (a sustained line earns no population over-bluff prior).
let k = aggressions_on(&spot.history, street, villain.seat);
let deeper = (reraise_depth_enabled() && k >= 2).then_some(()).and(first).map(|c| Continuation {
top_share: Some(reraise_share(villain, k)),
bluff_share: if reraise_bluff_first() {
c.bluff_share
} else {
own_aggression(&spot.history, ratios, street, villain.seat)
.map_or(0.0, |(_, ratio)| bluff_share(villain.profile.as_ref(), ratio, street))
},
..c
});
first.into_iter().chain(deeper).collect()
}
/// Postflop narrowing from the villain own actions, one entry per dealt street
@@ -169,6 +332,6 @@ pub fn continuations(spot: &Spot, villain: &Villain) -> Vec<Continuation> {
[Street::Flop, Street::Turn, Street::River]
.into_iter()
.filter(|street| street.board_len() <= spot.board.len())
.filter_map(|street| on_street(spot, &ratios, villain, street))
.flat_map(|street| on_street(spot, &ratios, villain, street))
.collect()
}
+20 -2
View File
@@ -36,6 +36,24 @@ const STATION_MAX_AGGRESSION: f64 = 0.45;
/// aggr 0.41 → trust 0.16) barely exploits. See `station_trust` and BEFUND-nemesis-soft-trust.
const STATION_FULL_TRUST_AGGRESSION: f64 = 0.20;
/// Messschalter (einmal gelesen) `STATION_POSTFLOP=1`: the loose-passive path to `CallingStation` also
/// needs a postflop signal - fold-to-bet at most `STATION_LOOSE_MAX_FOLD` (unknown passes). A reg who
/// only opens wider (the learning HUD reg, `sim::lerner`, 15.11.: memory read -7,15 bb/100 against blind,
/// all postflop) folds like a reg and is no station, however wide it plays preflop.
fn station_postflop() -> bool {
use std::sync::OnceLock;
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| std::env::var("STATION_POSTFLOP").as_deref() == Ok("1"))
}
/// Fold-to-bet above which a loose-passive player is not a station under `STATION_POSTFLOP` (a reg
/// folds ~0,50-0,55, the stations of the ladder 0,20-0,35).
const STATION_LOOSE_MAX_FOLD: f64 = 0.45;
fn folds_like_a_station(fold: Option<f64>) -> bool {
!station_postflop() || fold.is_none_or(|b| b <= STATION_LOOSE_MAX_FOLD)
}
/// 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))
@@ -70,11 +88,11 @@ pub fn classify(profile: &Profile) -> Style {
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() {
if profile.fold_only || (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 {
} else if (loose && passive && folds_like_a_station(fold)) || sticky {
Style::CallingStation
} else if tight {
Style::Nit