Files
pokerfreak/src/exploit/street_continuation.rs
T

580 lines
30 KiB
Rust

use super::bet_ratio::bet_ratios;
use super::bluff_share::{bluff_share, with_pop_prior_on};
use super::made_ladder::rung;
use super::range_spec::Continuation;
use super::size_notch::size_notch;
use super::style_rung::style_rung;
use crate::game::{ActionRecord, SeenAction, Spot, Street, Villain};
use crate::read::draw::Draw;
use crate::read::made::Made;
/// A call of a bet at least this big (pot fractions) shows a hand with some showdown value.
const BIG_BET: f64 = 0.6;
/// Floor rung of a bet / of a raise (or all-in) per street (flop, turn, river), see `LADDER`
/// in `made_ladder`: middle pair, top pair weak kicker, top pair good kicker for bets;
/// top pair good kicker, overpair, two pair for raises.
const BET_RUNG: [i32; 3] = [2, 3, 4];
const RAISE_RUNG: [i32; 3] = [4, 5, 6];
/// Draws are still in on flop and turn, not on the river.
const DRAWS: [bool; 3] = [true, true, false];
/// Messschalter (einmal gelesen) `GEGEN_GROSS=<t>[,akt]`: the range behind a bet that puts hero all-in
/// (any street) or a river bet of at least `GROSS_RATIO` pots keeps only its strongest `t` as value
/// (`Continuation::top_share`; on the river ranked by showdown strength, `engine::range_filter`), the
/// line's bluff share below it. `akt` scales `t` by the villain's aggression read against the pool
/// (`t * a / 0.30`, clamped to `[0.5 t, 2 t]`; no read: `t`). Live 17.11. KK on Ad7hAh7sJc called a
/// passive player's 1.5-pot river bet at "equity 0.66": the made-class floor kept 88-TT (18 of 28
/// combos) as value. Leak finder family A (calls against all-ins). Unset: off, bit-identical.
///
/// Zusaetze (20.11., Stack-off-Messung `messung/stackoff/`): `river` narrows only on the river (flop/turn
/// all-ins keep their range: there calling a jam with an overpair is +EV in the NL2 population), `ab:<r>` sets
/// the river bet size from which a bet narrows (default `GROSS_RATIO`); with `river` only the size counts, a
/// river all-in below it keeps its range; `allin` narrows only a bet that is all-in for one side (hhDealer holdout
/// 20.11.: a non-all-in river bet of 0,75 pot or more is called profitably by one pair, narrowing it cost -7 582 bb). Without them: unchanged.
#[derive(Clone, Copy)]
struct GegenGross {
t: f64,
akt: bool,
nur_river: bool,
nur_allin: bool,
ab: f64,
}
fn gegen_gross() -> Option<GegenGross> {
use std::sync::OnceLock;
static G: OnceLock<Option<GegenGross>> = OnceLock::new();
*G.get_or_init(|| {
let v = std::env::var("GEGEN_GROSS").ok()?;
let mut parts = v.split(',');
let t = parts.next()?.trim().parse::<f64>().ok().filter(|t| t.is_finite() && *t > 0.0 && *t < 1.0)?;
let mut g = GegenGross { t, akt: false, nur_river: false, nur_allin: false, ab: GROSS_RATIO };
for p in parts.map(str::trim) {
match p {
"akt" => g.akt = true,
"river" => g.nur_river = true,
"allin" => g.nur_allin = true,
p => {
if let Some(r) = p.strip_prefix("ab:").and_then(|r| r.parse::<f64>().ok()).filter(|r| r.is_finite() && *r > 0.0) {
g.ab = r;
}
}
}
}
Some(g)
})
}
/// Is `GEGEN_GROSS` on (the river ranking of `top_share` by showdown strength follows it)?
pub fn gegen_gross_enabled() -> bool {
gegen_gross().is_some()
}
/// River bet size (pots) from which `GEGEN_GROSS` narrows.
const GROSS_RATIO: f64 = 1.0;
/// Pool aggression the `akt` scaling is relative to.
const GROSS_POOL_AGGRESSION: f64 = 0.30;
/// The value share of `GEGEN_GROSS` for the villain's aggression on the current `street`, or `None`
/// when the switch is off or the bet is neither all-in for hero nor a big river bet.
fn gegen_gross_share(spot: &Spot, villain: &Villain, ratios: &[Option<f64>], street: Street) -> Option<f64> {
let GegenGross { t, akt, nur_river, nur_allin, ab } = gegen_gross()?;
if nur_river && street != Street::River {
return None;
}
let (_, ratio) = own_aggression(&spot.history, ratios, street, villain.seat)?;
let last_is_villain = spot.history.iter().rev().find(|r| r.street == street && r.action.is_aggressive()).is_some_and(|r| r.seat == villain.seat);
let hero_all_in = last_is_villain && spot.to_call > 0.0 && spot.to_call >= spot.hero_stack - 1e-9;
let villain_all_in = spot.history.iter().any(|r| r.street == street && r.seat == villain.seat && r.action == SeenAction::AllIn);
let big_river = street == Street::River && ratio.is_some_and(|r| r >= ab);
// `river`: only the size counts (a small river jam keeps its range: one pair calls it profitably).
if !(big_river || (!nur_river && (hero_all_in || villain_all_in))) || (nur_allin && !(hero_all_in || villain_all_in)) {
return None;
}
let a = villain.profile.as_ref().and_then(|p| p.aggression).filter(|a| a.is_finite() && akt);
Some(a.map_or(t, |a| (t * a / GROSS_POOL_AGGRESSION).clamp(0.5 * t, (2.0 * t).min(1.0))))
}
/// Bet = 0, raise (RAISE or ALL_IN) = 1.
fn level(action: SeenAction) -> Option<usize> {
match action {
SeenAction::Bet => Some(0),
SeenAction::Raise | SeenAction::AllIn => Some(1),
_ => None,
}
}
/// `level` of the record at `i` (`ratio`: its chips over the pot before it). Under `ALLIN_EINSATZ` an ALL_IN
/// that opens the street (no bet or raise before it there) is a bet, read by its size like any bet: always
/// with `1`, up to `bis:<x>` pots with `bis:x` (bigger opening all-ins keep the raise floor). After an earlier
/// bet or raise it is a raise. Off (default, bit-identical): every ALL_IN is a raise. Live 19.11. (hand
/// 180802100046): a river donk all-in of 0,29 pot got the bet curve AND the river raise floor, AcKd on Ks (top
/// pair) had equity 0,00 and folded. The hhDealer data write an all-in as BET/RAISE: no offline gate saw it.
fn level_in(history: &[ActionRecord], i: usize, action: SeenAction, ratio: Option<f64>) -> Option<usize> {
if let (SeenAction::AllIn, Some((max, passiv))) = (action, allin_einsatz()) {
let street = history[i].street;
let opens = !history[..i].iter().any(|r| r.street == street && r.action.is_aggressive());
// `/raise`: nur, wenn dieser Gegner auf keiner fruehen Flop-/Turn-Strasse erhoeht hat (Hand 177599200076: Turn-Raise,
// dann River-Jam = ein Raise-Spieler, die alte Raise-Range passt; Hand 180802100046: nur Flop-Bet, dann
// Jam = ein Einsatz).
let frueh = passiv && history[..i].iter().any(|r| r.seat == history[i].seat && r.street != street && r.street != Street::Preflop && matches!(r.action, SeenAction::Raise | SeenAction::AllIn));
if opens && !frueh && ratio.is_some_and(|x| x <= max) {
return Some(0);
}
}
level(action)
}
/// Messschalter `ALLIN_EINSATZ` (einmal gelesen), see `level_in`: `Some((max ratio, passiv))` (`1` = no limit);
/// Zusatz `/raise` (`1/raise`, `bis:1.3/raise`): ein Jam gilt nur dann als Einsatz, wenn der Jammer auf einer
/// frueheren Flop-/Turn-Strasse nicht erhoeht hat.
pub fn allin_einsatz() -> Option<(f64, bool)> {
use std::sync::OnceLock;
static AN: OnceLock<Option<(f64, bool)>> = OnceLock::new();
*AN.get_or_init(|| {
let v = std::env::var("ALLIN_EINSATZ").ok()?;
let (x, passiv) = match v.strip_suffix("/raise") {
Some(x) => (x, true),
None => (v.as_str(), false),
};
match x {
"1" => Some((f64::INFINITY, passiv)),
x => x.strip_prefix("bis:").and_then(|v| v.trim().parse().ok()).filter(|v: &f64| *v > 0.0).map(|m| (m, passiv)),
}
})
}
/// The strongest aggression of the villain on `street`: highest level, then biggest ratio.
fn own_aggression(
history: &[ActionRecord],
ratios: &[Option<f64>],
street: Street,
seat: u8,
) -> Option<(usize, Option<f64>)> {
history
.iter()
.zip(ratios)
.enumerate()
.filter(|(_, (r, _))| r.street == street && r.seat == seat)
.filter_map(|(i, (r, ratio))| level_in(history, i, r.action, *ratio).map(|l| (l, *ratio)))
.max_by(|a, b| {
a.0.cmp(&b.0).then(
a.1.unwrap_or(-1.0)
.partial_cmp(&b.1.unwrap_or(-1.0))
.unwrap_or(std::cmp::Ordering::Equal),
)
})
}
/// Did the villain call, on `street`, a bet or raise (by anyone) of at least `BIG_BET` pots?
fn called_big_bet(
history: &[ActionRecord],
ratios: &[Option<f64>],
street: Street,
seat: u8,
) -> bool {
history.iter().enumerate().any(|(i, r)| {
r.street == street
&& r.seat == seat
&& r.action == SeenAction::Call
&& history[..i]
.iter()
.zip(&ratios[..i])
.rev()
.find(|(b, _)| b.street == street && b.action.is_aggressive())
.is_some_and(|(_, ratio)| ratio.is_some_and(|x| x >= BIG_BET))
})
}
/// (floor, draws continue, weakest draw that counts, bluff share)
type Floor = (Made, bool, Draw, f64);
fn merge(a: Option<Floor>, b: Option<Floor>) -> Option<Floor> {
match (a, b) {
(Some((ma, da, wa, ba)), Some((mb, db, wb, bb))) => Some((ma.max(mb), da && db, wa.max(wb), ba.max(bb))),
(one, other) => one.or(other),
}
}
/// Messschalter (einmal gelesen): `RAISE_DRAWS=stark` laesst in der Range einer ERHOEHUNG nur
/// starke Draws (Open-Ender, Flush-Draw, Kombi) als Draws gelten statt jeden Gutshot.
/// Live 14.11.: gegen eine Flop-Erhoehung auf 89J hielt die Range jede Broadway-Hand mit Gutshot,
/// 78 (Bottom Pair + Gutshot) rechnete 0.50 Equity und ging all-in (-100 BB); Bluff-Anteil war dabei
/// fast egal (0.15 -> 0.49, 0.45 -> 0.51). Vorgabe: Gutshot (alt).
fn raise_draw_floor() -> Draw {
use std::sync::OnceLock;
static FLOOR: OnceLock<Draw> = OnceLock::new();
*FLOOR.get_or_init(|| match std::env::var("RAISE_DRAWS").as_deref() {
Ok("stark") => Draw::OpenEnded,
_ => Draw::Gutshot,
})
}
/// 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));
}
pub 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 {
history.iter().any(|r| {
r.seat == seat
&& r.street != Street::Preflop
&& (r.street as usize) < (street as usize)
&& r.action.is_aggressive()
})
}
/// `BETTOR`: the likelihood of the villain's answer at his open decision on `street` (nobody had bet
/// before him there): his check, or his bet by size class (`exploit::bettor`). Only heads-up (the
/// table is measured on heads-up nodes) and only with a table. Second value: the answer was a bet.
fn bettor_node(spot: &Spot, villain: &Villain, ratios: &[Option<f64>], street: Street) -> Option<(super::bettor::Likelihood, bool)> {
if !super::bettor::enabled() || spot.villains.iter().filter(|v| !v.folded).count() != 1 {
return None;
}
let (i, rec) = spot.history.iter().enumerate().find(|(_, r)| {
r.street == street && (r.action.is_aggressive() || (r.seat == villain.seat && r.action == SeenAction::Check))
})?;
if rec.seat != villain.seat {
return None;
}
let bet = rec.action.is_aggressive();
// An all-in bet is read by its size: PHH has no stacks, our own NL2 all-in bets are too few for a curve.
let answer = if bet {
super::bettor::answer_of(ratios.get(i).copied().flatten(), false)?
} else {
'x'
};
let gross = bet && (street == Street::River || (street == Street::Turn && bettor_gross_turn())) && matches!(answer, 'g' | 'u');
if gross && bettor_gross_aus() {
return None;
}
let pfa = spot.history.iter().rev().find(|r| r.street == Street::Preflop && r.action.is_aggressive()).is_some_and(|r| r.seat == villain.seat);
let before = street != Street::Flop
&& spot.history.iter().any(|r| r.seat == villain.seat && r.street as usize + 1 == street as usize && r.action.is_aggressive());
let mix = if gross { bettor_gross_mix() } else { 0.0 };
super::bettor::likelihood(street, pfa, before, answer).map(|mut lk| {
if mix > 0.0 {
lk.iter_mut().for_each(|x| *x = (1.0 - mix) * *x + mix);
}
(lk, bet)
})
}
/// `BETTOR_GROSS=klasse` (off = bit-identical): river bets above 0,8 pot (`g`, `u`) are read by the made-class
/// floor again, not by the `BETTOR` curve. Pruefstand 18.11. (solver-kern): against big river bets
/// "always call" beat the solver with BETTOR ranges by ~3000 bb on real dev spots, the curve gives big
/// bets too little air (`messung/pruefstand/BERICHT.md`).
fn bettor_gross_aus() -> bool {
use std::sync::OnceLock;
static AUS: OnceLock<bool> = OnceLock::new();
*AUS.get_or_init(|| std::env::var("BETTOR_GROSS").as_deref() == Ok("klasse"))
}
/// `BETTOR_GROSS_TURN=1` (off = bit-identical): a turn bet of a pot or more (`g`, `u`) after the same player's flop bet
/// is read like `BETTOR_GROSS` reads big river bets (class floor / `mix:<a>`), not by the flat `BETTOR` curve. The
/// curve (measured over all pots) accepts nearly every strength for a pot-size double barrel, so a squeeze pot's
/// range stayed wide: 99 on 478J called a pot-size turn barrel at equity 0,37 (hand 178593300919).
fn bettor_gross_turn() -> bool {
use std::sync::OnceLock;
static AN: OnceLock<bool> = OnceLock::new();
*AN.get_or_init(|| std::env::var("BETTOR_GROSS_TURN").as_deref() == Ok("1"))
}
/// `BETTOR_GROSS=mix:<a>` (off = bit-identical): the BETTOR curve of a river bet above 0,8 pot is mixed
/// with `a` of a flat acceptance, so weak holdings stay in the range (more air). Same measurement.
fn bettor_gross_mix() -> f64 {
use std::sync::OnceLock;
static MIX: OnceLock<f64> = OnceLock::new();
*MIX.get_or_init(|| {
std::env::var("BETTOR_GROSS").ok().and_then(|v| v.strip_prefix("mix:").and_then(|a| a.parse::<f64>().ok())).filter(|a| a.is_finite()).map_or(0.0, |a| a.clamp(0.0, 1.0))
})
}
/// `VORWISSEN_KERN=1`: am River mischt der Read `riverBluffShown_<klasse>` der Einsatzgroesse in den Bluff-Anteil:
/// `(1 - w) * bluff + w * q`, `q` = Schrumpfmittel (Luft-Anteil gezeigter Einsaetze der Klasse, Prior des Drahts oder
/// der eingehende Anteil), `w` = `n / (n + a + b)`, Ergebnis hoechstens `MAX_BLUFF_SHARE`. Aus / kein Read: `bluff`.
fn river_bluff_gezeigt(profile: Option<&crate::exploit::profile::Profile>, street: Street, ratio: Option<f64>, bluff: f64) -> f64 {
let art = super::profile::vorwissen_bluff_an();
if art == 0 || street != Street::River {
return bluff;
}
let zelle = |v: &super::profile::Vorwissen| if art == 3 { v.verlust_river } else { v.bluff_river };
let Some(z) = (|| zelle(&profile?.vorwissen)[super::profile::klasse_index(ratio?)?])() else { return bluff };
if art >= 2 {
// relativ: der Spieler gegen das Prior-Mittel seiner Zelle, im Logit auf den eingehenden Anteil verschoben
// (Pool-Definition und Kern-Anker passen so zusammen; absolut kostete es dev -0,107 bb/100)
let Some((a, b)) = z.prior else { return bluff };
let mu = a / (a + b);
let lg = |x: f64| { let x = x.clamp(1e-4, 1.0 - 1e-4); (x / (1.0 - x)).ln() };
let s = z.konfidenz() * (lg(z.mittel(mu)) - lg(mu));
let neu = 1.0 / (1.0 + (-(lg(bluff) + s)).exp());
return neu.clamp(0.0, super::bluff_share::MAX_BLUFF_SHARE.max(bluff));
}
let q = z.mittel(bluff).min(super::bluff_share::MAX_BLUFF_SHARE);
let w = z.konfidenz();
((1.0 - w) * bluff + w * q).clamp(0.0, super::bluff_share::MAX_BLUFF_SHARE.max(bluff))
}
/// One continuation for the villain on `street`, if their actions there say anything.
fn on_street(
spot: &Spot,
ratios: &[Option<f64>],
villain: &Villain,
street: Street,
) -> Vec<Continuation> {
let slot = street as usize - 1;
let sustained = aggressed_earlier(&spot.history, street, villain.seat);
// BETTOR: the open bet (or check) is read by its measured likelihood; a bet's class floor and
// bluff share then fall away, a later raise of the villain on the street keeps its floor.
let node = bettor_node(spot, villain, ratios, street);
let lk_bet = node.is_some_and(|(_, bet)| bet);
let made_bet =
own_aggression(&spot.history, ratios, street, villain.seat).filter(|(lvl, _)| !(lk_bet && *lvl == 0)).map(|(lvl, ratio)| {
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);
// EINSATZ_BLUFF: an open bet's air from the counted open-bet frequency around what blind
// believes here (`exploit::bet_open`); off or unread: unchanged.
let bluff = if lvl == 0 {
let blind = with_pop_prior_on(None, street, sustained, false, bluff_share(None, ratio, street));
super::bet_open::open_bluff_share(villain.profile.as_ref(), street, blind).unwrap_or(bluff)
} else {
bluff
};
// VORWISSEN_KERN: der Luft-Anteil gezeigter River-Einsaetze dieser Groesse, konfidenzgewichtet eingemischt.
let bluff = river_bluff_gezeigt(villain.profile.as_ref(), street, ratio, bluff);
let line = crate::engine::glaube_linie::line_of(spot, villain.seat, street, ratio, lvl == 1);
let bluff = crate::engine::glaube::bluff(villain.seat, street, ratio, line.as_ref(), bluff);
let base = [BET_RUNG, RAISE_RUNG][lvl][slot];
(
rung(base, read_notch(villain, ratio) + style_rung(villain)),
DRAWS[slot],
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(|| {
(
if street == Street::River {
Made::MiddlePair
} else {
Made::BottomPair
},
DRAWS[slot],
Draw::Gutshot,
0.0,
)
});
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,
// GEGEN_GROSS: a bet that puts hero all-in, or a river bet of at least a pot, keeps only the
// strongest share of the range as value (`gegen_gross_share`); the bluff share stays below it.
top_share: (made_bet.is_some() && street == spot.street).then(|| gegen_gross_share(spot, villain, ratios, street)).flatten(),
// WERT_BRETT=river: a river bet/raise floor means the same relative strength on every board.
min_strength: (street == Street::River && made_bet.is_some() && super::brett_floor::enabled())
.then(|| super::brett_floor::strength_cut(&spot.rules(), &spot.board, min_made))
.flatten(),
likelihood: 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
});
let measured = node.map(|(lk, _)| Continuation {
board_len: street.board_len(),
min_made: Made::Air,
draws_continue: false,
min_draw: Draw::Gutshot,
bluff_share: 0.0,
continue_share: None,
top_share: None,
min_strength: None,
likelihood: Some(lk),
});
measured.into_iter().chain(first).chain(deeper).collect()
}
/// Postflop narrowing from the villain own actions, one entry per dealt street
/// (`board_len <= spot.board.len()`), sorted by board length.
///
/// - **Bet** keeps `[middle pair, top pair weak kicker, top pair good kicker]+` on
/// flop/turn/river; **raise or all-in** keeps `[top pair good kicker, overpair, two pair]+`.
/// Flop and turn bets keep draws, the river keeps made hands only. Several actions on
/// one street: the highest level (then the biggest) counts.
/// - The size (chips added / pot before, from the amounts in the history) moves the floor
/// by `size_notch` rungs: bigger is stricter. Unknown sizes or pots: no move.
/// - A calling station or loose-aggressive style (see `style::classify`) lowers the floor
/// one rung, a nit raises it one. The floor never drops below bottom pair.
/// - Bets and raises keep a **bluff fraction** below their floor (`bluff_share`: bet size,
/// street, style or aggression); calls keep none.
/// - **Checks and calls add nothing**: the continuation only expresses a minimum strength,
/// and a check does not say the hand is weak (traps) nor does a call bound it from
/// below in a useful way. One exception, a mild floor: a call of a bet of at least 0.6 pot
/// keeps bottom pair or better (or a draw) on flop/turn, middle pair or better on the river.
/// Combined with the villain own bet on the same street the stricter floor wins.
pub fn continuations(spot: &Spot, villain: &Villain) -> Vec<Continuation> {
let ratios = bet_ratios(&spot.history);
[Street::Flop, Street::Turn, Street::River]
.into_iter()
.filter(|street| street.board_len() <= spot.board.len())
.flat_map(|street| on_street(spot, &ratios, villain, street))
.collect()
}