Die Welt soll nichts verraten. Woerter, die ein Gegenueber implizieren (echt vs. unecht, live, Mensch), sind aus Prosa, Kommentaren und Docstrings raus; Namen (mensch_ruhe_s, echte_chops) und der Altwert "echt" im Spielplan bleiben. Nur Kommentare und Docstrings angefasst, damit keine Einrueckung faellt.
112 lines
5.0 KiB
Rust
112 lines
5.0 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; no micro rule is modelled here.
|
|
|
|
/// 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,
|
|
}
|
|
|
|
/// 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 };
|
|
|
|
/// 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 {
|
|
return 0.0;
|
|
}
|
|
let cap = if players_in_pot > PLAYERS_ON_THE_PLAIN_CAP { self.cap_more_than_three } else { self.cap };
|
|
(pot * self.percent / PERCENT).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)];
|
|
|
|
/// 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,
|
|
}
|
|
|
|
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),
|
|
}
|
|
}
|
|
|
|
/// 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)
|
|
}
|
|
}
|
|
}
|
|
}
|