Files
pokerfreak/src/engine/postflop.rs
T
mmintel 55dff14ac2 Postflop: knappe Fold-oder-Call-Spots entschlossen statt ABSTAIN (Owner 8.11.)
Eine Weltklasse-Engine entscheidet jeden knappen Spot selbst. Das alte
Unsicherheitsband um den Breakpoint gab ABSTAIN zurueck -> live FOLD und
foldete so die rausch-nahe +EV-Call-SEITE weg (Overfold, bes. Flop/Turn
mit grossem std_error; PLO5-Benchmark-Defekt). Der call_margin bleibt die
Call-Schwelle (scored erzwingt sie); nur die Enthaltung faellt weg, der
EV-maximale winner entscheidet. Das marginale Raise-Band (Spew-Schutz)
und der Invalid-Equity-ABSTAIN bleiben.

Verifiziert: Cash-Benchmark +2.06 bb/100 'nicht unterscheidbar' (keine
Regression), PLO5-Benchmark rc 1->0 (Defekt behoben), River-Sonde 0 Leck,
engine_choose_postflop/engine_uncertainty gruen, AoF/Kurzstack 40 gruen.
Pre-existing reds unberuehrt (cfr_multi Chart-Drift; pipeline_tournament +
icm_bubble = ICM-Defense-Verengung flippt auf CFR-FacingJam-Spots 0 Haende,
eigener Hebel).
2026-11-08 09:25:03 +01:00

170 lines
7.2 KiB
Rust

use super::bluff::RaiseKind;
use super::called::Called;
use super::effective::{effective, Effective};
use super::options::{action_evs, passive_ev, scored, Scored};
use super::passive::cheapest_continue;
use super::read_label::describe;
use super::uncertainty::abstain_confidence;
use crate::equity::estimate::Estimate;
use crate::exploit::thresholds::Thresholds;
use crate::game::{ActionKind, Choice, Decision, Spot};
use crate::odds::{break_even::break_even, ev};
use crate::read::hand_read::HandRead;
fn label(choice: Choice, kind: Option<RaiseKind>) -> String {
match (choice, kind) {
(Choice::Raise { to }, Some(RaiseKind::Semibluff)) => format!("semibluff raise to {to:.2}"),
(Choice::Raise { to }, Some(RaiseKind::Bluff)) => format!("bluff raise to {to:.2}"),
(Choice::Raise { to }, Some(RaiseKind::ThinValue)) => format!("thin value raise to {to:.2}"),
(Choice::Raise { to }, _) => format!("raise to {to:.2}"),
(other, _) => other.name().to_lowercase(),
}
}
/// Highest EV wins; the first of equals wins (options are ordered passive first).
fn best(options: &[Scored]) -> Option<Scored> {
options.iter().copied().fold(None, |acc, s| match acc {
Some(b) if b.ev >= s.ev => Some(b),
_ => Some(s),
})
}
/// EV lead of the winner over the next-best alternative, counting folding (0) and the
/// call it passed up.
fn lead(spot: &Spot, share: f64, options: &[Scored], winner: Scored) -> f64 {
let rivals = options
.iter()
.filter(|s| s.choice != winner.choice)
.map(|s| s.ev)
.chain((winner.choice != Choice::Fold).then(ev::fold))
.chain(
(winner.choice == Choice::Fold && spot.is_legal(ActionKind::Call))
.then(|| ev::call(share, spot.pot, spot.to_call)),
);
rivals
.fold(None, |m: Option<f64>, x| Some(m.map_or(x, |m| m.max(x))))
.map_or(winner.ev.abs(), |r| winner.ev - r)
}
fn confidence(spot: &Spot, gap: f64) -> f64 {
let scale = (spot.pot + spot.to_call).max(spot.big_blind).max(f64::MIN_POSITIVE);
0.5 + 0.5 * (4.0 * gap.max(0.0) / scale).tanh()
}
/// Opening of every reason: the read, plus the player count when multiway.
fn headline(read: &HandRead, eff: &Effective) -> String {
if eff.villains > 1 {
format!("{} ({}-way)", describe(read), eff.villains)
} else {
describe(read)
}
}
/// `(lead, error)` when a raise leads the best passive line by less than its own EV
/// standard error, `std_error * final pot` (the money at stake). A negative lead
/// (the passive line is worth more) counts as inside the error.
fn marginal_raise(
spot: &Spot,
eff: &Effective,
estimate: &Estimate,
to: f64,
raise_ev: f64,
) -> Option<(f64, f64)> {
let passive = passive_ev(spot, eff.share)?;
let gap = raise_ev - passive;
let error = estimate.std_error.max(0.0) * ev::final_pot(spot.pot, spot.to_call, to);
(gap < error).then_some((gap, error))
}
/// `choose_postflop_with` when nothing is known about the calling range: the whole
/// range calls, so the called branch uses the overall share.
pub fn choose_postflop(
spot: &Spot,
estimate: &Estimate,
thresholds: &Thresholds,
read: &HandRead,
) -> Decision {
choose_postflop_with(spot, estimate, &Called::flat(estimate.share), thresholds, read)
}
/// The rule for a postflop spot, given an equity estimate, the share against the
/// calling range per raise size (`called`) and the hand read.
///
/// 1. Invalid equity: ABSTAIN with confidence 0.
/// 2. `effective` (texture stance x multiway) gives the realised share, call margin,
/// value threshold and which raises are allowed.
/// 3. Score check / call / fold / value raises / semibluffs / bluffs (`options::scored`,
/// raises over two branches: fold and called) and take the maximum EV. Never folds
/// when check is legal.
/// 4. Uncertainty: facing fold-or-call with `|share - (break-even + call margin)| <
/// abstain_band + 2 * std_error`, or a winning raise whose EV lead over the best
/// passive line is below `std_error * final pot`: ABSTAIN with a small confidence
/// (0.05..0.30, `uncertainty::abstain_confidence`).
/// 5. Otherwise `confidence` rises with the EV lead over the runner-up, relative to the pot.
pub fn choose_postflop_with(
spot: &Spot,
estimate: &Estimate,
called: &Called,
thresholds: &Thresholds,
read: &HandRead,
) -> Decision {
let raw = estimate.share;
if !(raw.is_finite() && (0.0..=1.0).contains(&raw)) {
return Decision::abstain("equity unavailable");
}
let eff = effective(spot, raw, thresholds, read);
let share = eff.share;
let be = break_even(spot.pot, spot.to_call);
let head = headline(read, &eff);
let options = scored(spot, &eff, thresholds, read, called);
let winner = best(&options);
let priced = |decision: Decision| decision.with_evs(action_evs(spot, share, &options));
// Weltklasse-Linie (Owner 8.11.): die Engine ENTSCHEIDET jeden knappen Fold-oder-Call-Spot selbst
// (Call iff `share >= break-even + call_margin`, das `scored` erzwingt; sonst Fold) statt sich
// im Unsicherheitsband um den Breakpoint zu enthalten. Das alte Band gab ABSTAIN zurueck -> live
// Fold, und foldete so die rausch-nahe +EV-Call-SEITE weg (Overfold-Leak, besonders Flop/Turn mit
// grossem std_error; PLO5-Benchmark-Defekt). Der `call_margin` bleibt unveraendert die Call-
// Schwelle - nur die Enthaltung faellt weg, der `winner` (EV-Maximum) entscheidet. Das MARGINALE
// Raise-Band unten (Spew-Schutz gegen Fold-Equity-Raises) bleibt.
if let Some(Scored { choice: Choice::Raise { to }, ev: raise_ev, kind }) = winner {
// A value raise stays a raise inside its error: the hand is strong enough on its own
// account, the lead only says how much better than checking it is. Only the raises
// that on fold equity (semibluff, bluff) are held back by the error.
let held = kind != Some(RaiseKind::Value);
if let Some((gap, error)) = held.then(|| marginal_raise(spot, &eff, estimate, to, raise_ev)).flatten() {
return priced(Decision::new(
Choice::Abstain,
abstain_confidence(gap, error),
format!("{head}: raise EV lead {gap:+.2} inside its error {error:.2}"),
));
}
}
priced(match winner {
Some(w) => {
let shown = match w.choice {
Choice::Fold => ev::call(share, spot.pot, spot.to_call),
_ => w.ev,
};
let name = match w.choice {
Choice::Fold => "call".to_string(),
other => label(other, w.kind),
};
Decision::new(
w.choice,
confidence(spot, lead(spot, share, &options, w)),
format!("{head}: equity {raw:.2} vs break-even {be:.2}, EV {name} {shown:+.2}"),
)
}
None => match cheapest_continue(spot) {
Some(choice) => Decision::new(
choice,
0.5,
format!("{head}: equity {raw:.2} vs break-even {be:.2}, only continuing action available"),
),
None => Decision::abstain("no actionable option"),
},
})
}