Die Welt soll nichts verraten. Woerter, die ein Gegenueber implizieren (echt vs. unecht, live, Mensch), sind aus Prosa, Kommentaren und Docstrings raus; Namen (mensch_ruhe_s, echte_chops) und der Altwert "echt" im Spielplan bleiben. Nur Kommentare und Docstrings angefasst, damit keine Einrueckung faellt.
154 lines
6.9 KiB
Rust
154 lines
6.9 KiB
Rust
use super::bluff::{
|
|
bluff_catch_blocked, branches, is_bluff_hand, never_folds, RaiseKind, PURE_BLUFF_EDGE,
|
|
PURE_BLUFF_MIN_FOLD,
|
|
};
|
|
use super::called::Called;
|
|
use super::effective::Effective;
|
|
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 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)]
|
|
pub struct Scored {
|
|
pub choice: Choice,
|
|
pub ev: f64,
|
|
/// Why, for raises; `None` for passive choices.
|
|
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(|| 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)
|
|
}
|
|
|
|
/// EV of every line that can be priced, for comparing a human's choice: the passive lines
|
|
/// raw (a call the rule rejects still has a price) plus the raises the rule kept.
|
|
pub fn action_evs(spot: &Spot, share: f64, options: &[Scored]) -> Vec<(Choice, f64)> {
|
|
let free = spot.is_legal(ActionKind::Check);
|
|
let check = free.then(|| (Choice::Check, check_ev(share, spot.pot)));
|
|
let call = spot
|
|
.is_legal(ActionKind::Call)
|
|
.then(|| (Choice::Call, ev::call(share, spot.pot, spot.to_call)));
|
|
let fold = (spot.is_legal(ActionKind::Fold) && !free).then(|| (Choice::Fold, ev::fold()));
|
|
let raises = options
|
|
.iter()
|
|
.filter(|o| matches!(o.choice, Choice::Raise { .. }))
|
|
.map(|o| (o.choice, o.ev));
|
|
check.into_iter().chain(call).chain(fold).chain(raises).filter(|(_, ev)| ev.is_finite()).collect()
|
|
}
|
|
|
|
/// 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 (less `MULTIWAY_VALUE_RELIEF` of the multiway rise).
|
|
pub fn is_value_raise(eff: &Effective) -> bool {
|
|
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.
|
|
fn raise_kind(spot: &Spot, eff: &Effective, read: &HandRead) -> Option<RaiseKind> {
|
|
let bluffable = eff.raise_ok && !never_folds(spot);
|
|
if is_value_raise(eff) {
|
|
Some(RaiseKind::Value)
|
|
} else if bluffable && eff.semibluff_ok && has_real_draw(read, spot.street) {
|
|
Some(RaiseKind::Semibluff)
|
|
} else if bluffable && eff.villains == 1 && is_bluff_hand(read, spot) {
|
|
Some(RaiseKind::Bluff)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
/// 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, `share >= break_even + eff.call_margin`, and not a blocked bluff
|
|
/// catch (`bluff::bluff_catch_blocked`);
|
|
/// * fold, when legal and check is not;
|
|
/// * each sizing candidate as a raise, valued over two branches (`bluff::branches`):
|
|
/// P(all fold) from each villain's profile (`exploit::table_fold`, times
|
|
/// `fold_equity_scale`) and the share against the calling range (`called`, realised
|
|
/// for the table size). Kept when
|
|
/// - it is a value raise (`is_value_raise`), or
|
|
/// - a semibluff (real draw, at most two villains, nobody who never folds) with a
|
|
/// positive fold branch, EV > 0 and EV above `passive_ev`, or
|
|
/// - a pure bluff (weak hand, heads-up, nobody who never folds) with P(fold) >= 0.5,
|
|
/// EV > 0 and EV at least `PURE_BLUFF_EDGE` pots above `passive_ev`.
|
|
pub fn scored(
|
|
spot: &Spot,
|
|
eff: &Effective,
|
|
thresholds: &Thresholds,
|
|
read: &HandRead,
|
|
called: &Called,
|
|
) -> Vec<Scored> {
|
|
let share = eff.share;
|
|
let free = spot.is_legal(ActionKind::Check);
|
|
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, check_ev(share, spot.pot)));
|
|
let call = (spot.is_legal(ActionKind::Call)
|
|
&& 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()));
|
|
|
|
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| {
|
|
sizes(spot, kind, share, read)
|
|
.into_iter()
|
|
.filter_map(|to| {
|
|
let fe = table_fold(spot, to, thresholds.fold_equity_scale);
|
|
let against = realized_share(called.share_at(to, share), eff.villains);
|
|
let b = branches(spot, to, fe, against);
|
|
let keep = match kind {
|
|
RaiseKind::Value => true,
|
|
RaiseKind::Semibluff => b.fold > 0.0 && b.total > 0.0 && b.total > floor,
|
|
RaiseKind::Bluff => {
|
|
fe >= PURE_BLUFF_MIN_FOLD
|
|
&& b.total > 0.0
|
|
&& b.total >= floor + PURE_BLUFF_EDGE * spot.pot
|
|
}
|
|
};
|
|
keep.then_some(Scored { choice: Choice::Raise { to }, ev: b.total, kind: Some(kind) })
|
|
})
|
|
.collect()
|
|
});
|
|
|
|
check
|
|
.into_iter()
|
|
.chain(call)
|
|
.chain(fold)
|
|
.chain(raises)
|
|
.filter(|s| s.ev.is_finite())
|
|
.collect()
|
|
}
|