Files
pokerfreak/tests/rake_live.rs
mmintelandClaude Opus 5.5 e6c2ff4f5d rake-live: Entscheidungs-Rake glatt (5 %, ohne Cent-Stufe), Diagnose station
Die Cent-Stufe im Entscheidungsmodell setzte kuenstliche 0.5-bb-Spruenge zwischen Nachbargroessen
und trieb Value-Bets gegen die station auf die kleine Groesse (Leiter -0.16 +-0.16). DECISION_RULE =
MICRO_BB ohne step; der Simulator-Tisch behaelt die Cents. diag_rake + diag_diff.py zerlegen die
Wirkung je Hand. Aus bleibt bit-gleich zu 43e566f. Nachmessung rake-glatt-* eingereiht.

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

108 lines
4.3 KiB
Rust

//! Spezifikation von `RAKE_LIVE` (`rake::live`): der Rake in der Live-Entscheidung.
//!
//! Ausserhalb eines Rake-Scopes rechnet alles roh, bit für bit; im Scope (Cash-Spot unter
//! `RAKE_LIVE=1`) ist jeder Topf, den hero gewinnt, der Topf nach Rake. Die Tests betreten den Scope
//! direkt (`Scope::enter`) und lassen den Prozess-Schalter in Ruhe.
use rechner::cfr::river::tree_with_chance;
use rechner::cfr::river_game::{build, Bets};
use rechner::cfr::tree::{Node, Payoff};
use rechner::odds::{break_even::break_even, ev};
use rechner::rake::live::{active, net, of_pot, Scope};
fn near(a: f64, b: f64) {
assert!((a - b).abs() < 1e-9, "{a} != {b}");
}
#[test]
fn without_a_scope_every_price_is_the_raw_one_to_the_bit() {
assert!(!active());
for (share, pot, call) in [(0.3, 0.19, 0.07), (0.55, 12.0, 4.0), (0.12, 1.0, 1.0)] {
assert_eq!(ev::call(share, pot, call).to_bits(), (share * (pot + call) - call).to_bits());
assert_eq!(ev::check(share, pot).to_bits(), (share * pot).to_bits());
assert_eq!(break_even(pot, call).to_bits(), (call / (pot + call)).to_bits());
let raw = 0.4 * pot + (1.0 - 0.4) * (share * ev::final_pot(pot, call, 2.0 * call) - 2.0 * call);
assert_eq!(ev::raise(share, pot, call, 2.0 * call, 0.4).to_bits(), raw.to_bits());
}
}
#[test]
fn in_the_scope_a_call_needs_the_price_of_the_pot_after_rake() {
let _s = Scope::enter(0.02);
// Topf 0.20 + Call 0.10 = 0.30, erwarteter Rake 5 % = 0.015 (glatt, nicht auf den Cent):
// break-even 0.10 / 0.285.
near(break_even(0.20, 0.10), 0.10 / 0.285);
near(ev::call(0.5, 0.20, 0.10), 0.5 * 0.285 - 0.10);
near(ev::check(0.5, 0.20), 0.5 * 0.19);
}
#[test]
fn a_pot_won_by_a_fold_is_raked_too() {
let _s = Scope::enter(1.0);
// Topf 20 bb: Rake 1 bb, auch wenn niemand callt (keine "no flop, no drop" am Mikro-Tisch).
near(ev::raise(0.0, 20.0, 0.0, 10.0, 1.0), 19.0);
}
#[test]
fn the_decision_rake_is_smooth_up_to_the_cap() {
let _s = Scope::enter(1.0);
// Keine Cent-Stufe zwischen Nachbargroessen (die Stufe trieb Value-Bets auf die kleine Groesse).
near(of_pot(4.67), 0.2335);
near(of_pot(6.0), 0.3);
near(net(4.0), 3.8);
near(of_pot(1000.0), 10.0);
}
#[test]
fn a_raked_leaf_takes_the_rake_from_the_winner_only() {
let _s = Scope::enter(1.0);
// Showdown um 20 bb (je 10), Rake 1: Sieger +9, Verlierer -10, Split je -0.5.
let leaf = Payoff::Pair(vec![0.0, -10.0, 10.0, 0.0]).with_live_rake(2, 20.0);
match leaf {
Payoff::Raked { pair, rake } => {
near(rake, 1.0);
assert_eq!(pair, vec![-0.5, -10.0, 9.0, -0.5]);
}
other => panic!("not raked: {other:?}"),
}
// Fold: wer gewinnt, zahlt.
match Payoff::Flat(10.0).with_live_rake(2, 20.0) {
Payoff::Raked { pair, rake } => {
near(rake, 1.0);
assert!(pair.iter().all(|v| (v - 9.0).abs() < 1e-12));
}
other => panic!("not raked: {other:?}"),
}
match Payoff::Flat(-10.0).with_live_rake(2, 20.0) {
Payoff::Raked { pair, .. } => assert!(pair.iter().all(|v| (v + 10.0).abs() < 1e-12)),
other => panic!("not raked: {other:?}"),
}
}
#[test]
fn without_a_scope_the_river_trees_are_the_raw_ones() {
let raw = tree_with_chance(3, vec![1.0 / 9.0; 9], 6.0, 4.0);
assert!(raw.nodes.iter().all(|n| !matches!(n, Node::Terminal(Payoff::Raked { .. }))));
let g = build(3, vec![1.0 / 9.0; 9], &Bets::standard(6.0, 50.0, 0), &[]);
assert!(g.tree.nodes.iter().all(|n| !matches!(n, Node::Terminal(Payoff::Raked { .. }))));
}
#[test]
fn in_the_scope_every_river_leaf_pays_the_rake_of_its_pot() {
let _s = Scope::enter(1.0);
let t = tree_with_chance(3, vec![1.0 / 9.0; 9], 30.0, 20.0);
let rakes: Vec<f64> = t
.nodes
.iter()
.filter_map(|n| match n {
Node::Terminal(Payoff::Raked { rake, .. }) => Some(*rake),
_ => None,
})
.collect();
// check-check 30 -> 1.5, Fold-Toepfe 30 -> 1.5, gecallt 70 -> 3.5.
assert_eq!(rakes.len(), 5);
assert!(rakes.iter().all(|r| [1.5, 3.5].contains(r)), "{rakes:?}");
let g = build(3, vec![1.0 / 9.0; 9], &Bets::standard(30.0, 100.0, 0), &[]);
assert!(g.tree.nodes.iter().all(|n| !matches!(n, Node::Terminal(Payoff::Pair(_) | Payoff::Flat(_)))));
}