Konflikte: BEKANNTE_SCHALTER vereinigt; range_filter Kept mit Accept + Klassen-Kipp; RAISE_FOLD_DECKEL in sized_fold_on. Specs gruen (169 Test-Binaries). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
202 lines
9.6 KiB
Rust
202 lines
9.6 KiB
Rust
//! How likely one opponent folds to a bet: the documented map from their profile.
|
|
//!
|
|
//! | step | rule |
|
|
//! |---|---|
|
|
//! | base `f` | `foldToBet`, clamped to [0, 1]; without it the style default: nit 0.65, calling station 0.20, loose-aggressive 0.40, otherwise 0.45 |
|
|
//! | size | `p = 1 - (1 - f)^(ratio / 0.66)`: foldToBet is a frequency against a typical two-thirds-pot bet, so at that size `p = f`; smaller bets fold less, bigger more, a zero bet never |
|
|
//! | raised | `p * 0.7` when the opponent already bet and is being raised (money invested, range stronger) |
|
|
//! | cap | at most 0.95: nobody folds for sure |
|
|
//!
|
|
//! `ratio` is the pressure: chips beyond a call over the pot after calling
|
|
//! (`table_fold::pressure_ratio`).
|
|
|
|
use super::profile::Profile;
|
|
use super::style::{classify, station_trust, Style};
|
|
use crate::game::Street;
|
|
|
|
/// Bet size (pot fraction) at which foldToBet is taken to be measured.
|
|
pub const REFERENCE_RATIO: f64 = 0.66;
|
|
/// Fold-to-bet of an opponent we know nothing about.
|
|
pub const DEFAULT_FOLD_TO_BET: f64 = 0.45;
|
|
/// Factor when the opponent is raised after betting.
|
|
pub const RAISE_RESISTANCE: f64 = 0.7;
|
|
/// Largest fold chance ever assumed for one opponent.
|
|
pub const MAX_FOLD: f64 = 0.95;
|
|
|
|
fn style_default(style: Style) -> f64 {
|
|
match style {
|
|
Style::Nit => 0.65,
|
|
Style::CallingStation => 0.20,
|
|
Style::LooseAggressive => 0.40,
|
|
Style::Regular | Style::Unknown => DEFAULT_FOLD_TO_BET,
|
|
}
|
|
}
|
|
|
|
/// The opponent's fold-to-bet at the reference size.
|
|
///
|
|
/// A `CallingStation` read is trust-weighted (`station_trust`): a misclassified aggressive "station"
|
|
/// (nemesis-2, fold-to-bet 0.56 read, aggr 0.41) only partly trusts its high fold frequency, so hero
|
|
/// does not over-barrel into a light-raising range whose multi-street cost the single-street bluff-EV
|
|
/// never models. A genuine station (trust 1.0) is bit-identical to the raw read.
|
|
pub fn fold_base(profile: Option<&Profile>) -> f64 {
|
|
fold_base_on(profile, None)
|
|
}
|
|
|
|
/// `fold_base`, but on `street` the per-street (already pooled-shrunk) fold read replaces the raw
|
|
/// pooled one when the profile carries it. Station trust applies on top, as for the pooled read.
|
|
pub fn fold_base_on(profile: Option<&Profile>, street: Option<Street>) -> f64 {
|
|
match profile {
|
|
None => DEFAULT_FOLD_TO_BET,
|
|
Some(p) => {
|
|
let per_street = street
|
|
.and_then(|s| match s {
|
|
Street::Flop => Some(0),
|
|
Street::Turn => Some(1),
|
|
Street::River => Some(2),
|
|
Street::Preflop => None,
|
|
})
|
|
.and_then(|i| p.street_fold_to_bet[i])
|
|
.filter(|f| !f.is_nan());
|
|
let raw = match per_street.or(p.fold_to_bet.filter(|f| !f.is_nan())) {
|
|
Some(f) => f.clamp(0.0, 1.0),
|
|
None => style_default(classify(p)),
|
|
};
|
|
if classify(p) == Style::CallingStation {
|
|
DEFAULT_FOLD_TO_BET + station_trust(p) * (raw - DEFAULT_FOLD_TO_BET)
|
|
} else {
|
|
raw
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// P(this opponent folds) to a bet of `ratio` pots. Total: any input gives `[0, MAX_FOLD]`.
|
|
pub fn fold_chance(profile: Option<&Profile>, ratio: f64, facing_raise: bool) -> f64 {
|
|
fold_chance_on(profile, ratio, facing_raise, None)
|
|
}
|
|
|
|
/// Fold base against hero's continuation bet: the opponent's fold-to-c-bet read when it carries one
|
|
/// (a calling station's is trust-damped like its pooled read), else the flop read (`fold_base_on`).
|
|
/// A c-bet folder gives up the flop far more often than its pooled fold-to-bet says, and a sticky
|
|
/// flop caller far less.
|
|
pub fn fold_base_cbet(profile: Option<&Profile>) -> f64 {
|
|
match profile.and_then(|p| p.fold_to_cbet.filter(|f| !f.is_nan()).map(|f| (p, f.clamp(0.0, 1.0)))) {
|
|
Some((p, f)) if classify(p) == Style::CallingStation => DEFAULT_FOLD_TO_BET + station_trust(p) * (f - DEFAULT_FOLD_TO_BET),
|
|
Some((_, f)) => f,
|
|
None => fold_base_on(profile, Some(Street::Flop)),
|
|
}
|
|
}
|
|
|
|
/// `fold_chance` with the street's own fold read (`fold_base_on`).
|
|
pub fn fold_chance_on(profile: Option<&Profile>, ratio: f64, facing_raise: bool, street: Option<Street>) -> f64 {
|
|
sized_fold_on(fold_base_on(profile, street), ratio, facing_raise, street)
|
|
}
|
|
|
|
/// Messschalter (einmal gelesen) `UEBERBET=<cap>` (`1` = 1.0): the fold curve stops growing above
|
|
/// `cap` pots. Real NL2 (M6b, `messung/poolruf/ziel-nl2.json`): the river first bet is folded 0.51 at
|
|
/// 0.5-1x pot and 0.50 against big bets/all-ins, our river all-ins were called 70 % - the pool does not
|
|
/// fold more to an overbet, while the `(1-f)^(r/0.66)` curve gave 0.80-0.89 for 1.8-2.4x. The same
|
|
/// switch prices every raise of at least pot (and every all-in) against the TOP of the range
|
|
/// (`engine::called_equity`). Default: off (bit-identical).
|
|
/// `flusspaar` / `flusspaarjam`: river only and only with exactly one pair (leak finder 17.11.: `fluss`
|
|
/// cut the one-pair leak lines by ~2 700 bb but gave up more value jams with two pair, sets and
|
|
/// straights+, net -3 254 bb in the NL2 view).
|
|
/// `fluss` / `flussjam`: the same as `1` / `jam`, but on the river only (gate 17.11.: `1` on every
|
|
/// street lost in 6-max, -7,05 and -10,15 in the NL2 pool, mostly on the turn; the live leak and the
|
|
/// leak finder's NL2 leak sit on the river).
|
|
#[derive(Clone, Copy)]
|
|
struct Ueberbet {
|
|
cap: f64,
|
|
jam: bool,
|
|
river_only: bool,
|
|
pair_only: bool,
|
|
}
|
|
|
|
thread_local! {
|
|
/// Does hero hold exactly one pair in the decision being made (`set_ueberbet_hand`)?
|
|
static UEBERBET_HAND: std::cell::Cell<bool> = const { std::cell::Cell::new(true) };
|
|
}
|
|
|
|
/// Set per postflop decision (`engine::decide`): whether hero holds exactly one pair (a board-pair
|
|
/// "two pair" counts as one). The `flusspaar*` modes act only then.
|
|
pub fn set_ueberbet_hand(one_pair: bool) {
|
|
UEBERBET_HAND.with(|c| c.set(one_pair));
|
|
}
|
|
|
|
fn ueberbet() -> Option<Ueberbet> {
|
|
use std::sync::OnceLock;
|
|
static CFG: OnceLock<Option<Ueberbet>> = OnceLock::new();
|
|
*CFG.get_or_init(|| {
|
|
let u = |jam, river_only, pair_only| Some(Ueberbet { cap: 1.0, jam, river_only, pair_only });
|
|
match std::env::var("UEBERBET").as_deref() {
|
|
Ok("1") => u(false, false, false),
|
|
Ok("jam") => u(true, false, false),
|
|
Ok("fluss") => u(false, true, false),
|
|
Ok("flussjam") => u(true, true, false),
|
|
Ok("flusspaar") => u(false, true, true),
|
|
Ok("flusspaarjam") => u(true, true, true),
|
|
Ok(v) => v.parse::<f64>().ok().filter(|c| c.is_finite() && *c > 0.0).map(|cap| Ueberbet { cap, jam: false, river_only: false, pair_only: false }),
|
|
Err(_) => None,
|
|
}
|
|
})
|
|
}
|
|
|
|
/// The `UEBERBET` fold cap on `street` (`None`: street unknown - only the all-street modes apply).
|
|
pub fn ueberbet_cap_on(street: Option<Street>) -> Option<f64> {
|
|
ueberbet()
|
|
.filter(|u| !u.river_only || street == Some(Street::River))
|
|
.filter(|u| !u.pair_only || UEBERBET_HAND.with(|c| c.get()))
|
|
.map(|u| u.cap)
|
|
}
|
|
|
|
/// Is `UEBERBET` on at all (any street)?
|
|
pub fn ueberbet_cap() -> Option<f64> {
|
|
ueberbet().map(|u| u.cap)
|
|
}
|
|
|
|
/// `UEBERBET=jam`: as `1`, and a heads-up all-in of at least `UEBERBET_JAM_RATIO` pots is priced
|
|
/// against the top of the range too (leak finder 17.11.: river jams with one pair at 0.5-1x pot, the
|
|
/// `REST_STACK` jams, are the biggest live remainder; NL2 calls them 7 of 10). Heads-up only: against
|
|
/// two ranges the top model is far too pessimistic (top trips 0.13 in 179095600052).
|
|
pub fn ueberbet_jam() -> bool {
|
|
ueberbet().is_some_and(|u| u.jam)
|
|
}
|
|
|
|
/// Smallest all-in (pressure, pots) `UEBERBET=jam` prices against the top of the range.
|
|
pub const UEBERBET_JAM_RATIO: f64 = 0.5;
|
|
|
|
/// Pressure from which `UEBERBET` prices the callers as the top of the range.
|
|
pub const UEBERBET_TOP_RATIO: f64 = 1.0;
|
|
|
|
/// P(fold) to a bet of `ratio` pots from a fold base `f` (the reference-size fold rate).
|
|
/// Schalter `RAISE_FOLD_DECKEL=1` (17.11., Gedaechtnis an den Kern; einmal gelesen): wird der Gegner nach seinem
|
|
/// Einsatz geraist, gilt hoechstens die Pool-Foldrate `DEFAULT_FOLD_TO_BET` als Basis. foldToBet misst die Antwort
|
|
/// auf einen Einsatz, bevor der Gegner Staerke zeigte; ein Setzer gibt einem Raise nicht so viel auf. Das volle
|
|
/// Gedaechtnis las nemesis-1 auf 0,70 statt 0,56 (HUD) und semibluffte in seine Einsaetze (-0,97 bb/100).
|
|
pub fn raise_fold_deckel() -> bool {
|
|
use std::sync::OnceLock;
|
|
static AN: OnceLock<bool> = OnceLock::new();
|
|
*AN.get_or_init(|| std::env::var("RAISE_FOLD_DECKEL").as_deref() == Ok("1"))
|
|
}
|
|
|
|
pub fn sized_fold(f: f64, ratio: f64, facing_raise: bool) -> f64 {
|
|
sized_fold_on(f, ratio, facing_raise, None)
|
|
}
|
|
|
|
/// `sized_fold` with the street known (the river-only `UEBERBET` modes need it).
|
|
pub fn sized_fold_on(f: f64, ratio: f64, facing_raise: bool, street: Option<Street>) -> f64 {
|
|
let f = if facing_raise && raise_fold_deckel() && !f.is_nan() { f.min(DEFAULT_FOLD_TO_BET) } else { f };
|
|
let ratio = if ratio.is_nan() { 0.0 } else { ratio.max(0.0) };
|
|
let ratio = match ueberbet_cap_on(street) {
|
|
Some(cap) => ratio.min(cap),
|
|
None => ratio,
|
|
};
|
|
let sized = if f >= 1.0 {
|
|
if ratio > 0.0 { 1.0 } else { 0.0 }
|
|
} else {
|
|
1.0 - (1.0 - f).powf(ratio / REFERENCE_RATIO)
|
|
};
|
|
let raised = if facing_raise { sized * RAISE_RESISTANCE } else { sized };
|
|
if raised.is_nan() { 0.0 } else { raised.clamp(0.0, MAX_FOLD) }
|
|
}
|