31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
use crate::game::Spot;
|
|
use crate::variant::SizingRule;
|
|
|
|
/// Inclusive range a free-form raise-to size may take.
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
pub struct Bounds {
|
|
pub lo: f64,
|
|
pub hi: f64,
|
|
}
|
|
|
|
impl Bounds {
|
|
pub fn clamp(self, x: f64) -> f64 {
|
|
x.max(self.lo).min(self.hi)
|
|
}
|
|
}
|
|
|
|
/// `[min_raise_to, min(max_raise_to, hero_stack)]`; pot-limit rules also cap at a
|
|
/// pot-sized raise (`pot + 2 * to_call`). A stack below `min_raise_to` may still go
|
|
/// all-in for exactly the stack (short all-in). `None` when no positive size fits.
|
|
pub fn bounds(spot: &Spot) -> Option<Bounds> {
|
|
let min = spot.min_raise_to.unwrap_or(0.0).max(0.0);
|
|
let capped = spot.max_raise_to.unwrap_or(f64::INFINITY).min(spot.hero_stack);
|
|
let hi = match spot.rules().sizing {
|
|
SizingRule::PotLimit => capped.min(spot.pot + 2.0 * spot.to_call),
|
|
_ => capped,
|
|
};
|
|
let short_all_in = hi == spot.hero_stack && spot.hero_stack < min;
|
|
let lo = if short_all_in { hi } else { min };
|
|
(lo.is_finite() && hi > 0.0 && lo <= hi).then_some(Bounds { lo, hi })
|
|
}
|