Files
pokerfreak/src/exploit/table_fold.rs
T

56 lines
2.5 KiB
Rust

use super::fold_chance::{fold_base_cbet, fold_chance_on, sized_fold_on, MAX_FOLD};
use crate::game::{line, Spot};
/// Pressure of a raise to `to`: the chips beyond a call, `to - to_call`, over the pot
/// after calling, `pot + to_call`. A plain bet (`to_call = 0`) is `to / pot`.
/// 0 when the pot is empty or the numbers are not finite.
pub fn pressure_ratio(pot: f64, to_call: f64, to: f64) -> f64 {
let base = pot + to_call;
let ratio = (to - to_call).max(0.0) / base;
if base > 0.0 && ratio.is_finite() { ratio } else { 0.0 }
}
/// P(every villain folds) to hero raising to `to`: each villain's `fold_chance`
/// (from their own profile) times the shared `scale` (`Thresholds::fold_equity_scale`),
/// capped, multiplied over the villains as independent events. No villain: 0.
pub fn table_fold(spot: &Spot, to: f64, scale: f64) -> f64 {
let ratio = pressure_ratio(spot.pot, spot.to_call, to);
let facing_raise = spot.to_call > 0.0;
let scale = if scale.is_finite() { scale.max(0.0) } else { 1.0 };
let mut live = spot.live_villains().peekable();
if live.peek().is_none() {
return 0.0;
}
// Hero's continuation bet is priced by the fold-to-c-bet read (`fold_base_cbet`).
let cbet = line::cbet_spot(&spot.history, spot.hero_seat, spot.street);
let glaube = crate::engine::glaube::fold_on();
let size_curve = super::pool_stufe::mode_at(spot.big_blind).is_some_and(|m| m.size);
live.map(|v| {
if glaube {
// POSTERIOR=fold: the same number the called branch plays against (`engine::glaube`).
return (crate::engine::glaube::table_fold_of(spot, v, ratio, facing_raise) * scale).clamp(0.0, MAX_FOLD);
}
let p = v.profile.as_ref();
let f = if cbet {
sized_fold_on(fold_base_cbet(p), ratio, facing_raise, Some(spot.street))
} else {
fold_chance_on(p, ratio, facing_raise, Some(spot.street))
};
// POOL_STUFE=groesse: the stake does not fold more to bigger bets (NL2 calls jams).
let f = match size_curve {
true if !facing_raise => {
let knee = super::pool_stufe::KNEE;
let f_knee = if cbet {
sized_fold_on(fold_base_cbet(p), knee, false, Some(spot.street))
} else {
fold_chance_on(p, knee, false, Some(spot.street))
};
super::pool_stufe::big_bet_fold(f, f_knee, ratio)
}
_ => f,
};
(f * scale).clamp(0.0, MAX_FOLD)
})
.product()
}