Bluffing and bluff catching driven by opponent frequencies
- exploit::fold_chance: documented foldToBet -> P(fold) map by bet size, per villain - engine: two-branch EV for every raise (fold branch, called branch vs calling range) - semibluffs first, pure bluffs heads-up above a fold and EV threshold - betting ranges keep a bluff share (size, street, style or new profile.aggression) - guards: no bluffs vs never-folders, no bluff catch vs ranges without bluffs - steal width in unopened pots from how often the blinds fold - combo-list sampling for narrow two-card ranges Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+57
-58
@@ -1,58 +1,57 @@
|
||||
use super::fold_equity_scale::{fold_equity_scale, MAX_SCALE, MIN_SCALE};
|
||||
use super::profile::Profile;
|
||||
use super::style::classify;
|
||||
use super::style_shift::shift_for;
|
||||
use super::thresholds::Thresholds;
|
||||
|
||||
/// Output ranges: whatever the inputs, the engine never sees thresholds outside these.
|
||||
const CALL_MARGIN: (f64, f64) = (0.0, 0.15);
|
||||
const VALUE_RAISE: (f64, f64) = (0.52, 0.85);
|
||||
const ABSTAIN_BAND: (f64, f64) = (0.0, 0.05);
|
||||
const RANGE_WIDTH: (f64, f64) = (0.6, 1.4);
|
||||
|
||||
fn bounded(x: f64, (low, high): (f64, f64)) -> f64 {
|
||||
if x.is_nan() {
|
||||
low
|
||||
} else {
|
||||
x.clamp(low, high)
|
||||
}
|
||||
}
|
||||
|
||||
/// `base` as seen against one profile; `None` when the profile says nothing.
|
||||
fn against(base: Thresholds, profile: &Profile) -> Option<Thresholds> {
|
||||
shift_for(classify(profile)).map(|shift| Thresholds {
|
||||
call_margin: bounded(base.call_margin + shift.call_margin, CALL_MARGIN),
|
||||
value_raise: bounded(base.value_raise + shift.value_raise, VALUE_RAISE),
|
||||
abstain_band: bounded(base.abstain_band, ABSTAIN_BAND),
|
||||
fold_equity_scale: (base.fold_equity_scale
|
||||
* fold_equity_scale(profile.fold_to_bet, shift.fold_equity_default))
|
||||
.clamp(MIN_SCALE, MAX_SCALE),
|
||||
range_width_scale: bounded(base.range_width_scale * shift.range_width, RANGE_WIDTH),
|
||||
})
|
||||
}
|
||||
|
||||
/// Conservative merge of two opponents: keep the harder-to-continue value of each
|
||||
/// threshold (higher margins, lower fold equity, narrower ranges).
|
||||
fn conservative(a: Thresholds, b: Thresholds) -> Thresholds {
|
||||
Thresholds {
|
||||
call_margin: a.call_margin.max(b.call_margin),
|
||||
value_raise: a.value_raise.max(b.value_raise),
|
||||
abstain_band: a.abstain_band.max(b.abstain_band),
|
||||
fold_equity_scale: a.fold_equity_scale.min(b.fold_equity_scale),
|
||||
range_width_scale: a.range_width_scale.min(b.range_width_scale),
|
||||
}
|
||||
}
|
||||
|
||||
/// Shift thresholds for the given live opponents' profiles. No profiles → `base` unchanged.
|
||||
///
|
||||
/// Each profile is classified (`style::classify`) and moves `base` by its style
|
||||
/// (`style_shift`); foldToBet, when given, sets `fold_equity_scale` continuously.
|
||||
/// Profiles with no usable numbers are ignored; with several informative ones the
|
||||
/// results are merged conservatively. Outputs are clamped to sane ranges.
|
||||
pub fn adjust(base: Thresholds, profiles: &[Profile]) -> Thresholds {
|
||||
profiles
|
||||
.iter()
|
||||
.filter_map(|p| against(base, p))
|
||||
.reduce(conservative)
|
||||
.unwrap_or(base)
|
||||
}
|
||||
use super::fold_equity_scale::{MAX_SCALE, MIN_SCALE};
|
||||
use super::profile::Profile;
|
||||
use super::style::classify;
|
||||
use super::style_shift::shift_for;
|
||||
use super::thresholds::Thresholds;
|
||||
|
||||
/// Output ranges: whatever the inputs, the engine never sees thresholds outside these.
|
||||
const CALL_MARGIN: (f64, f64) = (0.0, 0.15);
|
||||
const VALUE_RAISE: (f64, f64) = (0.52, 0.85);
|
||||
const ABSTAIN_BAND: (f64, f64) = (0.0, 0.05);
|
||||
const RANGE_WIDTH: (f64, f64) = (0.6, 1.4);
|
||||
|
||||
fn bounded(x: f64, (low, high): (f64, f64)) -> f64 {
|
||||
if x.is_nan() {
|
||||
low
|
||||
} else {
|
||||
x.clamp(low, high)
|
||||
}
|
||||
}
|
||||
|
||||
/// `base` as seen against one profile; `None` when the profile says nothing.
|
||||
fn against(base: Thresholds, profile: &Profile) -> Option<Thresholds> {
|
||||
shift_for(classify(profile)).map(|shift| Thresholds {
|
||||
call_margin: bounded(base.call_margin + shift.call_margin, CALL_MARGIN),
|
||||
value_raise: bounded(base.value_raise + shift.value_raise, VALUE_RAISE),
|
||||
abstain_band: bounded(base.abstain_band, ABSTAIN_BAND),
|
||||
fold_equity_scale: base.fold_equity_scale.clamp(MIN_SCALE, MAX_SCALE),
|
||||
range_width_scale: bounded(base.range_width_scale * shift.range_width, RANGE_WIDTH),
|
||||
})
|
||||
}
|
||||
|
||||
/// Conservative merge of two opponents: keep the harder-to-continue value of each
|
||||
/// threshold (higher margins, lower fold equity, narrower ranges).
|
||||
fn conservative(a: Thresholds, b: Thresholds) -> Thresholds {
|
||||
Thresholds {
|
||||
call_margin: a.call_margin.max(b.call_margin),
|
||||
value_raise: a.value_raise.max(b.value_raise),
|
||||
abstain_band: a.abstain_band.max(b.abstain_band),
|
||||
fold_equity_scale: a.fold_equity_scale.min(b.fold_equity_scale),
|
||||
range_width_scale: a.range_width_scale.min(b.range_width_scale),
|
||||
}
|
||||
}
|
||||
|
||||
/// Shift thresholds for the given live opponents' profiles. No profiles → `base` unchanged.
|
||||
///
|
||||
/// Each profile is classified (`style::classify`) and moves `base` by its style
|
||||
/// (`style_shift`). `fold_equity_scale` stays as given: how often each opponent folds is
|
||||
/// estimated per opponent (`fold_chance`), so the profile is not counted here a second time.
|
||||
/// Profiles with no usable numbers are ignored; with several informative ones the
|
||||
/// results are merged conservatively. Outputs are clamped to sane ranges.
|
||||
pub fn adjust(base: Thresholds, profiles: &[Profile]) -> Thresholds {
|
||||
profiles
|
||||
.iter()
|
||||
.filter_map(|p| against(base, p))
|
||||
.reduce(conservative)
|
||||
.unwrap_or(base)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
//! What part of an opponent's betting range is a bluff.
|
||||
//!
|
||||
//! | step | rule |
|
||||
//! |---|---|
|
||||
//! | base | `s / (1 + 2s)` for a bet of `s` pots: the river share at which a caller is indifferent (Chen/Ankenman, "The Mathematics of Poker"); unknown or broken size counts as 0.66 |
|
||||
//! | street | river 1.0, turn 0.6, flop 0.5 (earlier, draws do the bluffing and already stay in the range), preflop 0 |
|
||||
//! | style | nit 0.4, calling station 0.5 (passive players bet for value), loose-aggressive 1.5, otherwise 1.0 |
|
||||
//! | aggression | when the profile gives it, `aggression / 0.45` (0.45 = an average aggression frequency) replaces the style factor, clamped to [0, 2] |
|
||||
//! | cap | at most 0.6 |
|
||||
|
||||
use super::profile::Profile;
|
||||
use super::style::{classify, Style};
|
||||
use crate::game::Street;
|
||||
|
||||
pub const NEUTRAL_RATIO: f64 = 0.66;
|
||||
pub const MAX_BLUFF_SHARE: f64 = 0.6;
|
||||
const AVERAGE_AGGRESSION: f64 = 0.45;
|
||||
const MAX_FACTOR: f64 = 2.0;
|
||||
|
||||
fn street_factor(street: Street) -> f64 {
|
||||
match street {
|
||||
Street::Preflop => 0.0,
|
||||
Street::Flop => 0.5,
|
||||
Street::Turn => 0.6,
|
||||
Street::River => 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
fn style_factor(profile: Option<&Profile>) -> f64 {
|
||||
let Some(p) = profile else { return 1.0 };
|
||||
match p.aggression.filter(|a| !a.is_nan()) {
|
||||
Some(a) => (a.clamp(0.0, 1.0) / AVERAGE_AGGRESSION).clamp(0.0, MAX_FACTOR),
|
||||
None => match classify(p) {
|
||||
Style::Nit => 0.4,
|
||||
Style::CallingStation => 0.5,
|
||||
Style::LooseAggressive => 1.5,
|
||||
Style::Regular | Style::Unknown => 1.0,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Bluff share of the range that bet `ratio` pots on `street`. Always in `[0, MAX_BLUFF_SHARE]`.
|
||||
pub fn bluff_share(profile: Option<&Profile>, ratio: Option<f64>, street: Street) -> f64 {
|
||||
let s = ratio.filter(|r| r.is_finite() && *r > 0.0).unwrap_or(NEUTRAL_RATIO);
|
||||
let balanced = s / (1.0 + 2.0 * s);
|
||||
(balanced * street_factor(street) * style_factor(profile)).clamp(0.0, MAX_BLUFF_SHARE)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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::{Street, Villain};
|
||||
|
||||
/// Rung of the weakest hand that calls a bet, per street (flop, turn, river) on
|
||||
/// `made_ladder`: bottom pair on flop and turn, middle pair on the river.
|
||||
const CALL_RUNG: [i32; 3] = [1, 1, 2];
|
||||
|
||||
/// What a villain continues with when hero bets `ratio` pots on `street`: the calling
|
||||
/// floor moved by the size (`size_notch`) and the villain's style (`style_rung`); draws
|
||||
/// call on flop and turn. This is the range the called branch of a bet is played against.
|
||||
pub fn call_continuation(villain: &Villain, street: Street, ratio: f64) -> Continuation {
|
||||
let slot = (street as usize).clamp(1, 3) - 1;
|
||||
Continuation {
|
||||
board_len: street.board_len(),
|
||||
min_made: rung(CALL_RUNG[slot], size_notch(Some(ratio)) + style_rung(villain)),
|
||||
draws_continue: street != Street::River,
|
||||
bluff_share: 0.0,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
//! How likely one opponent folds to a bet: the documented map from their profile.
|
||||
//!
|
||||
//! | step | rule |
|
||||
//! |---|---|
|
||||
//! | base `f` | `foldToBet`, clamped to [0, 1]; without it the style default: nit 0.65, calling station 0.20, loose-aggressive 0.40, otherwise 0.45 |
|
||||
//! | size | `p = 1 - (1 - f)^(ratio / 0.66)`: foldToBet is a frequency against a typical two-thirds-pot bet, so at that size `p = f`; smaller bets fold less, bigger more, a zero bet never |
|
||||
//! | raised | `p * 0.7` when the opponent already bet and is being raised (money invested, range stronger) |
|
||||
//! | cap | at most 0.95: nobody folds for sure |
|
||||
//!
|
||||
//! `ratio` is the pressure: chips beyond a call over the pot after calling
|
||||
//! (`table_fold::pressure_ratio`).
|
||||
|
||||
use super::profile::Profile;
|
||||
use super::style::{classify, Style};
|
||||
|
||||
/// Bet size (pot fraction) at which foldToBet is taken to be measured.
|
||||
pub const REFERENCE_RATIO: f64 = 0.66;
|
||||
/// Fold-to-bet of an opponent we know nothing about.
|
||||
pub const DEFAULT_FOLD_TO_BET: f64 = 0.45;
|
||||
/// Factor when the opponent is raised after betting.
|
||||
pub const RAISE_RESISTANCE: f64 = 0.7;
|
||||
/// Largest fold chance ever assumed for one opponent.
|
||||
pub const MAX_FOLD: f64 = 0.95;
|
||||
|
||||
fn style_default(style: Style) -> f64 {
|
||||
match style {
|
||||
Style::Nit => 0.65,
|
||||
Style::CallingStation => 0.20,
|
||||
Style::LooseAggressive => 0.40,
|
||||
Style::Regular | Style::Unknown => DEFAULT_FOLD_TO_BET,
|
||||
}
|
||||
}
|
||||
|
||||
/// The opponent's fold-to-bet at the reference size.
|
||||
pub fn fold_base(profile: Option<&Profile>) -> f64 {
|
||||
match profile {
|
||||
None => DEFAULT_FOLD_TO_BET,
|
||||
Some(p) => match p.fold_to_bet.filter(|f| !f.is_nan()) {
|
||||
Some(f) => f.clamp(0.0, 1.0),
|
||||
None => style_default(classify(p)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// P(this opponent folds) to a bet of `ratio` pots. Total: any input gives `[0, MAX_FOLD]`.
|
||||
pub fn fold_chance(profile: Option<&Profile>, ratio: f64, facing_raise: bool) -> f64 {
|
||||
let f = fold_base(profile);
|
||||
let ratio = if ratio.is_nan() { 0.0 } else { ratio.max(0.0) };
|
||||
let sized = if f >= 1.0 {
|
||||
if ratio > 0.0 { 1.0 } else { 0.0 }
|
||||
} else {
|
||||
1.0 - (1.0 - f).powf(ratio / REFERENCE_RATIO)
|
||||
};
|
||||
let raised = if facing_raise { sized * RAISE_RESISTANCE } else { sized };
|
||||
if raised.is_nan() { 0.0 } else { raised.clamp(0.0, MAX_FOLD) }
|
||||
}
|
||||
@@ -1,13 +1,5 @@
|
||||
//! Fold-equity multiplier from an opponent's foldToBet.
|
||||
//! Bounds of `Thresholds::fold_equity_scale`, the shared multiplier on every opponent's
|
||||
//! fold chance (1.0 = neutral). The profile itself enters per opponent (`fold_chance`).
|
||||
|
||||
pub const MIN_SCALE: f64 = 0.3;
|
||||
pub const MAX_SCALE: f64 = 1.6;
|
||||
|
||||
/// `0.35 + 1.3 * foldToBet` clamped to `[0.3, 1.6]` (a 50 % folder is neutral, 1.0).
|
||||
/// Continuous and increasing in `fold_to_bet`; without a figure, `fallback`.
|
||||
pub fn fold_equity_scale(fold_to_bet: Option<f64>, fallback: f64) -> f64 {
|
||||
fold_to_bet
|
||||
.filter(|b| !b.is_nan())
|
||||
.map_or(fallback, |b| 0.35 + 1.3 * b.clamp(0.0, 1.0))
|
||||
.clamp(MIN_SCALE, MAX_SCALE)
|
||||
}
|
||||
|
||||
+28
-22
@@ -1,22 +1,28 @@
|
||||
//! Exploitation layer: reads opponent profiles, moves thresholds and range guesses.
|
||||
|
||||
pub mod adjust;
|
||||
pub mod band_bounds;
|
||||
pub mod band_stretch;
|
||||
pub mod bet_ratio;
|
||||
pub mod fold_equity_scale;
|
||||
pub mod made_ladder;
|
||||
pub mod pot_trace;
|
||||
pub mod preflop_role;
|
||||
pub mod profile;
|
||||
pub mod range_guess;
|
||||
pub mod range_model;
|
||||
pub mod range_spec;
|
||||
pub mod range_narrowing;
|
||||
pub mod role_band;
|
||||
pub mod role_from_history;
|
||||
pub mod size_notch;
|
||||
pub mod street_continuation;
|
||||
pub mod style;
|
||||
pub mod style_shift;
|
||||
pub mod thresholds;
|
||||
//! Exploitation layer: reads opponent profiles, moves thresholds and range guesses.
|
||||
|
||||
pub mod adjust;
|
||||
pub mod band_bounds;
|
||||
pub mod band_stretch;
|
||||
pub mod bet_ratio;
|
||||
pub mod bluff_share;
|
||||
pub mod call_floor;
|
||||
pub mod fold_chance;
|
||||
pub mod fold_equity_scale;
|
||||
pub mod made_ladder;
|
||||
pub mod pot_trace;
|
||||
pub mod preflop_role;
|
||||
pub mod profile;
|
||||
pub mod range_guess;
|
||||
pub mod range_model;
|
||||
pub mod range_spec;
|
||||
pub mod range_narrowing;
|
||||
pub mod role_band;
|
||||
pub mod role_from_history;
|
||||
pub mod size_notch;
|
||||
pub mod street_continuation;
|
||||
pub mod steal_width;
|
||||
pub mod style;
|
||||
pub mod style_rung;
|
||||
pub mod style_shift;
|
||||
pub mod table_fold;
|
||||
pub mod thresholds;
|
||||
|
||||
+15
-11
@@ -1,11 +1,15 @@
|
||||
/// Observed opponent tendencies, all frequencies in `[0, 1]`. Every field optional.
|
||||
/// Wire shape (extension): `"profile": {"vpip": 0.45, "pfr": 0.08, "foldToBet": 0.3}`.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Default)]
|
||||
pub struct Profile {
|
||||
/// Voluntarily put money in pot, preflop.
|
||||
pub vpip: Option<f64>,
|
||||
/// Preflop raise frequency.
|
||||
pub pfr: Option<f64>,
|
||||
/// How often the player folds to a bet postflop.
|
||||
pub fold_to_bet: Option<f64>,
|
||||
}
|
||||
/// Observed opponent tendencies, all frequencies in `[0, 1]`. Every field optional.
|
||||
/// Wire shape (extension):
|
||||
/// `"profile": {"vpip": 0.45, "pfr": 0.08, "foldToBet": 0.3, "aggression": 0.4}`.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Default)]
|
||||
pub struct Profile {
|
||||
/// Voluntarily put money in pot, preflop.
|
||||
pub vpip: Option<f64>,
|
||||
/// Preflop raise frequency.
|
||||
pub pfr: Option<f64>,
|
||||
/// How often the player folds to a bet postflop.
|
||||
pub fold_to_bet: Option<f64>,
|
||||
/// Share of the player's postflop actions that are bets or raises (aggression
|
||||
/// frequency). Steers how much of their betting range is a bluff (`bluff_share`).
|
||||
pub aggression: Option<f64>,
|
||||
}
|
||||
|
||||
+31
-28
@@ -1,28 +1,31 @@
|
||||
use crate::read::made::Made;
|
||||
|
||||
/// A villain's estimated holdings as data; the engine turns it into a predicate.
|
||||
///
|
||||
/// A hand is in the range when its preflop percentile lies in `[lo, hi]`
|
||||
/// (0 = best hand) and it satisfies every `Continuation`.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct RangeSpec {
|
||||
pub lo: f64,
|
||||
pub hi: f64,
|
||||
pub continues: Vec<Continuation>,
|
||||
}
|
||||
|
||||
/// "Villain bet or raised when the board had `board_len` cards": only hands at least
|
||||
/// `min_made` at that point stay in — plus drawing hands when `draws_continue`.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Continuation {
|
||||
pub board_len: usize,
|
||||
pub min_made: Made,
|
||||
pub draws_continue: bool,
|
||||
}
|
||||
|
||||
impl RangeSpec {
|
||||
/// The best `top` fraction of starting hands, no postflop filter.
|
||||
pub fn top(top: f64) -> RangeSpec {
|
||||
RangeSpec { lo: 0.0, hi: top, continues: Vec::new() }
|
||||
}
|
||||
}
|
||||
use crate::read::made::Made;
|
||||
|
||||
/// A villain's estimated holdings as data; the engine turns it into a predicate.
|
||||
///
|
||||
/// A hand is in the range when its preflop percentile lies in `[lo, hi]`
|
||||
/// (0 = best hand) and it satisfies every `Continuation`.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct RangeSpec {
|
||||
pub lo: f64,
|
||||
pub hi: f64,
|
||||
pub continues: Vec<Continuation>,
|
||||
}
|
||||
|
||||
/// "Villain bet or raised when the board had `board_len` cards": only hands at least
|
||||
/// `min_made` at that point stay in — plus drawing hands when `draws_continue` — plus
|
||||
/// a bluff fraction: hands below the floor are admitted so that they make up
|
||||
/// `bluff_share` of what passes (`engine::range_filter`). 0 = a pure value range.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Continuation {
|
||||
pub board_len: usize,
|
||||
pub min_made: Made,
|
||||
pub draws_continue: bool,
|
||||
pub bluff_share: f64,
|
||||
}
|
||||
|
||||
impl RangeSpec {
|
||||
/// The best `top` fraction of starting hands, no postflop filter.
|
||||
pub fn top(top: f64) -> RangeSpec {
|
||||
RangeSpec { lo: 0.0, hi: top, continues: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
use super::fold_chance::{fold_base, DEFAULT_FOLD_TO_BET};
|
||||
use crate::game::Spot;
|
||||
|
||||
/// Width change per point of average fold-to-bet above the neutral 0.45.
|
||||
const PER_FOLD: f64 = 1.5;
|
||||
const BOUNDS: (f64, f64) = (0.7, 1.4);
|
||||
|
||||
/// Opening-width multiplier for an unopened pot, from how often the players behind fold:
|
||||
/// `1 + 1.5 * (mean fold_base - 0.45)`, clamped to [0.7, 1.4]. Nits behind widen the
|
||||
/// steal, calling stations narrow it; no live villain or no profiles: 1.0.
|
||||
pub fn steal_width(spot: &Spot) -> f64 {
|
||||
let folds: Vec<f64> = spot.live_villains().map(|v| fold_base(v.profile.as_ref())).collect();
|
||||
if folds.is_empty() {
|
||||
return 1.0;
|
||||
}
|
||||
let mean = folds.iter().sum::<f64>() / folds.len() as f64;
|
||||
(1.0 + PER_FOLD * (mean - DEFAULT_FOLD_TO_BET)).clamp(BOUNDS.0, BOUNDS.1)
|
||||
}
|
||||
+142
-142
@@ -1,142 +1,142 @@
|
||||
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()
|
||||
}
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
use super::style::{classify, Style};
|
||||
use crate::game::Villain;
|
||||
|
||||
/// How a villain's style moves a made-hand floor on `made_ladder`: looser styles
|
||||
/// (calling station, loose-aggressive) one rung down, the nit one up.
|
||||
pub fn style_rung(villain: &Villain) -> i32 {
|
||||
match villain.profile.map(|p| classify(&p)) {
|
||||
Some(Style::CallingStation | Style::LooseAggressive) => -1,
|
||||
Some(Style::Nit) => 1,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
+45
-51
@@ -1,51 +1,45 @@
|
||||
//! How each style moves the thresholds, as data.
|
||||
|
||||
use super::style::Style;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Shift {
|
||||
/// Added to `call_margin`.
|
||||
pub call_margin: f64,
|
||||
/// Added to `value_raise`.
|
||||
pub value_raise: f64,
|
||||
/// Multiplies `range_width_scale`.
|
||||
pub range_width: f64,
|
||||
/// `fold_equity_scale` to use when the profile has no foldToBet figure.
|
||||
pub fold_equity_default: f64,
|
||||
}
|
||||
|
||||
const NONE: Shift = Shift {
|
||||
call_margin: 0.0,
|
||||
value_raise: 0.0,
|
||||
range_width: 1.0,
|
||||
fold_equity_default: 1.0,
|
||||
};
|
||||
|
||||
/// `None` for `Unknown`: nothing is learned from an empty profile.
|
||||
pub fn shift_for(style: Style) -> Option<Shift> {
|
||||
match style {
|
||||
Style::Unknown => None,
|
||||
Style::Regular => Some(NONE),
|
||||
// Their bets are strong, they fold to ours, we defend less.
|
||||
Style::Nit => Some(Shift {
|
||||
call_margin: 0.04,
|
||||
value_raise: 0.02,
|
||||
range_width: 0.85,
|
||||
fold_equity_default: 1.25,
|
||||
}),
|
||||
// They call too much: value-bet thinner, never bluff.
|
||||
Style::CallingStation => Some(Shift {
|
||||
call_margin: 0.0,
|
||||
value_raise: -0.04,
|
||||
range_width: 1.0,
|
||||
fold_equity_default: 0.5,
|
||||
}),
|
||||
// They bluff and raise light: call wider, defend wider.
|
||||
Style::LooseAggressive => Some(Shift {
|
||||
call_margin: -0.015,
|
||||
value_raise: -0.01,
|
||||
range_width: 1.15,
|
||||
fold_equity_default: 0.9,
|
||||
}),
|
||||
}
|
||||
}
|
||||
//! How each style moves the thresholds, as data.
|
||||
|
||||
use super::style::Style;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Shift {
|
||||
/// Added to `call_margin`.
|
||||
pub call_margin: f64,
|
||||
/// Added to `value_raise`.
|
||||
pub value_raise: f64,
|
||||
/// Multiplies `range_width_scale`.
|
||||
pub range_width: f64,
|
||||
}
|
||||
|
||||
const NONE: Shift = Shift {
|
||||
call_margin: 0.0,
|
||||
value_raise: 0.0,
|
||||
range_width: 1.0,
|
||||
};
|
||||
|
||||
/// `None` for `Unknown`: nothing is learned from an empty profile.
|
||||
pub fn shift_for(style: Style) -> Option<Shift> {
|
||||
match style {
|
||||
Style::Unknown => None,
|
||||
Style::Regular => Some(NONE),
|
||||
// Their bets are strong, they fold to ours, we defend less.
|
||||
Style::Nit => Some(Shift {
|
||||
call_margin: 0.04,
|
||||
value_raise: 0.02,
|
||||
range_width: 0.85,
|
||||
}),
|
||||
// They call too much: value-bet thinner, never bluff.
|
||||
Style::CallingStation => Some(Shift {
|
||||
call_margin: 0.0,
|
||||
value_raise: -0.04,
|
||||
range_width: 1.0,
|
||||
}),
|
||||
// They bluff and raise light: call wider, defend wider.
|
||||
Style::LooseAggressive => Some(Shift {
|
||||
call_margin: -0.015,
|
||||
value_raise: -0.01,
|
||||
range_width: 1.15,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
use super::fold_chance::{fold_chance, MAX_FOLD};
|
||||
use crate::game::Spot;
|
||||
|
||||
/// Pressure of a raise to `to`: the chips beyond a call, `to - to_call`, over the pot
|
||||
/// after calling, `pot + to_call`. A plain bet (`to_call = 0`) is `to / pot`.
|
||||
/// 0 when the pot is empty or the numbers are not finite.
|
||||
pub fn pressure_ratio(pot: f64, to_call: f64, to: f64) -> f64 {
|
||||
let base = pot + to_call;
|
||||
let ratio = (to - to_call).max(0.0) / base;
|
||||
if base > 0.0 && ratio.is_finite() { ratio } else { 0.0 }
|
||||
}
|
||||
|
||||
/// P(every live villain folds) to hero raising to `to`: each villain's `fold_chance`
|
||||
/// (from their own profile) times the shared `scale` (`Thresholds::fold_equity_scale`),
|
||||
/// capped, multiplied over the villains as independent events. No live villain: 0.
|
||||
pub fn table_fold(spot: &Spot, to: f64, scale: f64) -> f64 {
|
||||
let ratio = pressure_ratio(spot.pot, spot.to_call, to);
|
||||
let facing_raise = spot.to_call > 0.0;
|
||||
let scale = if scale.is_finite() { scale.max(0.0) } else { 1.0 };
|
||||
let mut live = spot.live_villains().peekable();
|
||||
if live.peek().is_none() {
|
||||
return 0.0;
|
||||
}
|
||||
live.map(|v| (fold_chance(v.profile.as_ref(), ratio, facing_raise) * scale).clamp(0.0, MAX_FOLD))
|
||||
.product()
|
||||
}
|
||||
Reference in New Issue
Block a user