Files
pokerfreak/src/cfr/terminal_value.rs
T
mmintelandClaude Opus 5.5 a7b32cf425 Add CFR preflop chart generator, frozen charts and lookup
Pure CFR+ core over a 169-class abstraction, push/fold and open/call/3-bet games,
Nash/Kuhn/plausibility/lookup tests, chartgen binary, frozen equity and charts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 13:05:07 +01:00

62 lines
1.9 KiB
Rust

//! Counterfactual value of a terminal node for one traverser, given the opponent's reach.
//!
//! For player 0: `value[i] = sum_j chance[i][j] * opp[j] * payoff(i, j)`.
//! For player 1: `value[j] = -sum_i chance[i][j] * opp[i] * payoff(i, j)` (zero-sum).
//! The traverser's own reach is not part of the value.
use super::tree::Payoff;
pub fn terminal_value(payoff: &Payoff, chance: &[f64], classes: usize, player: usize, opp: &[f64]) -> Vec<f64> {
let n = classes;
let mut out = vec![0.0; n];
for i in 0..n {
let row = &chance[i * n..(i + 1) * n];
let pair_row = match payoff {
Payoff::Pair(m) => m.get(i * n..(i + 1) * n),
_ => None,
};
let scale = match payoff {
Payoff::Flat(c) => *c,
Payoff::Own(v) => v.get(i).copied().unwrap_or(0.0),
Payoff::Pair(_) => 1.0,
};
if player == 0 {
let mut acc = 0.0;
match pair_row {
Some(m) => {
for j in 0..n {
acc += row[j] * opp[j] * m[j];
}
}
None if matches!(payoff, Payoff::Pair(_)) => {}
None => {
for j in 0..n {
acc += row[j] * opp[j];
}
acc *= scale;
}
}
out[i] = acc;
} else {
let weight = opp[i];
if weight == 0.0 {
continue;
}
match pair_row {
Some(m) => {
for j in 0..n {
out[j] -= row[j] * weight * m[j];
}
}
None if matches!(payoff, Payoff::Pair(_)) => {}
None => {
for j in 0..n {
out[j] -= row[j] * weight * scale;
}
}
}
}
}
out
}