//! Effective stack in big blinds. use crate::game::Spot; /// Used when the numbers cannot be trusted: deep enough not to trigger any short-stack rule. pub const UNKNOWN_DEEP_BB: f64 = 100.0; fn usable(x: f64) -> bool { x.is_finite() && x > 0.0 } /// `min(hero stack, largest villain stack)` in big blinds; hero's stack alone when /// no villain with a usable stack is known. Unusable numbers give `UNKNOWN_DEEP_BB`. pub fn effective_stack_bb(spot: &Spot) -> f64 { let largest_villain = spot .live_villains() .map(|v| v.stack) .filter(|s| usable(*s)) .fold(None, |best: Option, s| { Some(best.map_or(s, |b| b.max(s))) }); let chips = largest_villain.map_or(spot.hero_stack, |v| v.min(spot.hero_stack)); if usable(chips) && usable(spot.big_blind) { chips / spot.big_blind } else { UNKNOWN_DEEP_BB } }