Files
pokerfreak/src/cfr/payoffs.rs
T
mmintelandClaude Opus 5.5 3d65e856f6 Rake-aware CFR and charts: rake rule, ante situation, regenerated preflop charts
Secures the worktree's uncommitted state before merging into main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 10:36:11 +01:00

48 lines
2.0 KiB
Rust

//! Payoff matrices for the two kinds of showdown the games use. `u(i, j)` is always the net
//! result in bb for player 0 (invested chips already subtracted). The pot is split after the
//! rake of `env`; a fold pays none.
use super::environment::Environment;
use super::hand_class::CLASS_COUNT;
use super::spot_params::REALIZATION_SPREAD;
use super::tree::Payoff;
fn matrix(env: &Environment, rake: f64, f: impl Fn(f64) -> f64) -> Payoff {
let pair = (0..CLASS_COUNT * CLASS_COUNT)
.map(|k| f(env.equity.get(k / CLASS_COUNT, k % CLASS_COUNT)))
.collect();
if rake > 0.0 {
Payoff::Raked { pair, rake }
} else {
Payoff::Pair(pair)
}
}
/// All-in showdown: raw equity of the whole pot.
pub fn all_in(env: &Environment, pot: f64, invested: f64) -> Payoff {
let rake = env.rake.all_in(pot);
matrix(env, rake, |eq| (pot - rake) * eq - invested)
}
/// Pot not yet decided by chips: each side gets `share` of it (see `share`).
/// `player0_in_position` says who is who.
pub fn postflop(env: &Environment, pot: f64, invested: f64, player0_in_position: bool, realization: f64) -> Payoff {
let rake = env.rake.postflop(pot);
matrix(env, rake, |eq| (pot - rake) * share(eq, player0_in_position, realization) - invested)
}
/// Player 0's share of the pot given his all-in equity: stretch the equity around 50 % by
/// `REALIZATION_SPREAD`, weight the out-of-position side by `realization`, split in proportion.
/// The two players' shares always add up to 1.
pub fn share(equity: f64, player0_in_position: bool, realization: f64) -> f64 {
let stretched = (0.5 + REALIZATION_SPREAD * (equity - 0.5)).clamp(0.0, 1.0);
let (ip, oop) = if player0_in_position {
(stretched, realization * (1.0 - stretched))
} else {
(1.0 - stretched, realization * stretched)
};
let total = ip + oop;
let ip_share = if total > 0.0 { ip / total } else { 0.5 };
if player0_in_position { ip_share } else { 1.0 - ip_share }
}