use super::bluff::{ bluff_catch_blocked, branches, branches_vs_raise, check_raise_rate, is_bluff_hand, never_folds, RaiseKind, PURE_BLUFF_EDGE, PURE_BLUFF_MIN_FOLD, }; use super::called::Called; use super::effective::Effective; use super::multiway::{extra_value_raise, realized_share}; use super::semibluff::has_real_draw; use super::thin_value::thin_value; use crate::exploit::table_fold::table_fold; use crate::exploit::thresholds::Thresholds; use crate::game::{ActionKind, Choice, Spot}; use crate::odds::{break_even::break_even, ev}; use crate::read::hand_read::HandRead; use crate::read::made::Made; use crate::read::suit_pattern::SuitPattern; use crate::read::tier::{tier, Tier}; use super::size_policy::{extra_call_margin, sizes}; /// A legal choice with its expected value in chips (relative to folding now). #[derive(Clone, Copy, Debug, PartialEq)] pub struct Scored { pub choice: Choice, pub ev: f64, /// Why, for raises; `None` for passive choices. pub kind: Option, } /// Share of its equity a free check keeps: whoever checks gives up the initiative, lets /// the villain bet or take a free card and cannot charge the worse hands that call. A bet /// that is called by worse hands beats a check that is worth the same on paper. pub const CHECK_REALIZATION: f64 = 0.90; /// EV of checking for free: the share of the pot, discounted by [`CHECK_REALIZATION`]. pub fn check_ev(share: f64, pot: f64) -> f64 { CHECK_REALIZATION * ev::check(share, pot) } /// EV of the best non-raising line, ignoring the call margin: check when free, the raw /// call EV, folding (0) when check is not available. `None` when none is legal. pub fn passive_ev(spot: &Spot, share: f64) -> Option { let free = spot.is_legal(ActionKind::Check); let check = free.then(|| check_ev(share, spot.pot)); let call = spot.is_legal(ActionKind::Call).then(|| ev::call(share, spot.pot, spot.to_call)); let fold = (spot.is_legal(ActionKind::Fold) && !free).then(ev::fold); [check, call, fold].into_iter().flatten().filter(|x| x.is_finite()).reduce(f64::max) } /// EV of every line that can be priced, for comparing a human's choice: the passive lines /// raw (a call the rule rejects still has a price) plus the raises the rule kept. pub fn action_evs(spot: &Spot, share: f64, options: &[Scored]) -> Vec<(Choice, f64)> { let free = spot.is_legal(ActionKind::Check); let check = free.then(|| (Choice::Check, check_ev(share, spot.pot))); let call = spot .is_legal(ActionKind::Call) .then(|| (Choice::Call, ev::call(share, spot.pot, spot.to_call))); let fold = (spot.is_legal(ActionKind::Fold) && !free).then(|| (Choice::Fold, ev::fold())); let raises = options .iter() .filter(|o| matches!(o.choice, Choice::Raise { .. })) .map(|o| (o.choice, o.ev)); check.into_iter().chain(call).chain(fold).chain(raises).filter(|(_, ev)| ev.is_finite()).collect() } /// Part of the multiway rise of the value threshold (`multiway::extra_value_raise`) that is /// given back. The equity share is already the share against all villains and already /// discounted (`realized_share`), so the full rise counted the crowd twice and kept top /// pair from betting two-way. pub const MULTIWAY_VALUE_RELIEF: f64 = 0.5; /// A raise is a value raise when the read allows it and the realised share clears the /// effective value threshold (less `MULTIWAY_VALUE_RELIEF` of the multiway rise). pub fn is_value_raise(eff: &Effective) -> bool { let bar = eff.value_raise - MULTIWAY_VALUE_RELIEF * extra_value_raise(eff.villains); eff.raise_ok && eff.value_ok && eff.share >= bar } /// Messschalter (einmal gelesen) `FLUSS_WERT=1`: river, checked to hero, trips or better /// (`Tier::Monster`) always gets its value bet scored. Without it the bet is only offered when the /// share against the WHOLE range clears the value bar (0.58 plus the multiway rise); trips with a /// share of 0.46..0.54 there never had a bet option at all, the check won uncontested (live 16.11.: /// 178903200610, 179095600052, 178908100701). With it the bet is priced against the calling /// range per size (`called`) and wins only on its EV over the check. pub fn fluss_wert_on() -> bool { use std::sync::OnceLock; static ON: OnceLock = OnceLock::new(); *ON.get_or_init(|| std::env::var("FLUSS_WERT").as_deref() == Ok("1")) } /// River monster checked to hero (`FLUSS_WERT=1`): may bet for value, the EV decides. Not a /// straight or worse on a four-flush board: the called range there is the flushes (178870300411). fn river_monster(spot: &Spot, eff: &Effective, read: &HandRead) -> bool { fluss_wert_on() && spot.street == crate::game::Street::River && spot.is_legal(ActionKind::Check) && eff.raise_ok && eff.value_ok && tier(read.made) == Tier::Monster && !(read.texture.suits == SuitPattern::FourFlush && read.made < Made::Flush) } /// Messschalter (einmal gelesen) `PAAR_RAISE`: the value raise of a one-pair hand FACING a bet. /// Live NL2 (4430 hands, 16.11.): the open block of lost big pots is one pair raising a bet and /// then stacking off (KQ/AQ top pair, A5 top pair on the turn, JJ overpair on the river: -352 BB). /// The raise is valued over fold and call only; the villain's re-raise - near-nuts at the micros - /// and hero's pot-odds call-off are not in it. /// * `nie`: no value raise for one pair facing a bet (it calls or folds on its EV); /// * `antwort`: the raise keeps its value kind but is valued with the re-raise branch /// (`bluff::branches_vs_raise`, re-raise rate = the bettor's `reraise_to_raise` read, else the pool /// `RAISE_TO_BET_POOL`; hero calls the re-raise only when its bluffs pay). /// Anything else is off (bit-identical). /// * `passiv` / `passiv:`: like `nie`, but only when every live villain reads passive: shrunk /// aggression below `x` (default `PAAR_PASSIV_AGGRESSION`) and a raise-facing-a-bet read not above the /// pool. An unread villain carries the population prior (aggression 0.35, raise 0.30) and so counts as /// passive - the micro pool. Against an aggressive read (maniac, nemesis-2: both arms `nie` and /// `antwort` lost there, -18 / -9 bb/100) the one-pair raise stays as today. #[derive(Clone, Copy, Debug, PartialEq)] pub enum PaarRaise { Nie, Antwort, Passiv(f64), /// `gelesen`: like `passiv`, but an unread villain (no raw profile) keeps the raise as today. Gelesen(f64), } /// Aggression at and above which a villain is not passive (`style::STATION_MAX_AGGRESSION`). pub const PAAR_PASSIV_AGGRESSION: f64 = 0.45; thread_local! { /// The UNGATED reads of the running decision by seat (`note_paar_raw`): `read_gate::gate_reads` /// drops exactly the aggressive reads (LAG, maniac: no earned trust) to `None`, so on the gated /// spot every aggressor would look unread and count as passive. static PAAR_ROH: std::cell::RefCell> = const { std::cell::RefCell::new(Vec::new()) }; } /// Called by `decide_one` before the read gate: remembers the raw reads for `PAAR_RAISE=passiv`. /// A no-op for every other mode. pub fn note_paar_raw(raw: &Spot) { if !matches!(paar_raise(), Some(PaarRaise::Passiv(_) | PaarRaise::Gelesen(_))) && !matches!(super::called_equity::called_jam_mode(), 2 | 3) { return; } let kept = raw.villains.iter().filter_map(|v| v.profile.map(|p| (v.seat, p))).collect(); PAAR_ROH.with(|x| *x.borrow_mut() = kept); } /// Every live villain reads passive on his RAW read (see `PaarRaise::Passiv`). /// Every live villain has a raw read whose fold-to-bet is at least `fold` (`CALLED_JAM=gelesen`). pub fn all_read_folding(spot: &Spot, fold: f64) -> bool { let raw = PAAR_ROH.with(|x| x.borrow().clone()); spot.live_villains().all(|v| { raw.iter() .find(|(seat, _)| *seat == v.seat) .and_then(|(_, p)| p.fold_to_bet) .is_some_and(|f| f.is_finite() && f >= fold) }) } /// Some live villain has a raw read that folds to a bet less than `fold` (a calling station). pub fn any_read_station(spot: &Spot, fold: f64) -> bool { let raw = PAAR_ROH.with(|x| x.borrow().clone()); spot.live_villains().any(|v| { raw.iter() .find(|(seat, _)| *seat == v.seat) .and_then(|(_, p)| p.fold_to_bet) .is_some_and(|f| f.is_finite() && f < fold) }) } /// With `need_read` an unread villain (no raw profile) is not passive. fn all_passive(spot: &Spot, bar: f64, need_read: bool) -> bool { use crate::exploit::street_continuation::RAISE_TO_BET_POOL; let raw = PAAR_ROH.with(|x| x.borrow().clone()); spot.live_villains().all(|v| { let profile = raw.iter().find(|(seat, _)| *seat == v.seat).map(|(_, p)| *p); if need_read && profile.is_none() { return false; } // Nur Flop/Turn: am River fuehrte die Freigabe zu Paar-Raises auf 2x Pot (Pflichtfaelle // 177113202312 JJ, 177689800544 AQ: CALL -> RAISE 2P, das Overbet-Leck); dort bleibt der Riegel wie live. let aggr = if crate::exploit::sample::info_konsistent_paar() && spot.street != crate::game::Street::River { // Posterior-Lesart: der Teil ohne Stichprobe steht auf der Schwelle (= nicht passiv, wie blind). profile.and_then(|p| crate::exploit::sample::aggression_at(&p, bar)).unwrap_or(bar) } else { profile.and_then(|p| p.aggression).filter(|x| x.is_finite()).unwrap_or(0.35) }; let raise = profile.and_then(|p| p.raise_to_bet).filter(|x| x.is_finite()).unwrap_or(RAISE_TO_BET_POOL); aggr < bar && raise <= RAISE_TO_BET_POOL + 1e-9 }) } /// `STATION_ZUG=1` (17.11., Gedaechtnis an den Kern): gegen einen Gegner, der nie foldet (`never_folds`), /// war jeder Semibluff gesperrt - ein echter Draw wurde gecheckt. Der volle Gedaechtnis-Read macht aus /// jeder Station so einen Gegner (fold 0,002), der Live-Draht (fold 0,25) nicht: Station -9,7 bb/100, fast /// ganz aus gecheckten Flop-/Turn-Draws (`gedaechtnis_station`). Mit dem Schalter darf ein Draw auch gegen /// den Nie-Folder setzen, wenn der Einsatz mit allen Callern (Fold-Ast 0) mehr bringt als der passive Weg. pub fn station_zug() -> bool { use std::sync::OnceLock; static AN: OnceLock = OnceLock::new(); *AN.get_or_init(|| std::env::var("STATION_ZUG").as_deref() == Ok("1")) } pub fn paar_raise() -> Option { use std::sync::OnceLock; static MODE: OnceLock> = OnceLock::new(); *MODE.get_or_init(|| match std::env::var("PAAR_RAISE").as_deref() { Ok("nie") => Some(PaarRaise::Nie), Ok("antwort") => Some(PaarRaise::Antwort), Ok("passiv") => Some(PaarRaise::Passiv(PAAR_PASSIV_AGGRESSION)), Ok("gelesen") => Some(PaarRaise::Gelesen(PAAR_PASSIV_AGGRESSION)), Ok(x) => x .strip_prefix("passiv:") .and_then(|b| b.parse::().ok()) .filter(|b| b.is_finite()) .map(PaarRaise::Passiv), _ => None, }) } /// Exactly one pair: a pair class, or a board-pair "two pair" that is one own pair (`UEBERBET=flusspaar`). pub fn holds_one_pair(spot: &Spot, read: &HandRead) -> bool { matches!( read.made, Made::Underpair | Made::BottomPair | Made::MiddlePair | Made::TopPairWeakKicker | Made::TopPairGoodKicker | Made::Overpair ) || crate::read::hand_read::is_board_pair_two_pair(read.made, &spot.hero_cards, &spot.board) } /// One pair (no two pair or better), facing a bet postflop. fn one_pair_facing_bet(spot: &Spot, read: &HandRead) -> bool { spot.to_call > 0.0 && spot.street != crate::game::Street::Preflop && matches!( read.made, Made::Underpair | Made::BottomPair | Made::MiddlePair | Made::TopPairWeakKicker | Made::TopPairGoodKicker | Made::Overpair ) } /// Re-raise rate of the villains facing hero's raise: the highest `reraise_to_raise` read among the /// live villains, else the pool value. fn reraise_rate(spot: &Spot) -> f64 { use crate::exploit::street_continuation::RAISE_TO_BET_POOL; spot.live_villains() .map(|v| v.profile.and_then(|p| p.reraise_to_raise).filter(|x| x.is_finite()).unwrap_or(RAISE_TO_BET_POOL)) .fold(0.0_f64, f64::max) .clamp(0.0, 1.0) } /// What kind of raise this hand could make here, if any. fn raise_kind(spot: &Spot, eff: &Effective, read: &HandRead) -> Option { let nie = never_folds(spot); let bluffable = eff.raise_ok && !nie; let pair_blocked = match paar_raise() { Some(PaarRaise::Nie) => one_pair_facing_bet(spot, read), Some(PaarRaise::Passiv(bar)) => one_pair_facing_bet(spot, read) && all_passive(spot, bar, false), Some(PaarRaise::Gelesen(bar)) => one_pair_facing_bet(spot, read) && all_passive(spot, bar, true), _ => false, }; if (is_value_raise(eff) && !pair_blocked) || river_monster(spot, eff, read) { Some(RaiseKind::Value) } else if thin_value(eff, read.made, spot.street, spot.is_legal(ActionKind::Check)) { Some(RaiseKind::ThinValue) } else if (bluffable || (eff.raise_ok && nie && station_zug())) && eff.semibluff_ok && has_real_draw(read, spot.street) { Some(RaiseKind::Semibluff) } else if bluffable && eff.villains == 1 && is_bluff_hand(read, spot) { Some(RaiseKind::Bluff) } else { None } } /// Every action the rule lets hero consider, in preference order (passive first, so /// ties keep the cheaper line). With `eff` the effective (texture and multiway /// adjusted) numbers and `share = eff.share`: /// * check, when legal; /// * call, when legal, `share >= break_even + eff.call_margin`, and not a blocked bluff /// catch (`bluff::bluff_catch_blocked`); /// * fold, when legal and check is not; /// * each sizing candidate as a raise, valued over two branches (`bluff::branches`): /// P(all fold) from each villain's profile (`exploit::table_fold`, times /// `fold_equity_scale`) and the share against the calling range (`called`, realised /// for the table size). Kept when /// - it is a value raise (`is_value_raise`), or /// - a thin value bet (`thin_value`: medium hand, turn or river, checked to hero) - like a value /// raise it only wins on its EV (`postflop::best`), but inside its EV error it is held back, or /// - a semibluff (real draw, at most two villains, nobody who never folds) with a /// positive fold branch, EV > 0 and EV above `passive_ev`, or /// - a pure bluff (weak hand, heads-up, nobody who never folds) with P(fold) >= 0.5, /// EV > 0 and EV at least `PURE_BLUFF_EDGE` pots above `passive_ev`. pub fn scored( spot: &Spot, eff: &Effective, thresholds: &Thresholds, read: &HandRead, called: &Called, ) -> Vec { let share = eff.share; let free = spot.is_legal(ActionKind::Check); let be = break_even(spot.pot, spot.to_call); let passive = |choice, ev| Scored { choice, ev, kind: None }; let check = free.then(|| passive(Choice::Check, check_ev(share, spot.pot))); let call = (spot.is_legal(ActionKind::Call) && share >= be + eff.call_margin + extra_call_margin(spot, read) && !bluff_catch_blocked(spot, read)) .then(|| passive(Choice::Call, ev::call(share, spot.pot, spot.to_call))); let fold = (spot.is_legal(ActionKind::Fold) && !free).then(|| passive(Choice::Fold, ev::fold())); let kind = raise_kind(spot, eff, read).filter(|_| spot.is_legal(ActionKind::Raise)); let floor = passive_ev(spot, share).unwrap_or(f64::NEG_INFINITY); let raises = kind.map_or_else(Vec::new, |kind| { let capped = spot.to_call <= 0.0 && spot.street == crate::game::Street::River && crate::read::hand_read::brett_paar_mode() == 3 && crate::read::hand_read::is_board_pair_two_pair(read.made, &spot.hero_cards, &spot.board); sizes(spot, kind, share, read) .into_iter() .filter(|to| !capped || *to <= spot.pot + 1e-9) .filter_map(|to| { let fe = table_fold(spot, to, thresholds.fold_equity_scale); let against = realized_share(called.share_at(to, share), eff.villains); let against = super::fortsetzung::discounted(spot, kind, to, fe, against); let reraised = kind == RaiseKind::Value && paar_raise() == Some(PaarRaise::Antwort) && to < spot.hero_stack && one_pair_facing_bet(spot, read); let b = match (kind, check_raise_rate(spot)) { _ if reraised => { let rho = reraise_rate(spot); branches_vs_raise(spot, to, fe, against, RaiseKind::ThinValue, rho, None) } (RaiseKind::Value, _) | (_, None) => branches(spot, to, fe, against), (k, Some((rho, profile))) => branches_vs_raise(spot, to, fe, against, k, rho, profile.as_ref()), }; let keep = match kind { RaiseKind::Value | RaiseKind::ThinValue => true, RaiseKind::Semibluff => { (b.fold > 0.0 || (station_zug() && never_folds(spot))) && b.total > 0.0 && b.total > floor } RaiseKind::Bluff => { fe >= super::cbet_luft::applies(spot).map_or(PURE_BLUFF_MIN_FOLD, |m| m.min_fold.min(PURE_BLUFF_MIN_FOLD)) && b.total > 0.0 && b.total >= floor + PURE_BLUFF_EDGE * crate::rake::live::net(spot.pot) } }; keep.then_some(Scored { choice: Choice::Raise { to }, ev: b.total, kind: Some(kind) }) }) .collect() }); check .into_iter() .chain(call) .chain(fold) .chain(raises) .filter(|s| s.ev.is_finite()) .collect() }