Staerke und Geld am Tisch: Check-Realisierung, Wert-Raises bleiben Raises, Groessenband und Commitment-Leiter, Stapelbaender, ICM-lite

- Vorflop: Grenzhand abstaint nicht mehr (Zertainty-Boden), CFR-Mischung raist ab gleicher Haeufigkeit
- Postflop: Check realisiert 90 % der Equity, Mehrweg-Wertschwelle zur Haelfte, Wert-Raise nicht mehr als Unsicherheit
- engine/size_policy: SPR-Leiter, Baender je Art (Wert 60-75, Bluff 33-50, Nuss bis 125 %), Pot-Kontrolle, duenne Stack-Offs
- sizing/preflop: 15-40 BB kleinere Oeffnung
- icm: Malmuth-Harville, Risikoaufschlag fuer Calls, decide_with(Option<Turnierlage>)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 12:22:36 +01:00
co-authored by Claude Opus 5.5
parent ea50afd4f5
commit 12b5f67175
15 changed files with 675 additions and 22 deletions
+3 -3
View File
@@ -5,7 +5,7 @@
//! |---|---|
//! | two branches | `EV = P(fold) * pot + (1 - P(fold)) * (called share * final pot - added)` |
//! | semibluff | real draw (`semibluff::has_real_draw`), at most two villains, fold branch > 0, EV > 0 and above the best passive line |
//! | pure bluff | weak hand without a real draw, heads-up, P(fold) >= 0.5, EV > 0 and at least 0.05 pot above the best passive line |
//! | pure bluff | weak hand without a real draw, heads-up, P(fold) >= 0.35, EV > 0 and at least 0.03 pot above the best passive line |
//! | never bluff | no semibluff or bluff when any live villain's foldToBet is at most 0.12 |
//! | never bluff-catch | facing a bet without a real draw, a hand below the bettor's value floor may not call when their bluff share is under 0.05 |
@@ -20,9 +20,9 @@ use crate::read::tier::{tier, Tier};
/// A villain with foldToBet at or below this never folds: no bluffs against them.
pub const NEVER_FOLDS: f64 = 0.12;
/// A pure bluff needs at least this chance that everyone folds.
pub const PURE_BLUFF_MIN_FOLD: f64 = 0.5;
pub const PURE_BLUFF_MIN_FOLD: f64 = 0.45;
/// A pure bluff must beat the passive line by this share of the pot.
pub const PURE_BLUFF_EDGE: f64 = 0.05;
pub const PURE_BLUFF_EDGE: f64 = 0.03;
/// Below this bluff share a betting range counts as pure value.
pub const MIN_BLUFF_SHARE: f64 = 0.05;
+38 -5
View File
@@ -1,5 +1,5 @@
use super::called_equity::called_equity;
use super::from_plan::from_plan;
use super::from_plan::{from_plan, MIN_CERTAINTY};
use super::passive::cheapest_continue;
use super::postflop::choose_postflop_with;
use super::range_combos::{as_ranges, combos};
@@ -14,7 +14,10 @@ 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::icm::lage::Turnierlage;
use crate::icm::risk::{call_premium, width_factor};
use crate::preflop::advise::advise;
use crate::preflop::plan::PreflopPlan;
use crate::read::hand_read::read;
use crate::rng::Rng;
@@ -66,11 +69,30 @@ fn postflop(spot: &Spot, thresholds: &Thresholds) -> Decision {
}
}
fn think(spot: &Spot) -> Decision {
/// Thresholds with the tournament risk premium (`icm::risk`) added: calls need more equity,
/// the preflop width narrows. No premium: unchanged.
fn with_premium(thresholds: Thresholds, premium: f64) -> Thresholds {
if premium <= 0.0 {
return thresholds;
}
Thresholds {
call_margin: thresholds.call_margin + premium,
range_width_scale: thresholds.range_width_scale * width_factor(premium),
..thresholds
}
}
fn think(spot: &Spot, premium: f64) -> Decision {
let profiles: Vec<Profile> = spot.live_villains().filter_map(|v| v.profile).collect();
let thresholds = adjust(Thresholds::BASE, &profiles);
let thresholds = with_premium(adjust(Thresholds::BASE, &profiles), premium);
match spot.street {
Street::Preflop => from_plan(spot, &advise(spot, &thresholds)),
Street::Preflop => {
let plan = advise(spot, &thresholds);
// Eine Grenzhand folgt ihrer Seite der Tabelle (Raise bleibt Raise, Call bleibt Call):
// nahe der Grenze ist jede Linie fast gleich viel wert, Aussetzen ist die schlechteste.
let certainty = plan.certainty.max(MIN_CERTAINTY);
from_plan(spot, &PreflopPlan { certainty, ..plan })
}
Street::Flop | Street::Turn | Street::River => postflop(spot, &thresholds),
}
}
@@ -79,7 +101,18 @@ fn think(spot: &Spot) -> Decision {
/// always passed through `guard::enforce::enforce`. Die Handkategorie wird nur
/// zur Nachprüfung angehängt.
pub fn decide(spot: &Spot) -> Decision {
let decision = enforce(spot, think(spot));
decide_with(spot, None)
}
/// `decide` with an optional tournament situation (`icm`). Without one: cash. With one
/// that cannot be priced: ABSTAIN.
pub fn decide_with(spot: &Spot, lage: Option<&Turnierlage>) -> Decision {
let premium = match lage.map(|l| call_premium(spot, l)) {
None => 0.0,
Some(Some(p)) => p,
Some(None) => return Decision::abstain("tournament situation unusable: no money EV"),
};
let decision = enforce(spot, think(spot, premium));
match crate::hand::showdown::best(spot.rules().hole_usage, &spot.hero_cards, &spot.board) {
Ok(strength) => decision.with_category(strength.category),
Err(_) => decision,
+1
View File
@@ -16,5 +16,6 @@ pub mod range_filter;
pub mod read_label;
pub mod run_twice;
pub mod semibluff;
pub mod size_policy;
pub mod texture_stance;
pub mod uncertainty;
+25 -8
View File
@@ -4,14 +4,14 @@ use super::bluff::{
};
use super::called::Called;
use super::effective::Effective;
use super::multiway::realized_share;
use super::multiway::{extra_value_raise, realized_share};
use super::semibluff::has_real_draw;
use crate::exploit::table_fold::table_fold;
use crate::exploit::thresholds::Thresholds;
use crate::game::{ActionKind, Choice, Spot};
use crate::odds::{break_even::break_even, ev};
use crate::read::hand_read::HandRead;
use crate::sizing::candidates::candidates;
use super::size_policy::{extra_call_margin, sizes};
/// A legal choice with its expected value in chips (relative to folding now).
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -22,20 +22,37 @@ pub struct Scored {
pub kind: Option<RaiseKind>,
}
/// Share of its equity a free check keeps: whoever checks gives up the initiative, lets
/// the villain bet or take a free card and cannot charge the worse hands that call. A bet
/// that is called by worse hands beats a check that is worth the same on paper.
pub const CHECK_REALIZATION: f64 = 0.90;
/// EV of checking for free: the share of the pot, discounted by [`CHECK_REALIZATION`].
pub fn check_ev(share: f64, pot: f64) -> f64 {
CHECK_REALIZATION * ev::check(share, pot)
}
/// 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 check = free.then(|| check_ev(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)
}
/// Part of the multiway rise of the value threshold (`multiway::extra_value_raise`) that is
/// given back. The equity share is already the share against all villains and already
/// discounted (`realized_share`), so the full rise counted the crowd twice and kept top
/// pair from betting two-way.
pub const MULTIWAY_VALUE_RELIEF: f64 = 0.5;
/// A raise is a value raise when the read allows it and the realised share clears the
/// effective value threshold.
/// effective value threshold (less `MULTIWAY_VALUE_RELIEF` of the multiway rise).
pub fn is_value_raise(eff: &Effective) -> bool {
eff.raise_ok && eff.value_ok && eff.share >= eff.value_raise
let bar = eff.value_raise - MULTIWAY_VALUE_RELIEF * extra_value_raise(eff.villains);
eff.raise_ok && eff.value_ok && eff.share >= bar
}
/// What kind of raise this hand could make here, if any.
@@ -80,9 +97,9 @@ pub fn scored(
let be = break_even(spot.pot, spot.to_call);
let passive = |choice, ev| Scored { choice, ev, kind: None };
let check = free.then(|| passive(Choice::Check, ev::check(share, spot.pot)));
let check = free.then(|| passive(Choice::Check, check_ev(share, spot.pot)));
let call = (spot.is_legal(ActionKind::Call)
&& share >= be + eff.call_margin
&& share >= be + eff.call_margin + extra_call_margin(spot, read)
&& !bluff_catch_blocked(spot, read))
.then(|| passive(Choice::Call, ev::call(share, spot.pot, spot.to_call)));
let fold = (spot.is_legal(ActionKind::Fold) && !free).then(|| passive(Choice::Fold, ev::fold()));
@@ -90,7 +107,7 @@ pub fn scored(
let kind = raise_kind(spot, eff, read).filter(|_| spot.is_legal(ActionKind::Raise));
let floor = passive_ev(spot, share).unwrap_or(f64::NEG_INFINITY);
let raises = kind.map_or_else(Vec::new, |kind| {
candidates(spot)
sizes(spot, kind, share, read)
.into_iter()
.filter_map(|to| {
let fe = table_fold(spot, to, thresholds.fold_equity_scale);
+6 -2
View File
@@ -123,8 +123,12 @@ pub fn choose_postflop_with(
let options = scored(spot, &eff, thresholds, read, called);
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) {
if let Some(Scored { choice: Choice::Raise { to }, ev: raise_ev, kind }) = winner {
// A value raise stays a raise inside its error: the hand is strong enough on its own
// account, the lead only says how much better than checking it is. Only the raises
// that live on fold equity (semibluff, bluff) are held back by the error.
let held = kind != Some(RaiseKind::Value);
if let Some((gap, error)) = held.then(|| marginal_raise(spot, &eff, estimate, to, raise_ev)).flatten() {
return Decision::new(
Choice::Abstain,
abstain_confidence(gap, error),
+164
View File
@@ -0,0 +1,164 @@
//! 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;
let base = match kind {
RaiseKind::Semibluff | RaiseKind::Bluff => 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
}
+34
View File
@@ -0,0 +1,34 @@
//! Malmuth-Harville equities: expected prize of every player.
/// Largest field the exact expansion is run for.
pub const MAX_PLAYERS: usize = 10;
fn expand(stacks: &[f64], taken: &mut Vec<usize>, probability: f64, payouts: &[f64], out: &mut [f64]) {
let place = taken.len();
if place >= payouts.len() || probability <= 0.0 {
return;
}
let left: f64 = stacks.iter().enumerate().filter(|(i, _)| !taken.contains(i)).map(|(_, s)| *s).sum();
if left <= 0.0 {
return;
}
for i in 0..stacks.len() {
if taken.contains(&i) {
continue;
}
let p = probability * stacks[i] / left;
out[i] += p * payouts[place];
taken.push(i);
expand(stacks, taken, p, payouts, out);
taken.pop();
}
}
/// Expected prize per player. Places beyond the paid ones pay nothing; more payouts than
/// players are cut to the field. The sum of the result is the sum of the paid prizes.
pub fn equities(stacks: &[f64], payouts: &[f64]) -> Vec<f64> {
let mut out = vec![0.0; stacks.len()];
let paid = &payouts[..payouts.len().min(stacks.len())];
expand(stacks, &mut Vec::new(), 1.0, paid, &mut out);
out
}
+32
View File
@@ -0,0 +1,32 @@
/// The tournament situation of one decision. All amounts in chips (the unit of `Spot`).
#[derive(Clone, Debug, PartialEq)]
pub struct Turnierlage {
/// Prize of place 1, 2, ... (only paid places). Money, any unit.
pub payouts: Vec<f64>,
/// Chips of every player still in the tournament, hero included.
pub stacks: Vec<f64>,
/// Index of hero in `stacks`.
pub hero: usize,
/// Ante per player (informational; stacks are taken as they are behind).
pub ante: f64,
/// Blind level (informational).
pub level: u32,
}
impl Turnierlage {
/// Players in the field who still have chips.
pub fn players(&self) -> usize {
self.stacks.len()
}
/// Every number finite, stacks positive, payouts non-negative with a positive sum, hero
/// inside the field, field small enough for the exact expansion.
pub fn is_usable(&self) -> bool {
!self.payouts.is_empty()
&& self.hero < self.stacks.len()
&& self.stacks.len() <= super::harville::MAX_PLAYERS
&& self.stacks.iter().all(|s| s.is_finite() && *s > 0.0)
&& self.payouts.iter().all(|p| p.is_finite() && *p >= 0.0)
&& self.payouts.iter().sum::<f64>() > 0.0
}
}
+22
View File
@@ -0,0 +1,22 @@
//! ICM-lite: chip EV converted to money EV for tournament spots.
//!
//! An APPROXIMATION, like the multiway equity. Assumptions:
//! * Malmuth-Harville: a player finishes next with probability `stack / sum of stacks`
//! among those still unplaced (`harville`). Only the paid places are expanded.
//! * A call is a heads-up showdown for the whole `min(to_call, stacks)`; the pot is won or
//! lost as one piece, the rest of the field does not act (`risk`).
//! * The opponent is the last aggressor of the hand (largest live stack when unknown),
//! found in the field by its stack. Everything else in the field stays as given.
//! * Only calls (hero faces a bet) are tightened. Opening and jamming ranges are not yet
//! moved by the pay structure; chip EV stays in force there.
//! * Without a `Turnierlage` nothing changes: cash is bit-identical.
//! * A `Turnierlage` that does not make sense (no stacks, no payouts, hero not in the field,
//! non-positive stacks, more than `harville::MAX_PLAYERS` players) is not guessed at:
//! the engine answers ABSTAIN.
//!
//! Wire proposal for a later optional contract field (not in VERTRAG.md):
//! `"tournament": {"payouts": [..], "stacks": [..], "heroIndex": n, "ante": a, "level": l}`.
pub mod harville;
pub mod lage;
pub mod risk;
+74
View File
@@ -0,0 +1,74 @@
//! Risk premium of a call: how much more equity the money value asks than the chips.
use super::harville::equities;
use super::lage::Turnierlage;
use crate::game::Spot;
/// Largest premium ever applied (equity share).
pub const MAX_PREMIUM: f64 = 0.25;
/// Narrowing of the preflop width per point of premium (`1 - 4 p`, floor `MIN_WIDTH`).
pub const WIDTH_PER_PREMIUM: f64 = 4.0;
pub const MIN_WIDTH: f64 = 0.5;
/// Equity needed to call in money terms. `hero`/`opp` are the chips behind (the pot is
/// separate), `risk` what the call puts in, `gain` what is won (the pot). Folding hands the
/// pot to the opponent; winning gives it to hero; losing also gives him the call.
/// `others` is the rest of the field. `None` when win and loss are worth the same.
pub fn required_equity(others: &[f64], payouts: &[f64], hero: f64, opp: f64, risk: f64, gain: f64) -> Option<f64> {
let eq = |h: f64, o: f64| {
let mut stacks = vec![h, o];
stacks.extend_from_slice(others);
equities(&stacks, payouts)[0]
};
let (fold, win, lose) =
(eq(hero, opp + gain), eq(hero + gain, opp), eq((hero - risk).max(1e-9), opp + gain + risk));
(win - lose > 1e-12).then(|| (fold - lose) / (win - lose))
}
/// Index of the stack in `stacks` (hero's skipped) nearest to `chips`.
fn nearest(stacks: &[f64], skip: usize, chips: f64) -> Option<usize> {
(0..stacks.len())
.filter(|i| *i != skip)
.min_by(|a, b| (stacks[*a] - chips).abs().total_cmp(&(stacks[*b] - chips).abs()))
}
/// Stack (as listed in the spot) of the last aggressor of the hand among the live villains; else the largest stack.
fn opponent_stack(spot: &Spot) -> Option<f64> {
spot.history
.iter()
.rev()
.filter(|r| r.action.is_aggressive())
.find_map(|r| spot.live_villains().find(|v| v.seat == r.seat))
.or_else(|| spot.live_villains().max_by(|a, b| a.stack.total_cmp(&b.stack)))
.map(|v| v.stack)
}
/// The premium (>= 0, <= `MAX_PREMIUM`) hero's call asks over the chip break-even; 0 when
/// hero does not face a bet. `None` when the situation cannot be priced.
pub fn call_premium(spot: &Spot, lage: &Turnierlage) -> Option<f64> {
if !lage.is_usable() {
return None;
}
if spot.to_call <= 0.0 {
return Some(0.0);
}
// What hero already put in this hand (blind, ante): the field lists chips at hand start.
let committed = (lage.stacks[lage.hero] - spot.hero_stack).max(0.0);
let matched = committed + spot.to_call;
let seen = opponent_stack(spot)?;
let (a, b) = (nearest(&lage.stacks, lage.hero, seen)?, nearest(&lage.stacks, lage.hero, seen + matched)?);
let miss = |i: usize, x: f64| (lage.stacks[i] - x).abs();
let opp = if miss(a, seen) <= miss(b, seen + matched) { a } else { b };
let others: Vec<f64> =
lage.stacks.iter().enumerate().filter(|(i, _)| *i != lage.hero && *i != opp).map(|(_, s)| *s).collect();
let risk = spot.to_call.min(spot.hero_stack);
let chips_be = risk / (spot.pot + risk);
let behind = (lage.stacks[opp] - matched).max(1e-9);
let needed = required_equity(&others, &lage.payouts, spot.hero_stack, behind, risk, spot.pot)?;
Some((needed - chips_be).clamp(0.0, MAX_PREMIUM))
}
/// Factor on the preflop range width for a premium.
pub fn width_factor(premium: f64) -> f64 {
(1.0 - WIDTH_PER_PREMIUM * premium).clamp(MIN_WIDTH, 1.0)
}
+1
View File
@@ -12,6 +12,7 @@ pub mod fault;
pub mod game;
pub mod guard;
pub mod hand;
pub mod icm;
pub mod json;
pub mod odds;
pub mod preflop;
+5 -1
View File
@@ -84,10 +84,14 @@ pub struct CfrAdvice {
}
/// Most frequent action; ties go to the cheaper one (fold, then call).
/// A call only beats the aggressive line when it is played clearly more often: where the
/// equilibrium mixes about evenly, the hand raises.
const CALL_OVER_RAISE: f64 = 1.3;
fn pick(f: Frequencies, aggressive: ChartAction) -> ChartAction {
if f.fold >= f.call && f.fold >= f.raise {
ChartAction::Fold
} else if f.call >= f.raise {
} else if f.call >= f.raise * CALL_OVER_RAISE {
ChartAction::Call
} else {
aggressive
+14 -3
View File
@@ -1,4 +1,5 @@
use super::fit::fit;
use crate::preflop::effective_stack::effective_stack_bb;
use crate::game::Spot;
/// Open size in big blinds when nobody has raised yet.
@@ -6,13 +7,23 @@ pub const OPEN_BB: f64 = 2.5;
/// Multiplier on the bet faced for a re-raise.
pub const RERAISE_FACTOR: f64 = 3.0;
/// Between `PUSH_FOLD_BB` and this depth (bb) the sizes are smaller.
pub const SHORT_BAND_BB: f64 = 40.0;
/// Smaller open (bb) and re-raise factor in the 15 to 40 bb band.
pub const SHORT_OPEN_BB: f64 = 2.0;
pub const SHORT_RERAISE_FACTOR: f64 = 2.5;
const PUSH_FOLD_BB: f64 = 15.0;
/// Wished preflop raise-to: `2.5 bb` when only blinds/limps are faced
/// (`to_call <= big_blind`), else `3 x` the amount to call.
/// (`to_call <= big_blind`), else `3 x` the amount to call; `2 bb` and `2.5 x` for stacks
/// of 15 to 40 bb.
pub fn raise_target(spot: &Spot) -> f64 {
let depth = effective_stack_bb(spot);
let short = depth > PUSH_FOLD_BB && depth < SHORT_BAND_BB;
if spot.to_call <= spot.big_blind {
OPEN_BB * spot.big_blind
(if short { SHORT_OPEN_BB } else { OPEN_BB }) * spot.big_blind
} else {
RERAISE_FACTOR * spot.to_call
(if short { SHORT_RERAISE_FACTOR } else { RERAISE_FACTOR }) * spot.to_call
}
}
+92
View File
@@ -0,0 +1,92 @@
mod spot_fixture;
use pokerfreak::engine::bluff::RaiseKind;
use pokerfreak::engine::size_policy::{ladder_fraction, ladder_streets, sizes, spr};
use pokerfreak::game::{ActionKind, Spot};
use pokerfreak::read::draw::Draw;
use pokerfreak::read::made::Made;
use pokerfreak::read::suit_pattern::SuitPattern;
use spot_fixture::*;
/// Free to act on the flop, pot 10, big blind 0.1, the sizes 1/3, 1/2, 2/3, 1 pot and the stack.
fn bet_spot(stack: f64) -> Spot {
Spot {
to_call: 0.0,
pot: 10.0,
hero_stack: stack,
min_raise_to: Some(1.0),
max_raise_to: Some(stack),
allowed_sizes: Some(vec![3.33, 5.0, 6.67, 10.0, stack]),
legal: vec![ActionKind::Check, ActionKind::Raise],
villains: vec![pokerfreak::game::Villain { seat: 2, stack, folded: false, profile: None }],
big_blind: 0.1,
..round_flop()
}
}
fn strong() -> pokerfreak::read::hand_read::HandRead {
read_of(Made::Overpair, Draw::None, 0, SuitPattern::Rainbow, 0.4)
}
#[test]
fn ladder_streets_follow_the_spr_bands() {
assert_eq!(ladder_streets(10.0), 3);
assert_eq!(ladder_streets(6.01), 3);
assert_eq!(ladder_streets(6.0), 2);
assert_eq!(ladder_streets(3.0), 2);
assert_eq!(ladder_streets(2.99), 1);
}
#[test]
fn ladder_fraction_empties_the_stack_in_n_equal_bets() {
for (spr, n) in [(1.5, 1), (4.0, 2), (13.0, 3), (40.0, 3)] {
let f = ladder_fraction(spr, n);
let (mut pot, mut put) = (1.0, 0.0);
for _ in 0..n {
put += f * pot;
pot *= 1.0 + 2.0 * f;
}
assert!((put - spr).abs() < 1e-9, "spr {spr} over {n}: {put}");
}
}
#[test]
fn spr_is_stack_over_pot() {
assert!((spr(&bet_spot(50.0)) - 5.0).abs() < 1e-9);
}
#[test]
fn value_bets_use_the_value_band_and_only_allowed_sizes() {
let spot = bet_spot(200.0);
let picked = sizes(&spot, RaiseKind::Value, 0.7, &strong());
assert!(!picked.is_empty());
let allowed = spot.allowed_sizes.clone().expect("sizes");
assert!(picked.iter().all(|s| allowed.contains(s)), "{picked:?}");
// Flop value band 0.48 to 0.60 of the pot (times slack): nothing like the pot or the stack.
assert!(picked.iter().all(|s| *s <= 10.0 && *s >= 3.33), "{picked:?}");
}
#[test]
fn bluffs_stay_smaller_than_value() {
let spot = bet_spot(200.0);
let bluff = sizes(&spot, RaiseKind::Bluff, 0.2, &read_of(Made::Air, Draw::None, 0, SuitPattern::Rainbow, 0.4));
let value = sizes(&spot, RaiseKind::Value, 0.7, &strong());
assert!(bluff.iter().copied().fold(0.0, f64::max) <= value.iter().copied().fold(0.0, f64::max));
assert!(bluff.iter().all(|s| *s <= 6.67), "{bluff:?}");
}
#[test]
fn a_committed_stack_may_jam_for_value() {
// SPR 1.5: the stack goes in at once.
let spot = bet_spot(15.0);
let picked = sizes(&spot, RaiseKind::Value, 0.8, &strong());
assert!(picked.contains(&15.0), "{picked:?}");
}
#[test]
fn thin_hands_do_not_stack_off() {
let spot = bet_spot(15.0);
let thin = read_of(Made::TopPairWeakKicker, Draw::None, 0, SuitPattern::Rainbow, 0.2);
let picked = sizes(&spot, RaiseKind::Value, 0.64, &thin);
assert!(!picked.contains(&15.0), "{picked:?}");
}
+164
View File
@@ -0,0 +1,164 @@
//! ICM-lite: harville equities and the bubble. Same spots, cash against bubble.
use pokerfreak::card::Card;
use pokerfreak::engine::decide::{decide, decide_with};
use pokerfreak::game::{ActionKind, ActionRecord, Choice, SeenAction, Spot, Street, Villain};
use pokerfreak::icm::harville::equities;
use pokerfreak::icm::lage::Turnierlage;
use pokerfreak::icm::risk::{call_premium, required_equity};
use pokerfreak::variant::Variant;
const RANKS: &str = "AKQJT98765432";
fn close(a: f64, b: f64) -> bool {
(a - b).abs() < 1e-9
}
#[test]
fn equities_pay_out_exactly_the_prize_pool() {
let e = equities(&[10.0, 20.0, 30.0, 40.0], &[50.0, 30.0, 20.0]);
assert!(close(e.iter().sum::<f64>(), 100.0), "{e:?}");
assert!(e.windows(2).all(|w| w[0] < w[1]), "bigger stack, bigger equity: {e:?}");
}
#[test]
fn equal_stacks_are_worth_the_same_and_one_winner_takes_first() {
let e = equities(&[5.0; 4], &[50.0, 30.0, 20.0]);
assert!(e.iter().all(|x| close(*x, 25.0)), "{e:?}");
let winner_takes_all = equities(&[1.0, 3.0], &[100.0]);
assert!(close(winner_takes_all[1], 75.0) && close(winner_takes_all[0], 25.0));
}
#[test]
fn a_chip_is_worth_less_than_it_costs_to_lose_one() {
// The core of ICM: the equity gained by doubling up is less than the equity lost by busting.
let (fold, win, lose) = (
equities(&[10.0, 10.0, 20.0, 20.0], &[50.0, 30.0, 20.0])[0],
equities(&[20.0, 10.0, 20.0, 20.0], &[50.0, 30.0, 20.0])[0],
equities(&[1e-9, 10.0, 20.0, 20.0], &[50.0, 30.0, 20.0])[0],
);
assert!(win - fold < fold - lose);
}
#[test]
fn the_required_equity_exceeds_the_chip_break_even_on_the_bubble() {
let needed = required_equity(&[20.0, 20.0], &[50.0, 30.0, 20.0], 10.0, 1e-9, 10.0, 11.5).expect("priced");
assert!(needed > 10.0 / 21.5, "{needed}");
}
#[test]
fn winner_takes_all_has_no_premium() {
// Winner-takes-all: money is linear in chips, so money EV equals chip EV.
let needed = required_equity(&[20.0, 20.0], &[100.0], 10.0, 1e-9, 10.0, 11.5).expect("priced");
assert!((needed - 10.0 / 21.5).abs() < 1e-6, "{needed}");
}
fn record(seat: u8, action: SeenAction, amount: f64) -> ActionRecord {
ActionRecord { street: Street::Preflop, seat, action, amount: Some(amount) }
}
/// Heads-up pot, hero in the big blind (seat 1) facing the small blind's (seat 2) jam of `depth` bb.
fn facing_jam(hole: &str, depth: f64) -> Spot {
Spot {
variant: Variant::Nlhe,
big_blind: 1.0,
seats: 2,
hero_seat: 1,
button_seat: Some(2),
hero_cards: Card::parse_list(hole).expect("cards"),
board: vec![],
street: Street::Preflop,
pot: depth + 1.0,
to_call: depth - 1.0,
hero_stack: depth - 1.0,
min_raise_to: None,
max_raise_to: None,
legal: vec![ActionKind::Fold, ActionKind::Call],
allowed_sizes: None,
villains: vec![Villain { seat: 2, stack: depth, folded: false, profile: None }],
seed: 7,
history: vec![
record(2, SeenAction::PostSmallBlind, 0.5),
record(1, SeenAction::PostBigBlind, 1.0),
record(2, SeenAction::AllIn, depth),
],
}
}
fn bubble(depth: f64) -> Turnierlage {
Turnierlage {
payouts: vec![50.0, 30.0, 20.0],
stacks: vec![depth, depth, 2.0 * depth, 2.0 * depth],
hero: 0,
ante: 0.0,
level: 1,
}
}
fn holes() -> Vec<String> {
let r: Vec<char> = RANKS.chars().collect();
let mut out = Vec::new();
for (i, a) in r.iter().enumerate() {
for b in &r[i..] {
if a == b {
out.push(format!("{a}s {b}h"));
} else {
out.push(format!("{a}s {b}s"));
out.push(format!("{a}s {b}h"));
}
}
}
out
}
fn calls(choice: Choice) -> bool {
matches!(choice, Choice::Call)
}
#[test]
fn bubble_spots_call_narrower_than_cash_at_every_depth() {
let mut printed = String::new();
for depth in [5.0, 10.0, 15.0, 25.0] {
let (mut cash_calls, mut bubble_calls, mut wider) = (0, 0, 0);
let lage = bubble(depth);
for hole in holes() {
let spot = facing_jam(&hole, depth);
let cash = calls(decide(&spot).choice);
let money = calls(decide_with(&spot, Some(&lage)).choice);
cash_calls += usize::from(cash);
bubble_calls += usize::from(money);
wider += usize::from(money && !cash);
}
printed += &format!("{depth} bb: Cash {cash_calls} von 169 Haenden, Bubble {bubble_calls}\n");
assert_eq!(wider, 0, "{depth} bb: the bubble never calls a hand cash folds");
assert!(bubble_calls < cash_calls, "{depth} bb: {bubble_calls} >= {cash_calls}");
}
println!("{printed}");
}
#[test]
fn without_a_situation_nothing_changes() {
for hole in ["As Ah", "7s 2h", "Ks Qs"] {
let spot = facing_jam(hole, 12.0);
assert_eq!(decide(&spot), decide_with(&spot, None));
}
}
#[test]
fn an_unusable_situation_abstains() {
let spot = facing_jam("As Ah", 12.0);
for lage in [
Turnierlage { payouts: vec![], ..bubble(12.0) },
Turnierlage { hero: 9, ..bubble(12.0) },
Turnierlage { stacks: vec![12.0, f64::NAN], ..bubble(12.0) },
] {
assert_eq!(decide_with(&spot, Some(&lage)).choice, Choice::Abstain);
}
}
#[test]
fn no_bet_to_face_costs_no_premium() {
let mut spot = facing_jam("As Ah", 12.0);
spot.to_call = 0.0;
assert_eq!(call_premium(&spot, &bubble(12.0)), Some(0.0));
}