Files
pokerfreak/src/exploit/pot_trace.rs
T
mmintelandClaude Opus 5.5 9a9c6c946d Range narrowing from action history, position from inferred button
Wire: optional history decoding. exploit::range_model: role band + postflop
continuations. preflop::button / seat_position: button inference from blinds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 12:41:03 +01:00

42 lines
1.6 KiB
Rust

use crate::game::{ActionRecord, SeenAction};
/// What the seat had in on this street before `history[index]`: the last amount of an
/// earlier non-ante record of the same seat and street (0 if none).
fn already_in(history: &[ActionRecord], index: usize) -> f64 {
let record = &history[index];
history[..index]
.iter()
.rev()
.filter(|r| {
r.seat == record.seat && r.street == record.street && r.action != SeenAction::PostAnte
})
.find_map(|r| r.amount.filter(|a| a.is_finite()))
.unwrap_or(0.0)
}
/// Chips `history[index]` added to the pot. `None` when it cannot be told: a paying action
/// without a (usable) amount. Folds and checks add 0. Out-of-range index gives `None`.
pub fn contribution(history: &[ActionRecord], index: usize) -> Option<f64> {
let record = history.get(index)?;
match record.action {
SeenAction::Fold | SeenAction::Check => Some(0.0),
SeenAction::PostAnte => record.amount.filter(|a| a.is_finite() && *a >= 0.0),
_ => record
.amount
.filter(|a| a.is_finite() && *a >= 0.0)
.map(|a| (a - already_in(history, index)).max(0.0)),
}
}
/// The pot before each record, summed from the contributions. From the first record whose
/// contribution is unknown on, the pot is unknown (`None`).
pub fn pot_before(history: &[ActionRecord]) -> Vec<Option<f64>> {
(0..history.len())
.scan(Some(0.0), |pot, index| {
let before = *pot;
*pot = before.zip(contribution(history, index)).map(|(p, c)| p + c);
Some(before)
})
.collect()
}