From ee6d996cd7830e1316fdc2798fb4d558942876ec Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Tue, 1 Dec 2026 13:36:17 +0100 Subject: [PATCH] Sicherung 01.12.: ungesicherte Dateien aus Worktree C:\Users\marcm\pokerfreak-solverkern\fremd3-fix (Zweig (detached), HEAD 5f72b5fc) 3 Dateien. Nicht enthalten: 0 Dateien (Bau, Binaer, > 25 MB, archiv/lauf, Spuren echter Haende), 0 Loeschungen nicht nachgezogen. Der Worktree selbst ist unveraendert. Co-Authored-By: Claude Opus 5.5 --- src/engine/audit.rs | 2 +- src/engine/decide.rs | 2 +- src/rake/live.rs | 77 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/engine/audit.rs b/src/engine/audit.rs index deb197a9..f6f3dae6 100644 --- a/src/engine/audit.rs +++ b/src/engine/audit.rs @@ -166,7 +166,7 @@ impl Default for Opts { pub fn audit(spot: &Spot, taken: Taken, opts: Opts) -> Result { // RAKE_LIVE: the audit prices the river game and the all-in prices net of the room's rake, as the // live decision does (`rake::live`). The turn+river game (`cfr::turn_river_game`) stays raw. - let _rake = crate::rake::live::cash_scope(spot.big_blind); + let _rake = crate::rake::live::cash_scope_seats(spot.big_blind, spot.seats); match spot.street { Street::River => audit_river(spot, taken, opts), Street::Turn => audit_turn(spot, taken, opts), diff --git a/src/engine/decide.rs b/src/engine/decide.rs index b9740325..d9601e32 100644 --- a/src/engine/decide.rs +++ b/src/engine/decide.rs @@ -372,7 +372,7 @@ fn decide_one_inner(spot: &Spot, lage: Option<&Turnierlage>) -> Decision { // a tournament pays none, also a chip-linear one that plays the cash path below // (the scope is decided on the original situation). Off: no scope, nothing changes. let _rake = match lage { - None => crate::rake::live::cash_scope(spot.big_blind), + None => crate::rake::live::cash_scope_seats(spot.big_blind, spot.seats), Some(_) => crate::rake::live::enabled().then(crate::rake::live::Scope::none), }; // Chip-lineares Geld (der Sieger nimmt alles, alle Verbliebenen gleich bezahlt, p1 > p2 = ... = pn): diff --git a/src/rake/live.rs b/src/rake/live.rs index e9dfa608..01f4dc50 100644 --- a/src/rake/live.rs +++ b/src/rake/live.rs @@ -8,6 +8,12 @@ //! **Switch.** `RAKE_LIVE=1` (read once). Off by default: then no scope is ever entered, `net` returns //! its argument unchanged and every result is bit-identical to the engine without this module. //! +//! **Seat cap (`RAKE_LIVE=sitze`).** The room's cap depends on the players dealt in (measured 23.11., +//! `messung/fremd/4_regeln/ERGEBNIS.md`, NL 0.01/0.02): 5-6 players 20 cents (10 bb), 3-4 players 12 +//! cents (6 bb), 2 players 5 cents (2.5 bb); 7550 own and 1953 hhDealer hands match to the cent. +//! `RAKE_LIVE=sitze` is `RAKE_LIVE=1` plus that cap (the spot's `seats`, the players of the hand); +//! with `RAKE_LIVE=1` and at five or more seats nothing differs from the flat 10 bb, bit for bit. +//! //! **Scope.** The rake only exists at a cash table: `engine::decide::decide_with` enters a `Scope` for a //! spot without a tournament situation (tournaments pay no rake per pot). The scope is thread-local and //! restored on drop, so parallel simulations and nested decisions stay independent. Inside it the pot @@ -37,18 +43,37 @@ pub const DECISION_RULE: RakeRule = RakeRule { step: 0.0, ..LIVE_RULE }; /// `RAKE_LIVE=1` switches the rake into the live decision. Read once per process. pub fn enabled() -> bool { static ON: OnceLock = OnceLock::new(); - *ON.get_or_init(|| std::env::var("RAKE_LIVE").as_deref() == Ok("1")) + *ON.get_or_init(|| matches!(std::env::var("RAKE_LIVE").as_deref(), Ok("1") | Ok("sitze"))) +} + +/// `RAKE_LIVE=sitze`: the cap follows the players of the hand (`cap_bb`). Read once per process. +pub fn seat_cap_enabled() -> bool { + static ON: OnceLock = OnceLock::new(); + *ON.get_or_init(|| std::env::var("RAKE_LIVE").as_deref() == Ok("sitze")) +} + +/// The room's cap in big blinds for a hand with `players` dealt in (NL 0.01/0.02: 20 / 12 / 5 cents). +pub fn cap_bb(players: u8) -> f64 { + match players { + 0 | 1 => LIVE_RULE.cap, + 2 => 2.5, + 3 | 4 => 6.0, + _ => LIVE_RULE.cap, + } } thread_local! { /// Big blind of the cash spot being decided on this thread; `None` = no rake. static BIG_BLIND: Cell> = const { Cell::new(None) }; + /// Players of the hand when the seat cap is on; `None` = the flat cap. + static SEATS: Cell> = const { Cell::new(None) }; } /// While alive, `net` and `of_pot` rake pots in chips of a table with this big blind. #[must_use] pub struct Scope { previous: Option, + previous_seats: Option, } impl Scope { @@ -56,18 +81,26 @@ impl Scope { /// rake. pub fn enter(big_blind: f64) -> Scope { let value = (big_blind.is_finite() && big_blind > 0.0).then_some(big_blind); - Scope { previous: BIG_BLIND.with(|b| b.replace(value)) } + Scope { previous: BIG_BLIND.with(|b| b.replace(value)), previous_seats: SEATS.with(|s| s.replace(None)) } + } + + /// Enter with the seat cap of a table with `players` dealt in (tests, `cash_scope`). + pub fn enter_seats(big_blind: f64, players: u8) -> Scope { + let scope = Scope::enter(big_blind); + SEATS.with(|s| s.set(Some(players))); + scope } /// No rake inside, whatever the outer scope said (a tournament decision nested in a cash run). pub fn none() -> Scope { - Scope { previous: BIG_BLIND.with(|b| b.replace(None)) } + Scope { previous: BIG_BLIND.with(|b| b.replace(None)), previous_seats: SEATS.with(|s| s.replace(None)) } } } impl Drop for Scope { fn drop(&mut self) { BIG_BLIND.with(|b| b.set(self.previous)); + SEATS.with(|s| s.set(self.previous_seats)); } } @@ -77,6 +110,12 @@ pub fn cash_scope(big_blind: f64) -> Option { enabled().then(|| Scope::enter(big_blind)) } +/// `cash_scope` for a spot with `players` dealt in: under `RAKE_LIVE=sitze` the cap follows them, under +/// `RAKE_LIVE=1` the scope is the one of `cash_scope` (flat cap). +pub fn cash_scope_seats(big_blind: f64, players: u8) -> Option { + enabled().then(|| if seat_cap_enabled() { Scope::enter_seats(big_blind, players) } else { Scope::enter(big_blind) }) +} + /// Is a rake scope active on this thread? pub fn active() -> bool { BIG_BLIND.with(Cell::get).is_some() @@ -86,7 +125,16 @@ pub fn active() -> bool { pub fn of_pot(pot: f64) -> f64 { match BIG_BLIND.with(Cell::get) { None => 0.0, - Some(bb) if pot.is_finite() && pot > 0.0 => DECISION_RULE.of_hand(pot / bb, 2, HandEnd::FlopDealt) * bb, + Some(bb) if pot.is_finite() && pot > 0.0 => { + let rule = match SEATS.with(Cell::get) { + Some(players) if cap_bb(players) != LIVE_RULE.cap => { + let cap = cap_bb(players); + RakeRule { cap, cap_more_than_three: cap, ..DECISION_RULE } + } + _ => DECISION_RULE, + }; + rule.of_hand(pot / bb, 2, HandEnd::FlopDealt) * bb + } Some(_) => 0.0, } } @@ -141,6 +189,27 @@ mod tests { assert!(!active()); } + #[test] + fn the_seat_cap_follows_the_players_of_the_hand() { + { + let _s = Scope::enter_seats(0.02, 6); + near(of_pot(50.0), 0.20); + near(of_pot(3.38), 0.169); + } + { + let _s = Scope::enter_seats(0.02, 4); + near(of_pot(50.0), 0.12); + near(of_pot(1.0), 0.05); + } + { + let _s = Scope::enter_seats(0.02, 2); + near(of_pot(50.0), 0.05); + } + assert!(!active()); + let _s = Scope::enter(0.02); + near(of_pot(50.0), 0.20); + } + #[test] fn in_big_blinds_neighbouring_sizes_pay_no_step() { let _s = Scope::enter(1.0);