Files
pokerfreak/src/rake/mod.rs
T
mmintelandClaude Opus 5.5 09d2014c9e Merge rake-live (c8257b4): Mikro-Rake; chartgen --mikro = ohne Antes + Mikro-Rake, Fold-Rake
Ein Tabellenlauf fuer den Live-Mikro-Tisch (Absprache rake-live, Orchestrator):
- chartgen --mikro: Antes 0 UND ChartRake::Micro, fuer charts, multi, multi-deep
  und teilspiel. --ohne-ante und --rake mikro bleiben einzeln nutzbar.
- ChartRake::fold: ein durch Fold gewonnener Pot zahlt beim Mikro-Rake den
  Rake des gematchten Pots (live: 3-bet/fold 5,5 bb -> 0,5 bb). Gilt in allen
  sechs Spielen (open, open3, push/fold, push/fold3, multi, teilspiel).
  Measured/None: 0, also bit-identisch (eingefrorene Tabellen reproduzieren).
- generated_charts_short.rs: Renderer-Ausgabe zurueck (Leerzeichen).
- tests/chart_fold_rake.rs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 01:18:12 +01:00

155 lines
7.6 KiB
Rust

//! Rake as plain arithmetic, in the currency of the pot it is given.
//!
//! **Source.** `game.winnerInfo` of the client log carries `potAmount` and `potAmountAfterRake`
//! per pot, `roomProperties` the configuration (`shell: archiv/mitschrieb/PIPE-UND-BRUECKE.md`). Measured
//! per hand at the table 1000/2000, ante 320 ("Big Ben", 1134 hands):
//! - 5 % of the pot, antes included, capped at 1 big blind: 1023 of 1046 hands with a board match
//! exactly. Of the others 20 are run-it-twice hands (two lines of 1000 each, together the cap)
//! and 3 merge lines of two hands in the log.
//! - The cap holds per hand. Side pots share it in proportion to their size (96 of 106 hands
//! with several pots sum to exactly the cap).
//! - A hand that ends before the flop pays nothing (86 of 86; 2 more hands show no board only
//! because the log lost it). A preflop all-in that runs out the board does pay (319 hands).
//!
//! **Assumptions.** `cap_more_than_three` follows the order's reading of `rakeCapGT3` ("more than
//! three players in the pot"). The log cannot confirm it: at 1000/2000 both caps are equal, and
//! the micro tables contradict their configuration (0.05/0.10 configures 0.6 and 0.25 yet took
//! 1.0 twice; 0.02/0.05 configures 0.3 and 0.13 yet took 0.5 four times, once with four players
//! in the pot). Those tables also rake some preflop pots (`rakeGTPPf` 5). Only the rule of
//! 1000/2000 is therefore treated as measured by those tables.
//!
//! **The live stake NL 0.01/0.02 (`RakeRule::MICRO_BB`, measured 15.11.).** 857 hands of the live
//! micro runs (14.11., 16 tables; `archiv/rohlog` plus the client's current logs, `potAmount`
//! against `potAmountAfterRake` per hand): 5 % of the pot rounded to the cent (half to even), capped
//! at 0.20 = **10 bb**. 425 of 429 hands with a flop match exactly (the rest are merged log lines),
//! and the hands without a flop pay the same rule (50 of 428 raked: every pot of 0.11 or more, none
//! of 0.10 or less) — **no "no flop, no drop"** at this stake. In big blinds the cent is half a big
//! blind. The engine prices it only behind `RAKE_LIVE` (`rake::live`).
pub mod live;
/// Rake of one table. All amounts in the pot's currency.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct RakeRule {
/// Percent of the pot (`rake`).
pub percent: f64,
/// Cap of a hand (`rakeCap`).
pub cap: f64,
/// Cap with more than three players in the pot (`rakeCapGT3`).
pub cap_more_than_three: f64,
/// The rake is rounded to this unit, half to even (the cent); 0 = not rounded.
pub step: f64,
/// A hand that ends before the flop pays no rake ("no flop, no drop").
pub no_flop_no_drop: bool,
}
/// How far a hand got: rake is taken once a flop is dealt, whoever is left.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum HandEnd {
NoFlop,
FlopDealt,
}
/// Players above which `cap_more_than_three` applies.
const PLAYERS_ON_THE_PLAIN_CAP: usize = 3;
const PERCENT: f64 = 100.0;
impl RakeRule {
/// The measured table in big blinds: 5 %, cap 1 bb (2000 at blinds 1000/2000).
pub const MEASURED_BB: RakeRule =
RakeRule { percent: 5.0, cap: 1.0, cap_more_than_three: 1.0, step: 0.0, no_flop_no_drop: true };
/// The live stake NL 0.01/0.02 in big blinds: 5 % rounded to the cent (0.5 bb, half to even),
/// cap 10 bb, preflop pots raked as well.
pub const MICRO_BB: RakeRule =
RakeRule { percent: 5.0, cap: 10.0, cap_more_than_three: 10.0, step: 0.5, no_flop_no_drop: false };
/// Rake of a whole hand. `pot` is everything contested, antes included, uncalled chips not.
pub fn of_hand(&self, pot: f64, players_in_pot: usize, end: HandEnd) -> f64 {
if end == HandEnd::NoFlop && self.no_flop_no_drop {
return 0.0;
}
let cap = if players_in_pot > PLAYERS_ON_THE_PLAIN_CAP { self.cap_more_than_three } else { self.cap };
let raw = pot * self.percent / PERCENT;
let rounded = if self.step > 0.0 { (raw / self.step).round_ties_even() * self.step } else { raw };
rounded.max(0.0).min(cap)
}
}
/// A hand's rake over its side pots, in proportion to their size.
pub fn split_over_pots(rake: f64, pots: &[f64]) -> Vec<f64> {
let total: f64 = pots.iter().sum();
pots.iter().map(|p| if total > 0.0 { rake * p / total } else { 0.0 }).collect()
}
/// The uncalled top of the highest contribution: `(player, amount)`. It goes back to that player
/// and is no part of the pot (`potAmount` of the log does not contain it).
pub fn uncalled(contributions: &[f64]) -> Option<(usize, f64)> {
let mut order: Vec<usize> = (0..contributions.len()).collect();
order.sort_by(|a, b| contributions[*b].total_cmp(&contributions[*a]));
match order[..] {
[top, second, ..] => Some((top, contributions[top] - contributions[second])),
_ => None,
}
}
/// Ante of the measured table in big blinds (320 at big blind 2000), per player.
pub const MEASURED_ANTE_BB: f64 = 0.16;
/// Seats the chart games assume for the antes in their pots.
const CHART_SEATS: f64 = 6.0;
/// Antes of a whole table in the chart games, bb: dead money in every pot.
pub const CHART_ANTES_BB: f64 = CHART_SEATS * MEASURED_ANTE_BB;
/// Mean rake in bb of hands by their pot on the flop in bb, antes included, as upper bound of the
/// bucket: 728 hands that saw a flop at 1000/2000. It is more than 5 % of the flop pot because the
/// pot still grows after the flop. Above the last bound the means stop rising (0.91 to 0.95).
const MEAN_RAKE_BY_FLOP_POT: [(f64, f64); 5] = [(6.0, 0.489), (10.0, 0.720), (15.0, 0.850), (25.0, 0.906), (f64::INFINITY, 0.950)];
/// The same for the live micro stake (`RakeRule::MICRO_BB`): 413 hands of NL 0.01/0.02 that saw a
/// flop, mean final rake in bb by the pot at the start of the flop (bb, upper bound of the bucket;
/// 107 / 177 / 50 / 41 / 22 / 16 hands). With a 10 bb cap the rake keeps rising with the pot.
const MICRO_MEAN_RAKE_BY_FLOP_POT: [(f64, f64); 6] =
[(6.0, 0.500), (10.0, 0.808), (15.0, 1.890), (25.0, 2.061), (40.0, 2.545), (f64::INFINITY, 5.500)];
/// What a leaf of the chart games pays, for a pot with the antes in it.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ChartRake {
None,
Measured,
/// The live micro stake (`RakeRule::MICRO_BB`, `MICRO_MEAN_RAKE_BY_FLOP_POT`).
Micro,
}
impl ChartRake {
/// Pot that is decided by showdown now: the rule itself.
pub fn all_in(self, pot: f64) -> f64 {
match self {
ChartRake::None => 0.0,
ChartRake::Measured => RakeRule::MEASURED_BB.of_hand(pot, 2, HandEnd::FlopDealt),
ChartRake::Micro => RakeRule::MICRO_BB.of_hand(pot, 2, HandEnd::FlopDealt),
}
}
/// Pot won without a showdown (everybody else folded); `pot` is the matched pot (uncalled chips
/// returned), antes included. The micro stake rakes those too (no "no flop, no drop": a 3-bet/fold
/// pot of 5.5 bb pays 0.5 bb). `None` and `Measured` keep them free, as the tables always did.
pub fn fold(self, pot: f64) -> f64 {
match self {
ChartRake::None | ChartRake::Measured => 0.0,
ChartRake::Micro => RakeRule::MICRO_BB.of_hand(pot, 2, HandEnd::NoFlop),
}
}
/// Pot with chips behind: its final size is unknown here, so the measured mean applies.
pub fn postflop(self, pot: f64) -> f64 {
match self {
ChartRake::None => 0.0,
ChartRake::Measured => {
MEAN_RAKE_BY_FLOP_POT.iter().find(|(bound, _)| pot < *bound).map_or(0.0, |(_, rake)| *rake)
}
ChartRake::Micro => {
MICRO_MEAN_RAKE_BY_FLOP_POT.iter().find(|(bound, _)| pot < *bound).map_or(0.0, |(_, rake)| *rake)
}
}
}
}