Engine: texture-aware thresholds, semibluffs with fold equity, multiway, uncertainty band, range filter glue
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+17
-18
@@ -1,23 +1,20 @@
|
||||
use super::from_plan::from_plan;
|
||||
use super::passive::cheapest_continue;
|
||||
use super::postflop::choose_postflop;
|
||||
use crate::card::Card;
|
||||
use super::range_filter::{range_filter, HandFilter};
|
||||
use crate::equity::monte_carlo::estimate;
|
||||
use crate::equity::query::Query;
|
||||
use crate::equity::villain_range::VillainRange;
|
||||
use crate::exploit::adjust::adjust;
|
||||
use crate::exploit::profile::Profile;
|
||||
use crate::exploit::range_guess::top_fraction;
|
||||
use crate::exploit::range_model::range_spec;
|
||||
use crate::exploit::thresholds::Thresholds;
|
||||
use crate::game::{Decision, Spot, Street};
|
||||
use crate::guard::enforce::enforce;
|
||||
use crate::preflop::advise::advise;
|
||||
use crate::preflop::hand_percentile::percentile;
|
||||
use crate::read::hand_read::read;
|
||||
use crate::rng::Rng;
|
||||
|
||||
/// A villain's range as an owned predicate over hole cards.
|
||||
type HandFilter = Box<dyn Fn(&[Card]) -> bool>;
|
||||
|
||||
const TRIALS_TWO_CARD: u32 = 3000;
|
||||
const TRIALS_FIVE_CARD: u32 = 1500;
|
||||
|
||||
@@ -29,32 +26,34 @@ fn trials(spot: &Spot) -> u32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Postflop: read the hand, model each live villain's range, simulate, choose.
|
||||
fn postflop(spot: &Spot, thresholds: &Thresholds) -> Decision {
|
||||
let fractions: Vec<f64> = spot.live_villains().map(|v| top_fraction(spot, v)).collect();
|
||||
if fractions.is_empty() {
|
||||
let rules = spot.rules();
|
||||
let hand_read = match read(&rules, &spot.hero_cards, &spot.board) {
|
||||
Ok(r) => r,
|
||||
Err(fault) => return Decision::abstain(format!("hand read unavailable: {fault}")),
|
||||
};
|
||||
let filters: Vec<HandFilter> = spot
|
||||
.live_villains()
|
||||
.map(|v| range_filter(&range_spec(spot, v), rules, spot.variant, &spot.board))
|
||||
.collect();
|
||||
if filters.is_empty() {
|
||||
return cheapest_continue(spot).map_or_else(
|
||||
|| Decision::abstain("no live opponent and nothing to continue with"),
|
||||
|choice| Decision::new(choice, 0.5, "no live opponents: cheapest continuing action"),
|
||||
);
|
||||
}
|
||||
let variant = spot.variant;
|
||||
let filters: Vec<HandFilter> = fractions
|
||||
.into_iter()
|
||||
.map(|fraction| {
|
||||
Box::new(move |hand: &[Card]| percentile(variant, hand) <= fraction) as HandFilter
|
||||
})
|
||||
.collect();
|
||||
let ranges: Vec<VillainRange> =
|
||||
filters.iter().map(|f| VillainRange::Filter(f.as_ref())).collect();
|
||||
let query = Query {
|
||||
rules: spot.rules(),
|
||||
rules,
|
||||
hero: &spot.hero_cards,
|
||||
board: &spot.board,
|
||||
villains: &ranges,
|
||||
trials: trials(spot),
|
||||
};
|
||||
match estimate(&query, Rng::seeded(spot.seed)) {
|
||||
Ok((equity, _)) => choose_postflop(spot, &equity, thresholds),
|
||||
Ok((equity, _)) => choose_postflop(spot, &equity, thresholds, &hand_read),
|
||||
Err(fault) => Decision::abstain(format!("equity unavailable: {fault}")),
|
||||
}
|
||||
}
|
||||
@@ -68,7 +67,7 @@ fn think(spot: &Spot) -> Decision {
|
||||
}
|
||||
}
|
||||
|
||||
/// Full decision for a validated spot (preflop chart or postflop equity/EV),
|
||||
/// Full decision for a validated spot (preflop chart or postflop read/equity/EV),
|
||||
/// always passed through `guard::enforce::enforce`.
|
||||
pub fn decide(spot: &Spot) -> Decision {
|
||||
enforce(spot, think(spot))
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
use super::multiway::{extra_call_margin, extra_value_raise, realized_share, semibluff_allowed};
|
||||
use super::texture_stance::texture_stance;
|
||||
use crate::exploit::thresholds::Thresholds;
|
||||
use crate::game::{ActionKind, Spot};
|
||||
use crate::read::hand_read::HandRead;
|
||||
|
||||
/// Everything the choice needs, after texture and multiway adjustments.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Effective {
|
||||
/// Live villains, at least 1.
|
||||
pub villains: usize,
|
||||
/// Equity share after the multiway realisation discount.
|
||||
pub share: f64,
|
||||
pub call_margin: f64,
|
||||
pub value_raise: f64,
|
||||
pub value_ok: bool,
|
||||
pub raise_ok: bool,
|
||||
pub semibluff_ok: bool,
|
||||
}
|
||||
|
||||
/// `thresholds` seen through the hand read (`texture_stance`) and the number of live
|
||||
/// villains (`multiway`). Pure; heads-up with a monster is the identity.
|
||||
pub fn effective(spot: &Spot, share: f64, thresholds: &Thresholds, read: &HandRead) -> Effective {
|
||||
let live = spot.live_villains().count();
|
||||
let villains = live.max(1);
|
||||
let facing_bet = spot.to_call > 0.0 && spot.is_legal(ActionKind::Call);
|
||||
let stance = texture_stance(thresholds, read, facing_bet);
|
||||
Effective {
|
||||
villains,
|
||||
share: realized_share(share, villains),
|
||||
call_margin: stance.call_margin + extra_call_margin(villains),
|
||||
value_raise: (stance.value_raise + extra_value_raise(villains)).min(0.95),
|
||||
value_ok: stance.value_ok,
|
||||
raise_ok: stance.raise_ok,
|
||||
semibluff_ok: semibluff_allowed(villains),
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
//! Engine: composes assessment and choice into a decision.
|
||||
|
||||
pub mod decide;
|
||||
pub mod effective;
|
||||
pub mod from_plan;
|
||||
pub mod multiway;
|
||||
pub mod options;
|
||||
pub mod passive;
|
||||
pub mod postflop;
|
||||
pub mod range_filter;
|
||||
pub mod read_label;
|
||||
pub mod semibluff;
|
||||
pub mod texture_stance;
|
||||
pub mod uncertainty;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//! How the number of live villains `n` moves the postflop bars. Heads-up (`n <= 1`)
|
||||
//! is the identity; every extra villain (`e = n - 1`) adds:
|
||||
//!
|
||||
//! | quantity | rule | why |
|
||||
//! |------------------|----------------------------------------|--------------------------------------------------|
|
||||
//! | equity realised | `share * 0.97^e` | multiway pots are contested, equity is realised less |
|
||||
//! | call margin | `+ 0.01 * e` | someone else is likelier to hold the better hand |
|
||||
//! | value threshold | `+ 0.05 * e` | a raise must beat several ranges; the absolute bar rises while the fair share `1/(n+1)` falls, so the bar is kept above the heads-up one |
|
||||
//! | semibluffs | only while `n <= 2` | fold equity compounds to near zero against 3+ |
|
||||
|
||||
/// Per extra villain: factor on the equity share.
|
||||
pub const REALIZATION_PER_EXTRA: f64 = 0.97;
|
||||
/// Per extra villain: added to the call margin.
|
||||
pub const MARGIN_PER_EXTRA: f64 = 0.01;
|
||||
/// Per extra villain: added to the value-raise threshold.
|
||||
pub const VALUE_PER_EXTRA: f64 = 0.05;
|
||||
/// Most villains a semibluff may face.
|
||||
pub const SEMIBLUFF_MAX_VILLAINS: usize = 2;
|
||||
|
||||
fn extras(villains: usize) -> i32 {
|
||||
villains.saturating_sub(1).min(64) as i32
|
||||
}
|
||||
|
||||
/// Equity share after the multiway realisation discount.
|
||||
pub fn realized_share(share: f64, villains: usize) -> f64 {
|
||||
share * REALIZATION_PER_EXTRA.powi(extras(villains))
|
||||
}
|
||||
|
||||
pub fn extra_call_margin(villains: usize) -> f64 {
|
||||
MARGIN_PER_EXTRA * f64::from(extras(villains))
|
||||
}
|
||||
|
||||
pub fn extra_value_raise(villains: usize) -> f64 {
|
||||
VALUE_PER_EXTRA * f64::from(extras(villains))
|
||||
}
|
||||
|
||||
pub fn semibluff_allowed(villains: usize) -> bool {
|
||||
villains <= SEMIBLUFF_MAX_VILLAINS
|
||||
}
|
||||
+44
-12
@@ -1,7 +1,9 @@
|
||||
use crate::equity::estimate::Estimate;
|
||||
use super::effective::Effective;
|
||||
use super::semibluff::has_real_draw;
|
||||
use crate::exploit::thresholds::Thresholds;
|
||||
use crate::game::{ActionKind, Choice, Spot};
|
||||
use crate::odds::{break_even::break_even, ev, fold_equity::fold_equity};
|
||||
use crate::read::hand_read::HandRead;
|
||||
use crate::sizing::candidates::candidates;
|
||||
|
||||
/// A legal choice with its expected value in chips (relative to folding now).
|
||||
@@ -11,32 +13,62 @@ pub struct Scored {
|
||||
pub ev: f64,
|
||||
}
|
||||
|
||||
/// Every action the breakpoint rule lets hero consider, in preference order
|
||||
/// (passive first, so ties keep the cheaper line):
|
||||
/// EV of the best non-raising line, ignoring the call margin: check when free, the raw
|
||||
/// call EV, folding (0) when check is not available. `None` when none is legal.
|
||||
pub fn passive_ev(spot: &Spot, share: f64) -> Option<f64> {
|
||||
let free = spot.is_legal(ActionKind::Check);
|
||||
let check = free.then(|| ev::check(share, spot.pot));
|
||||
let call = spot.is_legal(ActionKind::Call).then(|| ev::call(share, spot.pot, spot.to_call));
|
||||
let fold = (spot.is_legal(ActionKind::Fold) && !free).then(ev::fold);
|
||||
[check, call, fold].into_iter().flatten().filter(|x| x.is_finite()).reduce(f64::max)
|
||||
}
|
||||
|
||||
/// A raise is a value raise when the read allows it and the realised share clears the
|
||||
/// effective value threshold.
|
||||
pub fn is_value_raise(eff: &Effective) -> bool {
|
||||
eff.raise_ok && eff.value_ok && eff.share >= eff.value_raise
|
||||
}
|
||||
|
||||
/// Every action the rule lets hero consider, in preference order (passive first, so
|
||||
/// ties keep the cheaper line). With `eff` the effective (texture and multiway
|
||||
/// adjusted) numbers and `share = eff.share`:
|
||||
/// * check, when legal;
|
||||
/// * call, when legal and `share >= break_even + call_margin`;
|
||||
/// * call, when legal and `share >= break_even + eff.call_margin`;
|
||||
/// * fold, when legal and check is not;
|
||||
/// * each sizing candidate as a raise, when legal and `share >= value_raise`.
|
||||
/// * each sizing candidate as a raise, when legal and either
|
||||
/// - it is a value raise (`is_value_raise`), or
|
||||
/// - it is a semibluff: raising is allowed, at most two villains, a real draw
|
||||
/// (`semibluff::has_real_draw`), and the raise EV is strictly above `passive_ev`.
|
||||
///
|
||||
/// Raises are value raises only: the fold-equity term shapes which size is best, it
|
||||
/// does not license raising a hand below the value threshold.
|
||||
pub fn scored(spot: &Spot, estimate: &Estimate, thresholds: &Thresholds) -> Vec<Scored> {
|
||||
let share = estimate.share;
|
||||
/// The raise EV uses `fold_equity(pot, to, fold_equity_scale, live villains)`, i.e.
|
||||
/// `fe * pot + (1 - fe) * (share * final_pot - added)`. Pure bluffs never qualify.
|
||||
pub fn scored(spot: &Spot, eff: &Effective, thresholds: &Thresholds, read: &HandRead) -> Vec<Scored> {
|
||||
let share = eff.share;
|
||||
let free = spot.is_legal(ActionKind::Check);
|
||||
let be = break_even(spot.pot, spot.to_call);
|
||||
let live = spot.live_villains().count();
|
||||
|
||||
let check = free.then(|| Scored { choice: Choice::Check, ev: ev::check(share, spot.pot) });
|
||||
let call = (spot.is_legal(ActionKind::Call) && share >= be + thresholds.call_margin)
|
||||
let call = (spot.is_legal(ActionKind::Call) && share >= be + eff.call_margin)
|
||||
.then(|| Scored { choice: Choice::Call, ev: ev::call(share, spot.pot, spot.to_call) });
|
||||
let fold = (spot.is_legal(ActionKind::Fold) && !free)
|
||||
.then(|| Scored { choice: Choice::Fold, ev: ev::fold() });
|
||||
let raises = if spot.is_legal(ActionKind::Raise) && share >= thresholds.value_raise { candidates(spot) } else { Default::default() }
|
||||
|
||||
let value = is_value_raise(eff);
|
||||
let semi = eff.raise_ok && eff.semibluff_ok && has_real_draw(read, spot.street);
|
||||
let floor = passive_ev(spot, share).unwrap_or(f64::NEG_INFINITY);
|
||||
let sizes = if spot.is_legal(ActionKind::Raise) && (value || semi) {
|
||||
candidates(spot)
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
let raises = sizes
|
||||
.into_iter()
|
||||
.map(|to| {
|
||||
let fe = fold_equity(spot.pot, to, thresholds.fold_equity_scale, live);
|
||||
Scored { choice: Choice::Raise { to }, ev: ev::raise(share, spot.pot, spot.to_call, to, fe) }
|
||||
});
|
||||
})
|
||||
.filter(move |s| value || s.ev > floor);
|
||||
|
||||
check
|
||||
.into_iter()
|
||||
|
||||
+88
-27
@@ -1,12 +1,17 @@
|
||||
use super::options::{scored, Scored};
|
||||
use super::effective::{effective, Effective};
|
||||
use super::options::{is_value_raise, passive_ev, scored, Scored};
|
||||
use super::passive::cheapest_continue;
|
||||
use super::read_label::describe;
|
||||
use super::uncertainty::abstain_confidence;
|
||||
use crate::equity::estimate::Estimate;
|
||||
use crate::exploit::thresholds::Thresholds;
|
||||
use crate::game::{ActionKind, Choice, Decision, Spot};
|
||||
use crate::odds::{break_even::break_even, ev};
|
||||
use crate::read::hand_read::HandRead;
|
||||
|
||||
fn label(choice: Choice) -> String {
|
||||
fn label(choice: Choice, semibluff: bool) -> String {
|
||||
match choice {
|
||||
Choice::Raise { to } if semibluff => format!("semibluff raise to {to:.2}"),
|
||||
Choice::Raise { to } => format!("raise to {to:.2}"),
|
||||
other => other.name().to_lowercase(),
|
||||
}
|
||||
@@ -32,7 +37,9 @@ fn lead(spot: &Spot, share: f64, options: &[Scored], winner: Scored) -> f64 {
|
||||
(winner.choice == Choice::Fold && spot.is_legal(ActionKind::Call))
|
||||
.then(|| ev::call(share, spot.pot, spot.to_call)),
|
||||
);
|
||||
rivals.fold(None, |m: Option<f64>, x| Some(m.map_or(x, |m| m.max(x)))).map_or(winner.ev.abs(), |r| winner.ev - r)
|
||||
rivals
|
||||
.fold(None, |m: Option<f64>, x| Some(m.map_or(x, |m| m.max(x))))
|
||||
.map_or(winner.ev.abs(), |r| winner.ev - r)
|
||||
}
|
||||
|
||||
fn confidence(spot: &Spot, gap: f64) -> f64 {
|
||||
@@ -40,51 +47,105 @@ fn confidence(spot: &Spot, gap: f64) -> f64 {
|
||||
0.5 + 0.5 * (4.0 * gap.max(0.0) / scale).tanh()
|
||||
}
|
||||
|
||||
/// The breakpoint rule for a postflop spot, given an equity estimate.
|
||||
/// Opening of every reason: the read, plus the player count when multiway.
|
||||
fn headline(read: &HandRead, eff: &Effective) -> String {
|
||||
if eff.villains > 1 {
|
||||
format!("{} ({}-way)", describe(read), eff.villains)
|
||||
} else {
|
||||
describe(read)
|
||||
}
|
||||
}
|
||||
|
||||
/// `(lead, error)` when a raise leads the best passive line by less than its own EV
|
||||
/// standard error, `std_error * final pot` (the money at stake). A negative lead
|
||||
/// (the passive line is worth more) counts as inside the error.
|
||||
fn marginal_raise(
|
||||
spot: &Spot,
|
||||
eff: &Effective,
|
||||
estimate: &Estimate,
|
||||
to: f64,
|
||||
raise_ev: f64,
|
||||
) -> Option<(f64, f64)> {
|
||||
let passive = passive_ev(spot, eff.share)?;
|
||||
let gap = raise_ev - passive;
|
||||
let error = estimate.std_error.max(0.0) * ev::final_pot(spot.pot, spot.to_call, to);
|
||||
(gap < error).then_some((gap, error))
|
||||
}
|
||||
|
||||
/// The rule for a postflop spot, given an equity estimate and the hand read.
|
||||
///
|
||||
/// 1. Uncertain equity, or `|share - break-even| < abstain_band + 2 * std_error` while
|
||||
/// facing a real fold/call choice: ABSTAIN.
|
||||
/// 2. Otherwise score check / call / fold / value raises (see `options::scored`) and
|
||||
/// take the maximum EV. Never folds when check is legal.
|
||||
/// 3. `confidence` rises with the EV lead over the runner-up, relative to the pot.
|
||||
pub fn choose_postflop(spot: &Spot, estimate: &Estimate, thresholds: &Thresholds) -> Decision {
|
||||
let share = estimate.share;
|
||||
if !(share.is_finite() && (0.0..=1.0).contains(&share)) {
|
||||
/// 1. Invalid equity: ABSTAIN with confidence 0.
|
||||
/// 2. `effective` (texture stance x multiway) gives the realised share, call margin,
|
||||
/// value threshold and which raises are allowed.
|
||||
/// 3. Score check / call / fold / value raises / semibluffs (`options::scored`) and take
|
||||
/// the maximum EV. Never folds when check is legal.
|
||||
/// 4. Uncertainty: facing fold-or-call with `|share - (break-even + call margin)| <
|
||||
/// abstain_band + 2 * std_error`, or a winning raise whose EV lead over the best
|
||||
/// passive line is below `std_error * final pot`: ABSTAIN with a small confidence
|
||||
/// (0.05..0.30, `uncertainty::abstain_confidence`).
|
||||
/// 5. Otherwise `confidence` rises with the EV lead over the runner-up, relative to the pot.
|
||||
pub fn choose_postflop(
|
||||
spot: &Spot,
|
||||
estimate: &Estimate,
|
||||
thresholds: &Thresholds,
|
||||
read: &HandRead,
|
||||
) -> Decision {
|
||||
let raw = estimate.share;
|
||||
if !(raw.is_finite() && (0.0..=1.0).contains(&raw)) {
|
||||
return Decision::abstain("equity unavailable");
|
||||
}
|
||||
let eff = effective(spot, raw, thresholds, read);
|
||||
let share = eff.share;
|
||||
let be = break_even(spot.pot, spot.to_call);
|
||||
let breakpoint = be + eff.call_margin;
|
||||
let band = thresholds.abstain_band + 2.0 * estimate.std_error.max(0.0);
|
||||
let facing_choice = spot.is_legal(ActionKind::Fold)
|
||||
&& spot.is_legal(ActionKind::Call)
|
||||
&& !spot.is_legal(ActionKind::Check);
|
||||
if facing_choice && (share - be).abs() < band {
|
||||
return Decision::abstain(format!(
|
||||
"equity {share:.2} vs break-even {be:.2}: inside uncertainty band {band:.3}"
|
||||
));
|
||||
let head = headline(read, &eff);
|
||||
let options = scored(spot, &eff, thresholds, read);
|
||||
let winner = best(&options);
|
||||
|
||||
if let Some(Scored { choice: Choice::Raise { to }, ev: raise_ev }) = winner {
|
||||
if let Some((gap, error)) = marginal_raise(spot, &eff, estimate, to, raise_ev) {
|
||||
return Decision::new(
|
||||
Choice::Abstain,
|
||||
abstain_confidence(gap, error),
|
||||
format!("{head}: raise EV lead {gap:+.2} inside its error {error:.2}"),
|
||||
);
|
||||
}
|
||||
} else if facing_choice && (share - breakpoint).abs() < band {
|
||||
return Decision::new(
|
||||
Choice::Abstain,
|
||||
abstain_confidence((share - breakpoint).abs(), band),
|
||||
format!(
|
||||
"{head}: equity {raw:.2} (realised {share:.2}) vs break-even {be:.2} + margin {:.2}: inside uncertainty band {band:.3}",
|
||||
eff.call_margin
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
let options = scored(spot, estimate, thresholds);
|
||||
match best(&options) {
|
||||
Some(winner) => {
|
||||
let shown = match winner.choice {
|
||||
match winner {
|
||||
Some(w) => {
|
||||
let shown = match w.choice {
|
||||
Choice::Fold => ev::call(share, spot.pot, spot.to_call),
|
||||
_ => winner.ev,
|
||||
_ => w.ev,
|
||||
};
|
||||
let name = match winner.choice {
|
||||
let name = match w.choice {
|
||||
Choice::Fold => "call".to_string(),
|
||||
other => label(other),
|
||||
other => label(other, !is_value_raise(&eff)),
|
||||
};
|
||||
Decision::new(
|
||||
winner.choice,
|
||||
confidence(spot, lead(spot, share, &options, winner)),
|
||||
format!("equity {share:.2} vs break-even {be:.2}, EV {name} {shown:+.2}"),
|
||||
w.choice,
|
||||
confidence(spot, lead(spot, share, &options, w)),
|
||||
format!("{head}: equity {raw:.2} vs break-even {be:.2}, EV {name} {shown:+.2}"),
|
||||
)
|
||||
}
|
||||
None => match cheapest_continue(spot) {
|
||||
Some(choice) => Decision::new(
|
||||
choice,
|
||||
0.5,
|
||||
format!("equity {share:.2} vs break-even {be:.2}, only continuing action available"),
|
||||
format!("{head}: equity {raw:.2} vs break-even {be:.2}, only continuing action available"),
|
||||
),
|
||||
None => Decision::abstain("no actionable option"),
|
||||
},
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
use crate::card::Card;
|
||||
use crate::exploit::range_spec::RangeSpec;
|
||||
use crate::preflop::hand_percentile::percentile;
|
||||
use crate::read::draw::Draw;
|
||||
use crate::read::glance::glance;
|
||||
use crate::variant::{Rules, Variant};
|
||||
|
||||
/// A villain's range as an owned predicate over hole cards.
|
||||
pub type HandFilter = Box<dyn Fn(&[Card]) -> bool>;
|
||||
|
||||
/// Turns a `RangeSpec` into the predicate Monte Carlo samples from: a hand is in when
|
||||
/// its preflop percentile lies in `[lo, hi]` and, for every continuation, its made
|
||||
/// hand on the first `board_len` board cards is at least `min_made` — or it holds at
|
||||
/// least a gutshot when the continuation lets draws continue. A hand `glance` cannot
|
||||
/// read is out. A `board_len` beyond the board is clamped to the whole board.
|
||||
pub fn range_filter(spec: &RangeSpec, rules: Rules, variant: Variant, board: &[Card]) -> HandFilter {
|
||||
let spec = spec.clone();
|
||||
let board = board.to_vec();
|
||||
Box::new(move |hand: &[Card]| {
|
||||
let p = percentile(variant, hand);
|
||||
p >= spec.lo
|
||||
&& p <= spec.hi
|
||||
&& spec.continues.iter().all(|c| {
|
||||
match glance(&rules, hand, &board[..c.board_len.min(board.len())]) {
|
||||
Ok((made, draw)) => made >= c.min_made || (c.draws_continue && draw >= Draw::Gutshot),
|
||||
Err(_) => false,
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
use crate::read::draw::Draw;
|
||||
use crate::read::hand_read::HandRead;
|
||||
use crate::read::made::Made;
|
||||
use crate::read::suit_pattern::SuitPattern;
|
||||
|
||||
/// Wetness from which a board is called wet, and up to which it is called dry.
|
||||
const WET: f64 = 0.6;
|
||||
const DRY: f64 = 0.3;
|
||||
|
||||
fn made_name(made: Made) -> &'static str {
|
||||
match made {
|
||||
Made::Air => "air",
|
||||
Made::BoardOnly => "board only",
|
||||
Made::Underpair => "underpair",
|
||||
Made::BottomPair => "bottom pair",
|
||||
Made::MiddlePair => "middle pair",
|
||||
Made::TopPairWeakKicker => "top pair weak kicker",
|
||||
Made::TopPairGoodKicker => "top pair good kicker",
|
||||
Made::Overpair => "overpair",
|
||||
Made::TwoPair => "two pair",
|
||||
Made::Set => "set",
|
||||
Made::Trips => "trips",
|
||||
Made::Straight => "straight",
|
||||
Made::Flush => "flush",
|
||||
Made::FullHouse => "full house",
|
||||
Made::Quads => "quads",
|
||||
Made::StraightFlush => "straight flush",
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_suffix(draw: Draw) -> &'static str {
|
||||
match draw {
|
||||
Draw::None | Draw::Backdoor => "",
|
||||
Draw::Gutshot => " with gutshot",
|
||||
Draw::OpenEnded => " with open-ended draw",
|
||||
Draw::Flush => " with flush draw",
|
||||
Draw::Combo => " with combo draw",
|
||||
}
|
||||
}
|
||||
|
||||
fn board_name(read: &HandRead) -> &'static str {
|
||||
let wetness = read.texture.wetness;
|
||||
if read.texture.suits == SuitPattern::FourFlush {
|
||||
"four-flush"
|
||||
} else if wetness >= WET {
|
||||
"wet"
|
||||
} else if wetness <= DRY {
|
||||
"dry"
|
||||
} else {
|
||||
"medium"
|
||||
}
|
||||
}
|
||||
|
||||
/// The read in words, e.g. "top pair good kicker on wet board" or
|
||||
/// "air with flush draw on dry board". Used in decision reasons.
|
||||
pub fn describe(read: &HandRead) -> String {
|
||||
format!("{}{} on {} board", made_name(read.made), draw_suffix(read.draw), board_name(read))
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
use crate::game::Street;
|
||||
use crate::read::draw::Draw;
|
||||
use crate::read::hand_read::HandRead;
|
||||
|
||||
/// Outs that make a draw "real" regardless of its class.
|
||||
pub const REAL_DRAW_OUTS: u8 = 8;
|
||||
|
||||
/// Hero holds a draw worth raising with: open-ended, flush or combo, or at least
|
||||
/// [`REAL_DRAW_OUTS`] outs. Never on the river (no cards to come).
|
||||
pub fn has_real_draw(read: &HandRead, street: Street) -> bool {
|
||||
street != Street::River
|
||||
&& (matches!(read.draw, Draw::OpenEnded | Draw::Flush | Draw::Combo)
|
||||
|| read.outs >= REAL_DRAW_OUTS)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
use crate::exploit::thresholds::Thresholds;
|
||||
use crate::read::draw::Draw;
|
||||
use crate::read::hand_read::HandRead;
|
||||
use crate::read::made::Made;
|
||||
use crate::read::suit_pattern::SuitPattern;
|
||||
use crate::read::tier::{tier, Tier};
|
||||
|
||||
/// Thresholds as seen by one specific hand on one specific board (heads-up basis).
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Stance {
|
||||
/// Equity above break-even needed to continue.
|
||||
pub call_margin: f64,
|
||||
/// Equity needed for a value raise.
|
||||
pub value_raise: f64,
|
||||
/// A value raise is allowed at all (pot control off).
|
||||
pub value_ok: bool,
|
||||
/// Any raise is allowed (`BoardOnly` never raises).
|
||||
pub raise_ok: bool,
|
||||
}
|
||||
|
||||
const CALL_MARGIN: (f64, f64) = (0.0, 0.2);
|
||||
const VALUE_RAISE: (f64, f64) = (0.5, 0.95);
|
||||
/// Wetness at or above this is a "wet" board (no thin value raise for one pair).
|
||||
const WET: f64 = 0.6;
|
||||
/// Wetness at or below this is "dry"; the strong-hand discount fades out by 0.3.
|
||||
const DRY: f64 = 0.3;
|
||||
|
||||
/// Shifts `(call_margin, value_raise)` for the hand's tier and the board, `w` = wetness.
|
||||
///
|
||||
/// | tier | call margin | value raise | value raise allowed |
|
||||
/// |---------|----------------------------------|-------------------------------------|------------------------------|
|
||||
/// | Weak | +0.03 facing a bet without a draw| +0.10 | yes |
|
||||
/// | Medium | +0.01 + 0.04w (+0.03 four-flush) | +0.06 + 0.12w | no if w >= 0.6 or four-flush |
|
||||
/// | Strong | +0.02w (+0.03 four-flush) | -0.04 dry (fades to 0 at w=0.3) + 0.05w (+0.08 four-flush) | yes |
|
||||
/// | Monster | 0 | 0 | yes |
|
||||
///
|
||||
/// `Made::BoardOnly` may not raise at all. Results are clamped to
|
||||
/// `call_margin` in [0, 0.2] and `value_raise` in [0.5, 0.95]. Unknown wetness counts as 0.5.
|
||||
pub fn texture_stance(base: &Thresholds, read: &HandRead, facing_bet: bool) -> Stance {
|
||||
let w = if read.texture.wetness.is_nan() { 0.5 } else { read.texture.wetness.clamp(0.0, 1.0) };
|
||||
let four = read.texture.suits == SuitPattern::FourFlush;
|
||||
let four_margin = if four { 0.03 } else { 0.0 };
|
||||
let drawing = read.draw >= Draw::Gutshot;
|
||||
let dry = (1.0 - w / DRY).clamp(0.0, 1.0);
|
||||
|
||||
let (margin, value, value_ok) = match tier(read.made) {
|
||||
Tier::Weak => (if facing_bet && !drawing { 0.03 } else { 0.0 }, 0.10, true),
|
||||
Tier::Medium => (0.01 + 0.04 * w + four_margin, 0.06 + 0.12 * w, !(w >= WET || four)),
|
||||
Tier::Strong => (
|
||||
0.02 * w + four_margin,
|
||||
-0.04 * dry + 0.05 * w + if four { 0.08 } else { 0.0 },
|
||||
true,
|
||||
),
|
||||
Tier::Monster => (0.0, 0.0, true),
|
||||
};
|
||||
let raise_ok = read.made != Made::BoardOnly;
|
||||
Stance {
|
||||
call_margin: (base.call_margin + margin).clamp(CALL_MARGIN.0, CALL_MARGIN.1),
|
||||
value_raise: (base.value_raise + value).clamp(VALUE_RAISE.0, VALUE_RAISE.1),
|
||||
value_ok: value_ok && raise_ok,
|
||||
raise_ok,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/// Confidence floor of an ABSTAIN caused by uncertainty (right at the edge).
|
||||
pub const MIN_UNCERTAIN_CONFIDENCE: f64 = 0.05;
|
||||
/// Ceiling (at the rim of the band). An uncertainty ABSTAIN never exceeds this.
|
||||
pub const MAX_UNCERTAIN_CONFIDENCE: f64 = 0.30;
|
||||
|
||||
/// Confidence of an uncertainty ABSTAIN: `0.05 + 0.25 * distance / width`, where
|
||||
/// `distance` is how far the evidence is from the edge being decided (break-even,
|
||||
/// or the EV tie) and `width` the uncertainty band. On the edge the engine is least
|
||||
/// sure (0.05); at the rim of the band it is most sure (0.30). Total: NaN, negative or
|
||||
/// zero-width input gives the floor or the ceiling, never anything outside the range.
|
||||
pub fn abstain_confidence(distance: f64, width: f64) -> f64 {
|
||||
let ratio = if width > 0.0 { (distance / width).clamp(0.0, 1.0) } else { 1.0 };
|
||||
let ratio = if ratio.is_nan() { 0.0 } else { ratio };
|
||||
MIN_UNCERTAIN_CONFIDENCE + (MAX_UNCERTAIN_CONFIDENCE - MIN_UNCERTAIN_CONFIDENCE) * ratio
|
||||
}
|
||||
Reference in New Issue
Block a user