Files
pokerfreak/src/exploit/street_continuation.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

143 lines
5.3 KiB
Rust

use super::bet_ratio::bet_ratios;
use super::made_ladder::rung;
use super::range_spec::Continuation;
use super::size_notch::size_notch;
use super::style::{classify, Style};
use crate::game::{ActionRecord, SeenAction, Spot, Street, Villain};
use crate::read::made::Made;
/// A call of a bet at least this big (pot fractions) shows a hand with some showdown value.
const BIG_BET: f64 = 0.6;
/// Floor rung of a bet / of a raise (or all-in) per street (flop, turn, river), see `LADDER`
/// in `made_ladder`: middle pair, top pair weak kicker, top pair good kicker for bets;
/// top pair good kicker, overpair, two pair for raises.
const BET_RUNG: [i32; 3] = [2, 3, 4];
const RAISE_RUNG: [i32; 3] = [4, 5, 6];
/// Draws are still in on flop and turn, not on the river.
const DRAWS: [bool; 3] = [true, true, false];
/// Looser styles lose one rung, the nit gains one.
fn style_shift(villain: &Villain) -> i32 {
match villain.profile.map(|p| classify(&p)) {
Some(Style::CallingStation | Style::LooseAggressive) => -1,
Some(Style::Nit) => 1,
_ => 0,
}
}
/// Bet = 0, raise (RAISE or ALL_IN) = 1.
fn level(action: SeenAction) -> Option<usize> {
match action {
SeenAction::Bet => Some(0),
SeenAction::Raise | SeenAction::AllIn => Some(1),
_ => None,
}
}
/// The strongest aggression of the villain on `street`: highest level, then biggest ratio.
fn own_aggression(
history: &[ActionRecord],
ratios: &[Option<f64>],
street: Street,
seat: u8,
) -> Option<(usize, Option<f64>)> {
history
.iter()
.zip(ratios)
.filter(|(r, _)| r.street == street && r.seat == seat)
.filter_map(|(r, ratio)| level(r.action).map(|l| (l, *ratio)))
.max_by(|a, b| {
a.0.cmp(&b.0).then(
a.1.unwrap_or(-1.0)
.partial_cmp(&b.1.unwrap_or(-1.0))
.unwrap_or(std::cmp::Ordering::Equal),
)
})
}
/// Did the villain call, on `street`, a bet or raise (by anyone) of at least `BIG_BET` pots?
fn called_big_bet(
history: &[ActionRecord],
ratios: &[Option<f64>],
street: Street,
seat: u8,
) -> bool {
history.iter().enumerate().any(|(i, r)| {
r.street == street
&& r.seat == seat
&& r.action == SeenAction::Call
&& history[..i]
.iter()
.zip(&ratios[..i])
.rev()
.find(|(b, _)| b.street == street && b.action.is_aggressive())
.is_some_and(|(_, ratio)| ratio.is_some_and(|x| x >= BIG_BET))
})
}
fn merge(a: Option<(Made, bool)>, b: Option<(Made, bool)>) -> Option<(Made, bool)> {
match (a, b) {
(Some((ma, da)), Some((mb, db))) => Some((ma.max(mb), da && db)),
(one, other) => one.or(other),
}
}
/// One continuation for the villain on `street`, if their actions there say anything.
fn on_street(
spot: &Spot,
ratios: &[Option<f64>],
villain: &Villain,
street: Street,
) -> Option<Continuation> {
let slot = street as usize - 1;
let made_bet =
own_aggression(&spot.history, ratios, street, villain.seat).map(|(lvl, ratio)| {
let base = [BET_RUNG, RAISE_RUNG][lvl][slot];
(
rung(base, size_notch(ratio) + style_shift(villain)),
DRAWS[slot],
)
});
let made_call = called_big_bet(&spot.history, ratios, street, villain.seat).then(|| {
(
if street == Street::River {
Made::MiddlePair
} else {
Made::BottomPair
},
DRAWS[slot],
)
});
merge(made_bet, made_call).map(|(min_made, draws_continue)| Continuation {
board_len: street.board_len(),
min_made,
draws_continue,
})
}
/// Postflop narrowing from the villain own actions, one entry per dealt street
/// (`board_len <= spot.board.len()`), sorted by board length.
///
/// - **Bet** keeps `[middle pair, top pair weak kicker, top pair good kicker]+` on
/// flop/turn/river; **raise or all-in** keeps `[top pair good kicker, overpair, two pair]+`.
/// Flop and turn bets keep draws, the river keeps made hands only. Several actions on
/// one street: the highest level (then the biggest) counts.
/// - The size (chips added / pot before, from the amounts in the history) moves the floor
/// by `size_notch` rungs: bigger is stricter. Unknown sizes or pots: no move.
/// - A calling station or loose-aggressive style (see `style::classify`) lowers the floor
/// one rung, a nit raises it one. The floor never drops below bottom pair.
/// - **Checks and calls add nothing**: the continuation only expresses a minimum strength,
/// and a check does not say the hand is weak (traps) nor does a call bound it from
/// below in a useful way. One exception, a mild floor: a call of a bet of at least 0.6 pot
/// keeps bottom pair or better (or a draw) on flop/turn, middle pair or better on the river.
/// Combined with the villain own bet on the same street the stricter floor wins.
pub fn continuations(spot: &Spot, villain: &Villain) -> Vec<Continuation> {
let ratios = bet_ratios(&spot.history);
[Street::Flop, Street::Turn, Street::River]
.into_iter()
.filter(|street| street.board_len() <= spot.board.len())
.filter_map(|street| on_street(spot, &ratios, villain, street))
.collect()
}