Files
pokerfreak/src/engine/size_policy.rs
T

171 lines
7.9 KiB
Rust

//! Which raise sizes a postflop raise may use: the commitment ladder, the size bands per
//! kind of raise, pot control and the stack bands. Pure; every size comes from
//! `sizing::candidates` (so from `allowedSizes` when given), never from outside it.
//!
//! | rule | value |
//! |---|---|
//! | ladder (SPR = effective stack / pot) | SPR > 6: three streets, 3 to 6: two streets, under 3: one (commit) |
//! | ladder size | `f = ((2 SPR + 1)^(1/n) - 1) / 2` pots per street, so `n` equal bets empty the stack by the river |
//! | value | 60 to 75 % of the pot, clamped around the ladder size |
//! | semibluff, bluff | 33 to 50 % of the pot |
//! | slack | sizes within the band times 0.8 to 1.25 are all kept (plus the one nearest to the target); the EV picks |
//! | raise over a bet | no band: the EV picks among sizes up to 1.25 pots |
//! | nuts (monster, share >= 0.85, turn or river) | may overbet, 75 to 125 % |
//! | street | flop bands times 0.8, turn times 0.9, river times 1 |
//! | pot control | medium hand: small band (as bluffs); deeper than 150 bb every value hand short of a monster: 45 to 60 % |
//! | stack bands | up to 15 bb push/fold (preflop); 15 to 40 bb sizes times 0.85 and speculative calls cost 0.02 more; 40 to 150 bb standard; over 150 bb pot control |
//! | thin stack-offs | a raise or call of 60 % of the stack or more needs a strong hand or a share of 0.75 (a call: 0.04 more margin for a medium hand) |
use super::bluff::RaiseKind;
use crate::exploit::table_fold::pressure_ratio;
use crate::game::{Spot, Street};
use crate::preflop::effective_stack::effective_stack_bb;
use crate::read::hand_read::HandRead;
use crate::read::tier::{tier, Tier};
use crate::sizing::candidates::candidates;
/// Above this SPR three streets are left to put the stack in.
pub const THREE_STREET_SPR: f64 = 6.0;
/// From this SPR up two streets; below it the stack goes in at once.
pub const TWO_STREET_SPR: f64 = 3.0;
/// Pot-fraction bands (low, high).
pub const VALUE_BAND: (f64, f64) = (0.60, 0.75);
pub const BLUFF_BAND: (f64, f64) = (0.33, 0.50);
pub const NUT_BAND: (f64, f64) = (0.75, 1.25);
pub const DEEP_VALUE_BAND: (f64, f64) = (0.45, 0.60);
/// Band factor per street (flop, turn, river).
pub const STREET_FACTOR: [f64; 3] = [0.8, 0.9, 1.0];
/// A size within `band * slack` is still allowed (low, high); the EV chooses among them.
pub const BAND_SLACK: (f64, f64) = (0.8, 1.25);
/// Share from which a monster may overbet.
pub const NUT_SHARE: f64 = 0.85;
/// Largest pot fraction any non-committed raise may use.
pub const MAX_FRACTION: f64 = 1.25;
/// Stack bands in big blinds.
pub const SHORT_STACK_BB: f64 = 40.0;
pub const DEEP_STACK_BB: f64 = 150.0;
pub const SHORT_SIZE_FACTOR: f64 = 0.85;
pub const SHORT_SPECULATIVE_MARGIN: f64 = 0.02;
/// A raise or call this share of the stack (or more) is a stack-off.
pub const STACK_OFF_SHARE: f64 = 0.6;
pub const THIN_STACK_OFF_SHARE_NEEDED: f64 = 0.75;
pub const THIN_STACK_OFF_CALL_MARGIN: f64 = 0.04;
/// Streets that can still be bet, this one included.
fn streets_left(street: Street) -> i32 {
match street {
Street::Preflop | Street::Flop => 3,
Street::Turn => 2,
Street::River => 1,
}
}
fn street_factor(street: Street) -> f64 {
STREET_FACTOR[(street as usize).clamp(1, 3) - 1]
}
/// Effective stack over the pot after calling.
pub fn spr(spot: &Spot) -> f64 {
let stack = effective_stack_bb(spot) * spot.big_blind;
let pot = spot.pot + spot.to_call;
if stack.is_finite() && pot > 0.0 { stack / pot } else { f64::INFINITY }
}
/// Streets the ladder spends putting the stack in.
pub fn ladder_streets(spr: f64) -> i32 {
if spr > THREE_STREET_SPR {
3
} else if spr >= TWO_STREET_SPR {
2
} else {
1
}
}
/// Pot fraction per bet so that `n` equal bets, each called, put `spr` pots in.
pub fn ladder_fraction(spr: f64, n: i32) -> f64 {
((2.0 * spr + 1.0).powf(1.0 / f64::from(n.max(1))) - 1.0) / 2.0
}
fn depth_bb(spot: &Spot) -> f64 {
effective_stack_bb(spot)
}
/// Stack-off: this much of hero's stack goes in with `to` (raise-to or call).
pub fn is_stack_off(spot: &Spot, to: f64) -> bool {
spot.hero_stack > 0.0 && to >= STACK_OFF_SHARE * spot.hero_stack
}
/// Extra call margin for the hand and the stack depth: a thin stack-off with a medium hand,
/// and speculative (weak-tier) calls at 15 to 40 bb.
pub fn extra_call_margin(spot: &Spot, read: &HandRead) -> f64 {
let t = tier(read.made);
let thin = if t == Tier::Medium && is_stack_off(spot, spot.to_call) { THIN_STACK_OFF_CALL_MARGIN } else { 0.0 };
let depth = depth_bb(spot);
let speculative = if t == Tier::Weak && spot.to_call > 0.0 && depth < SHORT_STACK_BB { SHORT_SPECULATIVE_MARGIN } else { 0.0 };
thin + speculative
}
/// The pot-fraction band for this raise.
fn band(spot: &Spot, kind: RaiseKind, share: f64, read: &HandRead) -> (f64, f64) {
let t = tier(read.made);
let late = spot.street != Street::Flop;
// ANGRIFF_FOLD against a style-less fold read: bluffs and semibluffs may also take the value sizes,
// where the read's fold chance applies in full (a small bet is folded less, `exploit::fold_chance`);
// the EV picks the size.
let fold_read = super::read_gate::fold_attack_enabled()
&& spot.live_villains().any(|v| v.profile.is_some_and(|p| p.fold_only));
let base = match kind {
RaiseKind::Semibluff | RaiseKind::Bluff if fold_read => (BLUFF_BAND.0, VALUE_BAND.1),
RaiseKind::Semibluff | RaiseKind::Bluff | RaiseKind::ThinValue => BLUFF_BAND,
RaiseKind::Value if t == Tier::Medium => BLUFF_BAND,
RaiseKind::Value if t == Tier::Monster && late && share >= NUT_SHARE => NUT_BAND,
RaiseKind::Value if t != Tier::Monster && depth_bb(spot) > DEEP_STACK_BB => DEEP_VALUE_BAND,
RaiseKind::Value => VALUE_BAND,
};
let f = street_factor(spot.street)
* if depth_bb(spot) < SHORT_STACK_BB { SHORT_SIZE_FACTOR } else { 1.0 };
(base.0 * f, base.1 * f)
}
/// The raise-to sizes this raise may use: the usable size nearest to the target pot
/// fraction (ladder size clamped into the band), plus the largest size when the stack goes
/// in anyway (value, SPR under 3). Thin stack-offs are removed. May be empty.
pub fn sizes(spot: &Spot, kind: RaiseKind, share: f64, read: &HandRead) -> Vec<f64> {
let all = candidates(spot);
let (lo, hi) = band(spot, kind, share, read);
let s = spr(spot);
let n = ladder_streets(s).min(streets_left(spot.street));
let target = ladder_fraction(s, n).clamp(lo, hi);
let fraction = |to: f64| pressure_ratio(spot.pot, spot.to_call, to);
let committed = kind == RaiseKind::Value && s < TWO_STREET_SPR;
let cap = if hi > VALUE_BAND.1 { MAX_FRACTION } else { hi * 1.5 };
let within: Vec<f64> = all.iter().copied().filter(|to| fraction(*to) <= cap).collect();
// No size fits the cap (only big raises allowed): the smallest legal one.
let within = if within.is_empty() { all.first().copied().into_iter().collect() } else { within };
let mut picked: Vec<f64> = if spot.to_call > 0.0 {
// Raising over a bet: the bands are for bets; the EV picks among the sizes up to MAX_FRACTION.
all.iter().copied().filter(|to| fraction(*to) <= MAX_FRACTION).collect()
} else {
// Every size inside the band (with slack), and the one nearest to the target; the EV picks.
let nearest = within
.iter()
.copied()
.min_by(|a, b| (fraction(*a) - target).abs().total_cmp(&(fraction(*b) - target).abs()));
within
.iter()
.copied()
.filter(|to| (lo * BAND_SLACK.0..=hi * BAND_SLACK.1).contains(&fraction(*to)))
.chain(nearest)
.collect()
};
if committed {
picked.extend(all.last().copied());
}
picked.sort_by(f64::total_cmp);
picked.dedup();
let strong = tier(read.made) >= Tier::Strong || share >= THIN_STACK_OFF_SHARE_NEEDED;
picked.retain(|to| strong || !is_stack_off(spot, *to));
picked
}