//! The decision deadline of the postflop solvers ("Solver ueberall"): `decide_with` marks the start of //! each decision on its thread, and a solver gets what is left of its street's total before it starts. //! Totals per decision (live table): river and flop 2 s, turn 1.25 s, each minus `MARGIN_MS` for the //! work after the solve. Without a mark (tests, tools calling a solver directly) the full total is left. use std::cell::Cell; use std::time::Instant; thread_local! { static START: Cell> = const { Cell::new(None) }; } /// Total wall time of one decision per street, in ms. pub const RIVER_MS: f64 = 2000.0; pub const TURN_MS: f64 = 1250.0; pub const FLOP_MS: f64 = 2000.0; /// Kept free after the solve (strategy readout, sampling, the answer). pub const MARGIN_MS: f64 = 150.0; /// Mark the start of a decision on this thread. pub fn begin() { START.with(|s| s.set(Some(Instant::now()))); } /// Milliseconds since the mark (0 without one). pub fn elapsed_ms() -> f64 { START.with(|s| s.get().map_or(0.0, |t| t.elapsed().as_secs_f64() * 1e3)) } /// What a solver may still spend of `total_ms` (may be ≤ 0: then it must not start). pub fn left_ms(total_ms: f64) -> f64 { total_ms - MARGIN_MS - elapsed_ms() } /// Measurement switch `SOLVER_ZEIT=fest`: solvers ignore wall time and always run their full iteration /// count, so ladder and LBR results do not depend on machine load (read once). pub fn fixed() -> bool { static FIXED: std::sync::OnceLock = std::sync::OnceLock::new(); *FIXED.get_or_init(|| std::env::var("SOLVER_ZEIT").as_deref() == Ok("fest")) } /// The budget a solve gets: `cap_ms` (its own limit), cut to what is left of the street's total; /// infinite under `SOLVER_ZEIT=fest`. pub fn budget_ms(cap_ms: f64, total_ms: f64) -> f64 { if fixed() { f64::INFINITY } else { cap_ms.min(left_ms(total_ms)) } }