Files
pokerfreak/src/preflop/commit_guard.rs
T

81 lines
3.9 KiB
Rust

//! Price guard over the charted action. The heuristic chart row is solved for standard bet sizes;
//! facing a large, non-standard raise it misprices (Vorfall 6.11.: a medium hand jammed the stack
//! into a big 4-bet, and hands were folded while getting the price). This re-prices the ACTUAL call
//! against the pot, reusing the all-in call cut-off (`allin_call_cutoff`), so no new poker math.
use super::allin_call_cutoff::call_cutoff;
use super::plan::ChartAction;
/// A raise that reaches this fraction of the all-in size is a de-facto jam (leaves almost nothing).
const NEAR_ALLIN: f64 = 0.9;
/// What to do with a charted `Raise` once it has been sized.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RaiseVerdict {
/// Keep the raise as sized.
Keep,
/// The sized raise over-commits without the hand to back it - just pay the price (call).
Downgrade,
/// Not committable and not even getting the price - fold.
Fold,
}
/// A re-raise sized to (near) all-in commits the stack and must clear the same price cut-off as a
/// jam (Vorfall 6.11.: a 3x re-raise of a big 4-bet got capped to a near-all-in "raise" with 99 -
/// the action stayed `Raise`, so the jam ceiling never saw it). A raise well below all-in, or no
/// price to weigh, is kept untouched - normal 3-bets are never downgraded.
pub fn raise_commitment(percentile: f64, raise_to: f64, all_in: f64, to_call: f64, pot: f64) -> RaiseVerdict {
let priced = all_in.is_finite() && all_in > 0.0 && raise_to >= NEAR_ALLIN * all_in
&& to_call.is_finite() && pot.is_finite() && to_call > 0.0;
if !priced {
return RaiseVerdict::Keep;
}
if percentile <= call_cutoff(raise_to, pot) {
RaiseVerdict::Keep
} else if percentile <= call_cutoff(to_call, pot) {
RaiseVerdict::Downgrade
} else {
RaiseVerdict::Fold
}
}
/// Re-price `action` for the real price. `percentile` is the hand (smaller = better);
/// `to_call`/`pot` the immediate price; `commit` the chips at risk (hero's remaining stack);
/// `allow_call` is false in jam-or-fold games, where continuing means jamming, not calling.
///
/// `call_cutoff` is ALL-IN math: it prices a call that closes the action, with no streets left to
/// bleed a dominated hand. So the fold floor only fires when the call is itself (near) all-in
/// (`to_call >= NEAR_ALLIN * commit`) - the "danach fold" incident (6.11.): the last bit into a
/// huge pot is never folded. A cheaper call still has streets to come; there the chart decides, not
/// raw pot odds.
///
/// * Fold floor: an all-in-level call the hand is priced for (`percentile <= call_cutoff(to_call,
/// pot)`) is never folded - it continues (call, or jam in a jam-or-fold game).
/// * Jam ceiling: a jam is kept only when the hand clears the cut-off for committing `commit`
/// (`call_cutoff(commit, pot)`); otherwise it steps down to a call when calling is allowed and the
/// immediate price is paid, else a fold. Never commit the stack with a hand the price denies.
///
/// Not facing a bet (`to_call <= 0`) or non-finite input: unchanged.
pub fn price_guarded(action: ChartAction, percentile: f64, to_call: f64, pot: f64, commit: f64, allow_call: bool) -> ChartAction {
if !(to_call.is_finite() && pot.is_finite()) || to_call <= 0.0 {
return action;
}
let stake = if commit.is_finite() && commit > 0.0 { commit } else { to_call };
let all_in_call = to_call >= NEAR_ALLIN * stake;
let pays_price = percentile <= call_cutoff(to_call, pot);
let continue_ = if allow_call { ChartAction::Call } else { ChartAction::Jam };
match action {
ChartAction::Fold if all_in_call && pays_price => continue_,
ChartAction::Jam => {
if percentile <= call_cutoff(stake, pot) {
ChartAction::Jam
} else if allow_call && pays_price {
ChartAction::Call
} else {
ChartAction::Fold
}
}
other => other,
}
}