Die Welt soll nichts verraten. Woerter, die ein Gegenueber implizieren (echt vs. unecht, live, Mensch), sind aus Prosa, Kommentaren und Docstrings raus; Namen (mensch_ruhe_s, echte_chops) und der Altwert "echt" im Spielplan bleiben. Nur Kommentare und Docstrings angefasst, damit keine Einrueckung faellt.
143 lines
5.4 KiB
Rust
143 lines
5.4 KiB
Rust
use super::bet_ratio::bet_ratios;
|
|
use super::bluff_share::bluff_share;
|
|
use super::made_ladder::rung;
|
|
use super::range_spec::Continuation;
|
|
use super::size_notch::size_notch;
|
|
use super::style_rung::style_rung;
|
|
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];
|
|
|
|
/// 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))
|
|
})
|
|
}
|
|
|
|
/// (floor, draws continue, bluff share)
|
|
type Floor = (Made, bool, f64);
|
|
|
|
fn merge(a: Option<Floor>, b: Option<Floor>) -> Option<Floor> {
|
|
match (a, b) {
|
|
(Some((ma, da, ba)), Some((mb, db, bb))) => Some((ma.max(mb), da && db, ba.max(bb))),
|
|
(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_rung(villain)),
|
|
DRAWS[slot],
|
|
bluff_share(villain.profile.as_ref(), ratio, street),
|
|
)
|
|
});
|
|
let made_call = called_big_bet(&spot.history, ratios, street, villain.seat).then(|| {
|
|
(
|
|
if street == Street::River {
|
|
Made::MiddlePair
|
|
} else {
|
|
Made::BottomPair
|
|
},
|
|
DRAWS[slot],
|
|
0.0,
|
|
)
|
|
});
|
|
merge(made_bet, made_call).map(|(min_made, draws_continue, bluff_share)| Continuation {
|
|
board_len: street.board_len(),
|
|
min_made,
|
|
draws_continue,
|
|
bluff_share,
|
|
})
|
|
}
|
|
|
|
/// 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.
|
|
/// - Bets and raises keep a **bluff fraction** below their floor (`bluff_share`: bet size,
|
|
/// street, style or aggression); calls keep none.
|
|
/// - **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()
|
|
}
|