//! How likely one opponent folds to a bet: the documented map from their profile. //! //! | step | rule | //! |---|---| //! | base `f` | `foldToBet`, clamped to [0, 1]; without it the style default: nit 0.65, calling station 0.20, loose-aggressive 0.40, otherwise 0.45 | //! | size | `p = 1 - (1 - f)^(ratio / 0.66)`: foldToBet is a frequency against a typical two-thirds-pot bet, so at that size `p = f`; smaller bets fold less, bigger more, a zero bet never | //! | raised | `p * 0.7` when the opponent already bet and is being raised (money invested, range stronger) | //! | cap | at most 0.95: nobody folds for sure | //! //! `ratio` is the pressure: chips beyond a call over the pot after calling //! (`table_fold::pressure_ratio`). use super::profile::Profile; use super::style::{classify, Style}; /// Bet size (pot fraction) at which foldToBet is taken to be measured. pub const REFERENCE_RATIO: f64 = 0.66; /// Fold-to-bet of an opponent we know nothing about. pub const DEFAULT_FOLD_TO_BET: f64 = 0.45; /// Factor when the opponent is raised after betting. pub const RAISE_RESISTANCE: f64 = 0.7; /// Largest fold chance ever assumed for one opponent. pub const MAX_FOLD: f64 = 0.95; fn style_default(style: Style) -> f64 { match style { Style::Nit => 0.65, Style::CallingStation => 0.20, Style::LooseAggressive => 0.40, Style::Regular | Style::Unknown => DEFAULT_FOLD_TO_BET, } } /// The opponent's fold-to-bet at the reference size. pub fn fold_base(profile: Option<&Profile>) -> f64 { match profile { None => DEFAULT_FOLD_TO_BET, Some(p) => match p.fold_to_bet.filter(|f| !f.is_nan()) { Some(f) => f.clamp(0.0, 1.0), None => style_default(classify(p)), }, } } /// P(this opponent folds) to a bet of `ratio` pots. Total: any input gives `[0, MAX_FOLD]`. pub fn fold_chance(profile: Option<&Profile>, ratio: f64, facing_raise: bool) -> f64 { let f = fold_base(profile); let ratio = if ratio.is_nan() { 0.0 } else { ratio.max(0.0) }; let sized = if f >= 1.0 { if ratio > 0.0 { 1.0 } else { 0.0 } } else { 1.0 - (1.0 - f).powf(ratio / REFERENCE_RATIO) }; let raised = if facing_raise { sized * RAISE_RESISTANCE } else { sized }; if raised.is_nan() { 0.0 } else { raised.clamp(0.0, MAX_FOLD) } }