Files
pokerfreak/src/engine/size_policy.rs
T
mmintelandClaude Opus 5.5 5739e52bf0 Eigene Wetten: Kandidat UEBERWERT (River-Value >= 0,90 -> 2x Pot, aus), Tor gegen main 5b706670
- src/engine/ueberwert.rs: exaktes River-Perzentil, nur HU, offener Topf, Value, 2x Pot unter dem Stapel
- Merge main 5b706670 (BETTOR, VORFLOP_BAND, VETO_AB=0.9, VORFLOP_POP), UEBERWERT in BEKANNTE_SCHALTER
- Tor: aus bitgleich; Pflichtfaelle bestanden; echte Spots +0,66 bb/100 [+15 781; +20 427 bb];
  LBR bitgleich; Leiter-Warnsignal (Sim polar/reg/tanker) auf echten Regs widerlegt
- WETT_KURVE abgeschlossen: Sim Pool +1,08 und Leiter +1,50 Gewinner, LBR bitgleich
- beide zusammen +0,71 bb/100; nicht live, Wechselpunkt Orchestrator (messung/eigene_wetten/TOR.md)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 13:25:19 +01:00

252 lines
12 KiB
Rust

//! Which raise sizes a postflop raise may use: the commitment ladder, the size bands per
//! kind of raise, pot control and the stack bands. Pure; every size comes from
//! `sizing::candidates` (so from `allowedSizes` when given), never from outside it.
//!
//! | rule | value |
//! |---|---|
//! | ladder (SPR = effective stack / pot) | SPR > 6: three streets, 3 to 6: two streets, under 3: one (commit) |
//! | ladder size | `f = ((2 SPR + 1)^(1/n) - 1) / 2` pots per street, so `n` equal bets empty the stack by the river |
//! | value | 60 to 75 % of the pot, clamped around the ladder size |
//! | semibluff, bluff | 33 to 50 % of the pot |
//! | slack | sizes within the band times 0.8 to 1.25 are all kept (plus the one nearest to the target); the EV picks |
//! | raise over a bet | no band: the EV picks among sizes up to 1.25 pots |
//! | nuts (monster, share >= 0.85, turn or river) | may overbet, 75 to 125 % |
//! | street | flop bands times 0.8, turn times 0.9, river times 1 |
//! | pot control | medium hand: small band (as bluffs); deeper than 150 bb every value hand short of a monster: 45 to 60 % |
//! | stack bands | up to 15 bb push/fold (preflop); 15 to 40 bb sizes times 0.85 and speculative calls cost 0.02 more; 40 to 150 bb standard; over 150 bb pot control |
//! | thin stack-offs | a raise or call of 60 % of the stack or more needs a strong hand or a share of 0.75 (a call: 0.04 more margin for a medium hand) |
//! | no man's land (`REST_STACK=1`) | a raise that, called, leaves under 0.5 pot behind: all-in instead with a strong hand or share 0.75, else dropped |
use super::bluff::RaiseKind;
use crate::exploit::table_fold::pressure_ratio;
use crate::game::{Spot, Street};
use crate::preflop::effective_stack::effective_stack_bb;
use crate::read::hand_read::HandRead;
use crate::read::tier::{tier, Tier};
use crate::sizing::candidates::candidates;
/// Above this SPR three streets are left to put the stack in.
pub const THREE_STREET_SPR: f64 = 6.0;
/// From this SPR up two streets; below it the stack goes in at once.
pub const TWO_STREET_SPR: f64 = 3.0;
/// Pot-fraction bands (low, high).
pub const VALUE_BAND: (f64, f64) = (0.60, 0.75);
pub const BLUFF_BAND: (f64, f64) = (0.33, 0.50);
pub const NUT_BAND: (f64, f64) = (0.75, 1.25);
pub const DEEP_VALUE_BAND: (f64, f64) = (0.45, 0.60);
/// Band factor per street (flop, turn, river).
pub const STREET_FACTOR: [f64; 3] = [0.8, 0.9, 1.0];
/// A size within `band * slack` is still allowed (low, high); the EV chooses among them.
pub const BAND_SLACK: (f64, f64) = (0.8, 1.25);
/// Share from which a monster may overbet.
pub const NUT_SHARE: f64 = 0.85;
/// Largest pot fraction any non-committed raise may use.
pub const MAX_FRACTION: f64 = 1.25;
/// Stack bands in big blinds.
pub const SHORT_STACK_BB: f64 = 40.0;
pub const DEEP_STACK_BB: f64 = 150.0;
pub const SHORT_SIZE_FACTOR: f64 = 0.85;
pub const SHORT_SPECULATIVE_MARGIN: f64 = 0.02;
/// A raise or call this share of the stack (or more) is a stack-off.
pub const STACK_OFF_SHARE: f64 = 0.6;
pub const THIN_STACK_OFF_SHARE_NEEDED: f64 = 0.75;
pub const THIN_STACK_OFF_CALL_MARGIN: f64 = 0.04;
/// Streets that can still be bet, this one included.
fn streets_left(street: Street) -> i32 {
match street {
Street::Preflop | Street::Flop => 3,
Street::Turn => 2,
Street::River => 1,
}
}
fn street_factor(street: Street) -> f64 {
STREET_FACTOR[(street as usize).clamp(1, 3) - 1]
}
/// Effective stack over the pot after calling.
pub fn spr(spot: &Spot) -> f64 {
let stack = effective_stack_bb(spot) * spot.big_blind;
let pot = spot.pot + spot.to_call;
if stack.is_finite() && pot > 0.0 { stack / pot } else { f64::INFINITY }
}
/// Streets the ladder spends putting the stack in.
pub fn ladder_streets(spr: f64) -> i32 {
if spr > THREE_STREET_SPR {
3
} else if spr >= TWO_STREET_SPR {
2
} else {
1
}
}
/// Pot fraction per bet so that `n` equal bets, each called, put `spr` pots in.
pub fn ladder_fraction(spr: f64, n: i32) -> f64 {
((2.0 * spr + 1.0).powf(1.0 / f64::from(n.max(1))) - 1.0) / 2.0
}
fn depth_bb(spot: &Spot) -> f64 {
effective_stack_bb(spot)
}
/// Stack-off: this much of hero's stack goes in with `to` (raise-to or call).
pub fn is_stack_off(spot: &Spot, to: f64) -> bool {
spot.hero_stack > 0.0 && to >= STACK_OFF_SHARE * spot.hero_stack
}
/// Extra call margin for the hand and the stack depth: a thin stack-off with a medium hand,
/// and speculative (weak-tier) calls at 15 to 40 bb.
pub fn extra_call_margin(spot: &Spot, read: &HandRead) -> f64 {
let t = tier(read.made);
let thin = if t == Tier::Medium && is_stack_off(spot, spot.to_call) { THIN_STACK_OFF_CALL_MARGIN } else { 0.0 };
let depth = depth_bb(spot);
let speculative = if t == Tier::Weak && spot.to_call > 0.0 && depth < SHORT_STACK_BB { SHORT_SPECULATIVE_MARGIN } else { 0.0 };
thin + speculative
}
/// The pot-fraction band for this raise.
fn band(spot: &Spot, kind: RaiseKind, share: f64, read: &HandRead) -> (f64, f64) {
let t = tier(read.made);
let late = spot.street != Street::Flop;
// ANGRIFF_FOLD against a style-less fold read: bluffs and semibluffs may also take the value sizes,
// where the read's fold chance applies in full (a small bet is folded less, `exploit::fold_chance`);
// the EV picks the size.
let fold_read = super::read_gate::fold_attack_enabled()
&& spot.live_villains().any(|v| v.profile.is_some_and(|p| p.fold_only));
let base = match kind {
RaiseKind::Semibluff | RaiseKind::Bluff if fold_read => (BLUFF_BAND.0, VALUE_BAND.1),
// CBET_LUFT=..,gross: a c-bet/stab bluff may take the value sizes, the EV picks.
RaiseKind::Bluff if super::cbet_luft::applies(spot).is_some_and(|m| m.wide) => (BLUFF_BAND.0, VALUE_BAND.1),
RaiseKind::Semibluff | RaiseKind::Bluff | RaiseKind::ThinValue => BLUFF_BAND,
RaiseKind::Value if t == Tier::Medium => BLUFF_BAND,
RaiseKind::Value if t == Tier::Monster && late && share >= NUT_SHARE => NUT_BAND,
RaiseKind::Value if t != Tier::Monster && depth_bb(spot) > DEEP_STACK_BB => DEEP_VALUE_BAND,
RaiseKind::Value => VALUE_BAND,
};
let f = street_factor(spot.street)
* if depth_bb(spot) < SHORT_STACK_BB { SHORT_SIZE_FACTOR } else { 1.0 };
(base.0 * f, base.1 * f)
}
/// The raise-to sizes this raise may use: the usable size nearest to the target pot
/// fraction (ladder size clamped into the band), plus the largest size when the stack goes
/// in anyway (value, SPR under 3). Thin stack-offs are removed. May be empty.
pub fn sizes(spot: &Spot, kind: RaiseKind, share: f64, read: &HandRead) -> Vec<f64> {
// UEBERWERT (aus = bitgleich): River-Value ab Perzentil p heads-up mit fester Overbet-Groesse.
if let Some(to) = super::ueberwert::groesse(spot, kind) {
return vec![to];
}
let all = candidates(spot);
let (lo, hi) = band(spot, kind, share, read);
let s = spr(spot);
let n = ladder_streets(s).min(streets_left(spot.street));
let target = ladder_fraction(s, n).clamp(lo, hi);
let fraction = |to: f64| pressure_ratio(spot.pot, spot.to_call, to);
let committed = kind == RaiseKind::Value && s < TWO_STREET_SPR;
let cap = if hi > VALUE_BAND.1 { MAX_FRACTION } else { hi * 1.5 };
let within: Vec<f64> = all.iter().copied().filter(|to| fraction(*to) <= cap).collect();
// No size fits the cap (only big raises allowed): the smallest legal one.
let within = if within.is_empty() { all.first().copied().into_iter().collect() } else { within };
let mut picked: Vec<f64> = if spot.to_call > 0.0 {
// Raising over a bet: the bands are for bets; the EV picks among the sizes up to MAX_FRACTION.
all.iter().copied().filter(|to| fraction(*to) <= MAX_FRACTION).collect()
} else {
// Every size inside the band (with slack), and the one nearest to the target; the EV picks.
let nearest = within
.iter()
.copied()
.min_by(|a, b| (fraction(*a) - target).abs().total_cmp(&(fraction(*b) - target).abs()));
within
.iter()
.copied()
.filter(|to| (lo * BAND_SLACK.0..=hi * BAND_SLACK.1).contains(&fraction(*to)))
.chain(nearest)
.collect()
};
if committed {
picked.extend(all.last().copied());
}
picked.sort_by(f64::total_cmp);
picked.dedup();
let strong = tier(read.made) >= Tier::Strong || share >= THIN_STACK_OFF_SHARE_NEEDED;
picked.retain(|to| strong || !is_stack_off(spot, *to));
match rest_stack_mode() {
0 => {}
mode => {
// `streng`: facing a raise on this street (a raise war) the tier alone does not carry a
// stack-off, only the share does (live hand 178493100165: top pair "strong", 0.62 against
// the raise, 0.39 against the shove).
let faced_raise = mode == 2 && villain_raised_this_street(spot);
let commit = if faced_raise { share >= THIN_STACK_OFF_SHARE_NEEDED } else { strong };
picked = no_mans_land(spot, picked, commit);
}
}
picked
}
/// Below this stack-to-pot ratio after a called raise the raiser is committed: against a shove of the
/// rest `r` into the pot `p` the call needs equity `r / (p + 2r)`, at `r = 0.5 p` exactly 25 %, which
/// any pair or draw holds against a value range. So such a raise is a stack-off in effect.
pub const REST_STACK_SPR: f64 = 0.5;
/// Messschalter `REST_STACK` (einmal gelesen): `1` = 1, `streng` = 2, sonst aus (bitgleich).
fn rest_stack_mode() -> u8 {
use std::sync::OnceLock;
static MODE: OnceLock<u8> = OnceLock::new();
*MODE.get_or_init(|| match std::env::var("REST_STACK").as_deref() {
Ok("1") => 1,
Ok("streng") => 2,
_ => 0,
})
}
/// Hero faces a raise: some villain raised over an earlier bet on this street.
fn villain_raised_this_street(spot: &Spot) -> bool {
let mut bets = spot.history.iter().filter(|r| r.street == spot.street && r.action.is_aggressive());
spot.to_call > 0.0 && bets.next().is_some() && bets.next().is_some()
}
/// Stack behind after a raise to `to` is called (effective stack, so a raise that already covers the
/// villain leaves nothing), and the pot then.
fn rest_after(spot: &Spot, to: f64) -> (f64, f64) {
let eff = (effective_stack_bb(spot) * spot.big_blind).min(spot.hero_stack);
let pot = crate::odds::ev::final_pot(spot.pot, spot.to_call, to);
((eff - to).max(0.0), pot)
}
/// A raise in no man's land: if called, less than `REST_STACK_SPR` pots stay behind, but not nothing.
pub fn in_no_mans_land(spot: &Spot, to: f64) -> bool {
let (rest, pot) = rest_after(spot, to);
rest > 1e-9 && pot > 0.0 && rest < REST_STACK_SPR * pot
}
/// Live hand 178493100165 (-97,5 BB): a re-raise to 58 % of the stack slipped under the stack-off
/// share, left ~0,5 pot behind, villain shoved, hero had to call. Such a size is a stack-off: with a
/// strong hand (or share >= 0.75) the all-in replaces it; otherwise it is dropped (call/fold remain).
fn no_mans_land(spot: &Spot, picked: Vec<f64>, strong: bool) -> Vec<f64> {
if !picked.iter().any(|to| in_no_mans_land(spot, *to)) {
return picked;
}
let shove = all_in_size(spot);
let mut out: Vec<f64> = picked.into_iter().filter(|to| !in_no_mans_land(spot, *to)).collect();
if strong {
out.extend(shove);
}
out.sort_by(f64::total_cmp);
out.dedup();
out
}
/// The legal all-in raise-to: the upper bound without a size menu; with one, its largest size when
/// that puts the stack in.
fn all_in_size(spot: &Spot) -> Option<f64> {
let hi = crate::sizing::bounds::bounds(spot)?.hi;
match &spot.allowed_sizes {
None => (hi.is_finite() && hi >= spot.hero_stack - 1e-9).then_some(hi),
Some(_) => candidates(spot).last().copied().filter(|to| *to >= spot.hero_stack - 1e-9),
}
}