Files
pokerfreak/src/guard/ledger.rs
T
2026-10-28 11:51:24 +01:00

16 lines
534 B
Rust

/// Hero's stack and the pot after an action.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Ledger {
pub stack: f64,
pub pot: f64,
}
impl Ledger {
/// Moves `amount` from the stack into the pot, never more than the stack holds and
/// never anything for a non-finite or non-positive amount.
pub fn pay(self, amount: f64) -> Ledger {
let paid = if amount.is_finite() { amount.max(0.0).min(self.stack.max(0.0)) } else { 0.0 };
Ledger { stack: self.stack - paid, pot: self.pot + paid }
}
}