5 Dateien. Nicht enthalten: 0 Dateien (Bau, Binaer, > 25 MB, archiv/lauf, Spuren echter Haende), 0 Loeschungen nicht nachgezogen. Der Worktree selbst ist unveraendert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
359 lines
16 KiB
Rust
359 lines
16 KiB
Rust
use super::cfr_advice::{cfr_advice, CfrAdvice};
|
||
use super::exploit_border::exploit_border;
|
||
use super::certainty::certainty;
|
||
use super::chart_decision::decide;
|
||
use super::chart_row::ChartRow;
|
||
use super::commit_guard::price_guarded_deep;
|
||
use super::effective_stack::effective_stack_bb;
|
||
use super::full_chart::full_row;
|
||
use super::hand_percentile::percentile;
|
||
use super::plan::{ChartAction, PreflopPlan};
|
||
use super::position::Position;
|
||
use super::seat_position::seat_position;
|
||
use super::push_chart::push_cutoff;
|
||
use super::open_jam::{call_vs_jam, depth_bb, open_jam, open_jam_on};
|
||
use super::reason::describe;
|
||
use super::situation::Situation;
|
||
use super::situation_of::situation_of;
|
||
use super::width_factor::width_factor;
|
||
use crate::exploit::steal_width::steal_width;
|
||
use crate::exploit::thresholds::Thresholds;
|
||
use crate::game::{line, SeenAction, Spot, Street};
|
||
use crate::variant::ActionShape;
|
||
|
||
/// At or below this effective stack (bb) raising ranges become jamming ranges.
|
||
const SHORT_STACK_BB: f64 = 15.0;
|
||
|
||
/// A non-finite or non-positive width scale is ignored (treated as neutral).
|
||
fn sane_scale(scale: f64) -> f64 {
|
||
if scale.is_finite() && scale > 0.0 {
|
||
scale
|
||
} else {
|
||
1.0
|
||
}
|
||
}
|
||
|
||
/// The cut-offs that apply here, before the hand is looked at. `jam_widen` (`>= 1`) widens the
|
||
/// open-jam band under ICM bubble pressure; `1.0` is neutral (cash and every non-open spot).
|
||
fn cutoffs(spot: &Spot, situation: Situation, effective_bb: f64, scale: f64, jam_widen: f64) -> ChartRow {
|
||
let rules = spot.rules();
|
||
let pos = seat_position(spot, spot.hero_seat);
|
||
let width = width_factor(spot.seats, rules.hole_usage) * scale;
|
||
// Bubble-Aggression: der Open-Jam weitet sich, wenn der deckende Caller ICM-Druck spuert
|
||
// (`icm::risk::jam_pressure` -> `jam_width_factor`). NUR beim OEFFNEN oder ueber einen Limp, wo
|
||
// echte Fold-Equity existiert; gegen eine Bet ist der Gegner schon committet - da kein Steal.
|
||
let push = |p: Position, s: Situation| {
|
||
let c = push_cutoff(p, s, effective_bb);
|
||
if matches!(s, Situation::Unopened | Situation::FacingLimp) { c * jam_widen } else { c }
|
||
};
|
||
match (situation, rules.shape) {
|
||
(Situation::FacingAllIn, ActionShape::Full) => {
|
||
ChartRow::new(0.0, super::allin_call_cutoff::call_cutoff_deep(spot.to_call, spot.pot, spot.big_blind), 0.0).scaled(scale)
|
||
}
|
||
(Situation::FacingAllIn, ActionShape::Binary) => {
|
||
ChartRow::new(0.0, 0.0, super::allin_call_cutoff::call_cutoff_deep(spot.to_call, spot.pot, spot.big_blind)).scaled(scale)
|
||
}
|
||
(_, ActionShape::Binary) => {
|
||
ChartRow::new(0.0, 0.0, push(pos, situation)).scaled(scale)
|
||
}
|
||
(_, ActionShape::Full) => {
|
||
if effective_bb <= SHORT_STACK_BB {
|
||
// Kurzstack: Jam/Fold über die Push/Fold-Chart (`push_cutoff`), KEIN Limpen. Vorher
|
||
// ließ `raises_become_jams` die Limp-Bande stehen -> 8bb-SB limpte KK/AKs statt zu
|
||
// jammen (Turnier-Benchmark 7.11.). Jetzt wie der Binary/AoF-Zweig: eine Jam-Bande.
|
||
ChartRow::new(0.0, 0.0, push(pos, situation)).scaled(scale)
|
||
} else {
|
||
full_row(pos, situation).unwrap_or(ChartRow::new(0.0, 0.0, 0.0)).scaled(width)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Width multiplier for this situation: `range_width_scale` (the profile shift), and in
|
||
/// unopened pots, which are steals, also how often the players behind fold
|
||
/// (`exploit::steal_width`: wider against nits, narrower against calling stations).
|
||
pub(crate) fn scale_for(spot: &Spot, situation: Situation, thresholds: &Thresholds, steal: Option<f64>) -> f64 {
|
||
let shift = sane_scale(thresholds.range_width_scale);
|
||
match situation {
|
||
Situation::Unopened => shift * steal.unwrap_or_else(|| steal_width(spot)),
|
||
_ => shift,
|
||
}
|
||
}
|
||
|
||
/// How often the equilibrium plays `action`.
|
||
fn equilibrium_share(advice: &CfrAdvice, action: ChartAction) -> f64 {
|
||
let f = advice.frequencies;
|
||
match action {
|
||
ChartAction::Fold => f.fold,
|
||
ChartAction::Call => f.call,
|
||
ChartAction::Raise | ChartAction::Jam => f.raise,
|
||
}
|
||
}
|
||
|
||
fn verb(action: ChartAction) -> &'static str {
|
||
match action {
|
||
ChartAction::Fold => "fold",
|
||
ChartAction::Call => "call",
|
||
ChartAction::Raise => "raise",
|
||
ChartAction::Jam => "jam",
|
||
}
|
||
}
|
||
|
||
/// The CFR answer, with the exploit border applied (`exploit_border`).
|
||
fn from_equilibrium(
|
||
pos: Position,
|
||
situation: Situation,
|
||
advice: &CfrAdvice,
|
||
hand: f64,
|
||
scale: f64,
|
||
depth: f64,
|
||
) -> PreflopPlan {
|
||
let action = exploit_border(advice.action, advice.widen_to, hand, advice.width, scale);
|
||
let against = match advice.defenders {
|
||
Some(1) => " vs 1 defender".to_string(),
|
||
Some(k) => format!(" vs {k} defenders"),
|
||
None => String::new(),
|
||
};
|
||
let head = format!("{} {}, CFR {} {:.0}bb{against}", pos.label(), situation.label(), advice.table, depth);
|
||
let share = equilibrium_share(advice, advice.action);
|
||
let said = format!("{head}: {} {:.0}%", verb(advice.action), 100.0 * share);
|
||
// Certainty of the equilibrium: `2p - 1`, so pure strategies are certain and mixed
|
||
// ones near 50 % are not. A deviation is as certain as its distance to the border.
|
||
let (certainty, reason) = if action == advice.action {
|
||
((2.0 * share - 1.0).clamp(0.0, 1.0), said)
|
||
} else {
|
||
(
|
||
certainty(hand, &[advice.width * scale]),
|
||
format!("{said}, exploit width {scale:.2} of top {:.0}% -> {}", 100.0 * advice.width, verb(action)),
|
||
)
|
||
};
|
||
PreflopPlan { action, percentile: hand, certainty, reason }
|
||
}
|
||
|
||
/// The pot minus the antes the history names: antes are dead money, not action, and six of them
|
||
/// (2.46 bb first in, measured) would read as a limp. Without records the pot stays as it is.
|
||
pub(crate) fn pot_without_antes(spot: &Spot) -> f64 {
|
||
let antes: f64 = spot
|
||
.history
|
||
.iter()
|
||
.filter(|r| r.action == SeenAction::PostAnte)
|
||
.filter_map(|r| r.amount)
|
||
.filter(|a| a.is_finite() && *a > 0.0)
|
||
.sum();
|
||
spot.pot - antes
|
||
}
|
||
|
||
/// Advice for a preflop spot.
|
||
///
|
||
/// 1. Where the frozen CFR tables cover the spot (`cfr_advice`: NLHE and AOF, first in,
|
||
/// big blind vs one open or one jam, opener vs 3-bet), the equilibrium decides; the
|
||
/// exploit width (`scale_for`) may only move its border, judged by the scaled
|
||
/// heuristic chart (`exploit_border`).
|
||
/// 2. Otherwise the heuristic chart: position, situation and the variant's rules pick a
|
||
/// row, scaled by table size, game and `scale_for`; the hand's percentile selects
|
||
/// jam / raise / call / fold. Binary-shape games only ever answer Jam or Fold.
|
||
pub fn advise(spot: &Spot, thresholds: &Thresholds) -> PreflopPlan {
|
||
advise_widened(spot, thresholds, 1.0)
|
||
}
|
||
|
||
/// `advise` with an ICM open-jam widening factor (`>= 1`, `1.0` = neutral). The tournament entry
|
||
/// (`engine::decide`) passes the bubble factor (`icm::risk::jam_width_factor`); cash passes `1.0`.
|
||
pub fn advise_widened(spot: &Spot, thresholds: &Thresholds, jam_widen: f64) -> PreflopPlan {
|
||
advise_widened_read(spot, None, thresholds, jam_widen)
|
||
}
|
||
|
||
/// `advise_widened` with the RAW (ungated) spot: an opener the read gate plays blind may still be
|
||
/// light-3-bet on its trust-bounded fold-to-3-bet read (`engine::read_exploit`, switch GEGNER_BREIT).
|
||
/// `raw = None` (or the switch off) is exactly `advise_widened`.
|
||
pub fn advise_widened_read(spot: &Spot, raw: Option<&Spot>, thresholds: &Thresholds, jam_widen: f64) -> PreflopPlan {
|
||
let situation = situation_of(spot);
|
||
let blind = advise_chart(spot, thresholds, jam_widen, None);
|
||
// Steal (`read_exploit` channel `s`): the opening width from the players' reads behind.
|
||
let read = (situation == Situation::Unopened)
|
||
.then(|| raw.and_then(crate::engine::read_exploit::steal_width_read))
|
||
.flatten();
|
||
let plan = match read {
|
||
Some(width) => {
|
||
let read_plan = advise_chart(spot, thresholds, jam_widen, Some(width));
|
||
if read_plan.action == blind.action {
|
||
blind
|
||
} else {
|
||
PreflopPlan {
|
||
reason: format!(
|
||
"{} | breit:s: steal width {width:.2} vs blind {:.2}",
|
||
read_plan.reason,
|
||
steal_width(spot)
|
||
),
|
||
..read_plan
|
||
}
|
||
}
|
||
}
|
||
None => blind,
|
||
};
|
||
// VORFLOP_POP=vs3bet/vs4bet: Fold-Veto des Openers gegen eine 3-Bet, des 3-Bettors gegen eine 4-Bet (aus = unveraendert).
|
||
let plan = super::vorflop_pop::veto_vs3bet(spot, light_three_bet(spot, raw, situation, plan));
|
||
let plan = super::vorflop_pop::veto_bluff4(spot, plan);
|
||
let plan = super::vorflop_pop::veto_vs4bet(spot, plan);
|
||
let plan = super::vorflop_pop::veto_jamread(spot, raw, plan);
|
||
super::vorflop_pop::veto_jamall(spot, plan)
|
||
}
|
||
|
||
/// A light 3-bet re-raises to this multiple of the open.
|
||
const LIGHT_THREE_BET_MULT: f64 = 3.0;
|
||
/// The fold-to-3-bet read must clear the pure bluff's break-even by this much.
|
||
const LIGHT_THREE_BET_EDGE: f64 = 0.05;
|
||
/// Channel `m`: how often each player still to act behind folds to a light 3-bet (no read for it;
|
||
/// cold 4-bets and cold calls of a 3-bet are rare, so a high, fixed share).
|
||
pub const BEHIND_FOLD: f64 = 0.9;
|
||
/// Folding hands 3-bet light only from the top of the deck (some equity when called); the bottom
|
||
/// stays a fold.
|
||
const LIGHT_THREE_BET_BAND: f64 = 0.85;
|
||
|
||
/// Against an opener who folds to 3-bets more than a pure bluff needs, a hand the chart calls or
|
||
/// (inside `LIGHT_THREE_BET_BAND`) folds re-raises instead: the pure bluff already wins
|
||
/// `P(fold) · pot > (1 − P(fold)) · risk`, i.e. the read clears `risk / (pot + risk)`
|
||
/// (+ `LIGHT_THREE_BET_EDGE`) for a 3-bet to `LIGHT_THREE_BET_MULT`× the open, and a called 3-bet
|
||
/// still has the hand's equity — against a folder that beats flatting. Only heads-up against the
|
||
/// lone opener with a fold-to-3-bet read, full-shape games. Everything else stays as the chart says.
|
||
fn light_three_bet(spot: &Spot, raw: Option<&Spot>, situation: Situation, plan: PreflopPlan) -> PreflopPlan {
|
||
let candidate = match plan.action {
|
||
ChartAction::Call => true,
|
||
ChartAction::Fold => plan.percentile <= LIGHT_THREE_BET_BAND,
|
||
_ => false,
|
||
};
|
||
if situation != Situation::FacingOpen || !candidate || !matches!(spot.rules().shape, ActionShape::Full) {
|
||
return plan;
|
||
}
|
||
let mut live = spot.live_villains();
|
||
let (v, behind) = match (live.next(), live.next()) {
|
||
(Some(v), None) => {
|
||
if line::opener(&spot.history) != Some(v.seat) {
|
||
return plan;
|
||
}
|
||
(v, 0)
|
||
}
|
||
// Channel `m` (read_exploit): the opener alone in, everyone else still to act behind.
|
||
(Some(_), Some(_)) if raw.is_some() && crate::engine::read_exploit::channels().three_bet_behind => {
|
||
let Some((seat, behind)) = players_behind(spot) else { return plan };
|
||
let Some(v) = spot.live_villains().find(|v| v.seat == seat) else { return plan };
|
||
(v, behind)
|
||
}
|
||
_ => return plan,
|
||
};
|
||
let gated = v.profile.and_then(|p| p.fold_to_three_bet).filter(|f| !f.is_nan());
|
||
let bounded = || raw.and_then(|r| crate::engine::read_exploit::fold_to_three_bet_any(r, v.seat));
|
||
let Some(f3) = gated.or_else(bounded) else { return plan };
|
||
let f3 = f3 * BEHIND_FOLD.powi(behind);
|
||
let hero_in = spot
|
||
.history
|
||
.iter()
|
||
.filter(|r| r.street == Street::Preflop && r.seat == spot.hero_seat)
|
||
.filter_map(|r| r.amount)
|
||
.fold(0.0, f64::max);
|
||
let to = LIGHT_THREE_BET_MULT * (spot.to_call + hero_in);
|
||
let risk = to - hero_in;
|
||
if !(risk > 0.0 && spot.pot > 0.0) {
|
||
return plan;
|
||
}
|
||
let need = risk / (spot.pot + risk);
|
||
if f3 < need + LIGHT_THREE_BET_EDGE {
|
||
return plan;
|
||
}
|
||
PreflopPlan {
|
||
action: ChartAction::Raise,
|
||
reason: format!(
|
||
"{} | {}light 3-bet: fold to 3-bet {f3:.2} > {need:.2} needed",
|
||
plan.reason,
|
||
if behind > 0 {
|
||
format!("breit:m: {behind} behind, ")
|
||
} else if gated.is_some() {
|
||
String::new()
|
||
} else {
|
||
"breit:3: ".to_string()
|
||
}
|
||
),
|
||
..plan
|
||
}
|
||
}
|
||
|
||
/// Facing one open with nobody in between: the opener's seat and how many live players are still to
|
||
/// act behind (they only posted blinds or have not acted). `None` when someone called or raised besides
|
||
/// the opener (a squeeze spot) or there is no opener.
|
||
pub fn players_behind(spot: &Spot) -> Option<(u8, i32)> {
|
||
let opener = line::opener(&spot.history)?;
|
||
let mut behind = 0;
|
||
for v in spot.live_villains().filter(|v| v.seat != opener) {
|
||
let acted = spot.history.iter().any(|r| {
|
||
r.street == Street::Preflop
|
||
&& r.seat == v.seat
|
||
&& !matches!(r.action, SeenAction::PostSmallBlind | SeenAction::PostBigBlind | SeenAction::PostAnte)
|
||
});
|
||
if acted {
|
||
return None;
|
||
}
|
||
behind += 1;
|
||
}
|
||
spot.live_villains().any(|v| v.seat == opener).then_some((opener, behind))
|
||
}
|
||
|
||
fn advise_chart(spot: &Spot, thresholds: &Thresholds, jam_widen: f64, steal: Option<f64>) -> PreflopPlan {
|
||
let hand = percentile(spot.variant, &spot.hero_cards);
|
||
let pos = seat_position(spot, spot.hero_seat);
|
||
let situation = situation_of(spot);
|
||
// An open-jam is played at the jam's depth, not at the deepest stack behind (`open_jam`).
|
||
let jam = open_jam_on().then(|| open_jam(spot)).flatten();
|
||
let depth = jam.as_ref().map_or_else(|| effective_stack_bb(spot), |j| depth_bb(spot, j));
|
||
let scale = scale_for(spot, situation, thresholds, steal);
|
||
let row = cutoffs(spot, situation, depth, scale, jam_widen);
|
||
let action = decide(hand, &row);
|
||
let sure = certainty(hand, &[row.raise, row.call, row.jam]);
|
||
match cfr_advice(spot, situation, pos, depth) {
|
||
Some(advice) => from_equilibrium(pos, situation, &advice, hand, scale, depth),
|
||
None if jam.is_some() => match call_vs_jam(spot, call_margin_premium(thresholds)) {
|
||
Some(plan) => plan,
|
||
None => heuristic(spot, situation, pos, action, hand, sure, &row),
|
||
},
|
||
None => heuristic(spot, situation, pos, action, hand, sure, &row),
|
||
}
|
||
}
|
||
|
||
/// Equity a call needs on top of the price: what the thresholds add to the base call margin (the
|
||
/// tournament risk premium, `engine::decide::with_premium`, and exploit shifts). Cash with no
|
||
/// shift: 0.
|
||
fn call_margin_premium(thresholds: &Thresholds) -> f64 {
|
||
let extra = thresholds.call_margin - Thresholds::BASE.call_margin;
|
||
if extra.is_finite() { extra.max(0.0) } else { 0.0 }
|
||
}
|
||
|
||
/// The heuristic chart answer with the price guard (no CFR table, no open-jam answer).
|
||
fn heuristic(
|
||
spot: &Spot,
|
||
situation: Situation,
|
||
pos: Position,
|
||
action: ChartAction,
|
||
hand: f64,
|
||
sure: f64,
|
||
row: &ChartRow,
|
||
) -> PreflopPlan {
|
||
// Preis-/Commitment-Riegel: die Chart-Zeile ist fuer Standardgroessen geloest; gegen eine
|
||
// grosse Bet wird die ACTUAL Call-Hoehe am Pot neu bepreist (Vorfall 6.11.: 99 jammte den
|
||
// Stack in eine 4-Bet und wurde danach gefoldet). Die geloesten CFR-Spots bleiben.
|
||
//
|
||
// NUR gegen eine Bet (facing raise): da committet der Jam ohne Fold-Equity. Beim OEFFNEN
|
||
// oder ueber einen Limp ist der Kurzstack-Jam ein Steal mit Fold-Equity - der Deckel wuerde
|
||
// ihn faelschlich zum Call/Limp degradieren (8bb-SB limpte KK, Turnier-Benchmark 7.11.).
|
||
let allow_call = matches!(spot.rules().shape, ActionShape::Full);
|
||
let facing_raise = !matches!(situation, Situation::Unopened | Situation::FacingLimp);
|
||
let guarded = if facing_raise {
|
||
price_guarded_deep(action, hand, spot.to_call, spot.pot, spot.hero_stack, allow_call, spot.big_blind)
|
||
} else {
|
||
action
|
||
};
|
||
let reason = if guarded == action {
|
||
describe(pos, situation, action, row)
|
||
} else {
|
||
format!("{} | Preis-Riegel {} -> {}", describe(pos, situation, action, row), verb(action), verb(guarded))
|
||
};
|
||
PreflopPlan { action: guarded, percentile: hand, certainty: sure, reason }
|
||
}
|