D1c: RangeRead::believed_row fuer das Knoten-Festlegen im TrSolver (restricted Nash response)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
//! Live only behind the switch `GEGNER_RANGE=1` (default off).
|
||||
|
||||
use super::posterior::DEFAULT_AGGRESSION;
|
||||
use crate::cfr::river_game::Act;
|
||||
use super::profile::Profile;
|
||||
use super::sample::{PRIOR, STREET_PRIOR};
|
||||
|
||||
@@ -32,6 +33,13 @@ use super::sample::{PRIOR, STREET_PRIOR};
|
||||
pub const TILT_SCALE: f64 = 1.0;
|
||||
/// The tilt never exceeds this either way (a 90 % vpip player is not infinitely weak).
|
||||
pub const TILT_MAX: f64 = 2.0;
|
||||
/// Range percentile at/above which the believed villain value-bets when it may bet (as the river
|
||||
/// gearbox's `VALUE_RANK`).
|
||||
pub const VALUE_PCT: f64 = 0.60;
|
||||
/// Range percentile at/below which the believed villain may bluff (as `BLUFF_RANK`).
|
||||
pub const BLUFF_PCT: f64 = 0.30;
|
||||
/// The bet size (pot fraction) the believed villain uses when several are offered: the nearest.
|
||||
pub const BELIEVED_BET_FRACTION: f64 = 0.66;
|
||||
|
||||
/// The read the solver applies to one villain.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@@ -120,6 +128,61 @@ impl RangeRead {
|
||||
self.fold.get(street).copied().flatten()
|
||||
}
|
||||
|
||||
/// The believed villain's strategy at one decision node, for node-locking in the solver
|
||||
/// (restricted Nash response: villain plays `(1−w)·σ_cfr + w·believed`, `w` = the solver's trust).
|
||||
/// `acts` are the node's actions (sizes = street totals in chips), `pot` the pot before this
|
||||
/// street's bets, `pct` the combo's strength percentile in the villain's (weighted) range. One
|
||||
/// probability per act, or `None` = no opinion (the node stays pure CFR).
|
||||
///
|
||||
/// - **Facing a bet** (`Fold` and `Call` offered): folds below the street's fold-to-bet read by
|
||||
/// percentile, calls above; never raises (the read says nothing about raising). No fold read →
|
||||
/// `None`.
|
||||
/// - **May bet** (`Check` and `Bet` offered): value-bets from `VALUE_PCT`, bluffs below `BLUFF_PCT`
|
||||
/// with the probability that makes the air share of its betting range `bluff_share(street, size)`,
|
||||
/// checks the middle; one size (nearest `BELIEVED_BET_FRACTION`). No aggression read on the street
|
||||
/// (and, on the river, no shown bets) → `None`.
|
||||
///
|
||||
/// On flop and turn `pct` is current strength (draw-blind), so the bluff region holds the draws:
|
||||
/// read it as "bets with nothing made", semi-bluffs included.
|
||||
pub fn believed_row(&self, street: u8, acts: &[Act], pot: f64, pct: f64) -> Option<Vec<f64>> {
|
||||
let st = street as usize;
|
||||
if st > 2 || acts.is_empty() || !pct.is_finite() {
|
||||
return None;
|
||||
}
|
||||
let pct = pct.clamp(0.0, 1.0);
|
||||
let has = |f: fn(&Act) -> bool| acts.iter().any(f);
|
||||
if has(|a| matches!(a, Act::Fold)) && has(|a| matches!(a, Act::Call)) {
|
||||
let f = self.fold_to_bet(st)?;
|
||||
let fold = pct < f;
|
||||
return Some(acts.iter().map(|a| match a {
|
||||
Act::Fold => fold as u8 as f64,
|
||||
Act::Call => !fold as u8 as f64,
|
||||
_ => 0.0,
|
||||
}).collect());
|
||||
}
|
||||
if has(|a| matches!(a, Act::Check)) && has(|a| matches!(a, Act::Bet(_))) {
|
||||
let read = self.aggression_ratio[st].is_some() || (st == 2 && self.shown.is_some());
|
||||
if !read || pot <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
let (ix, to) = acts
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, a)| if let Act::Bet(x) = a { Some((i, *x)) } else { None })
|
||||
.min_by(|a, b| (a.1 / pot - BELIEVED_BET_FRACTION).abs().total_cmp(&(b.1 / pot - BELIEVED_BET_FRACTION).abs()))?;
|
||||
let share = self.bluff_share(st, to / pot).clamp(0.0, 0.95);
|
||||
// air share = BLUFF_PCT·b / ((1−VALUE_PCT) + BLUFF_PCT·b) → b
|
||||
let bluff = (share * (1.0 - VALUE_PCT) / (BLUFF_PCT * (1.0 - share))).clamp(0.0, 1.0);
|
||||
let bet = if pct >= VALUE_PCT { 1.0 } else if pct <= BLUFF_PCT { bluff } else { 0.0 };
|
||||
return Some(acts.iter().enumerate().map(|(i, a)| match a {
|
||||
Act::Check => 1.0 - bet,
|
||||
_ if i == ix => bet,
|
||||
_ => 0.0,
|
||||
}).collect());
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// The confidence a hero line exploiting this read may use: the bluff confidence for lines that
|
||||
/// rest on the villain's betting (calling down, folding bluff-catchers), the plain one otherwise.
|
||||
/// A shown-hand count lifts the bluff confidence to at least its own weight on the river.
|
||||
@@ -188,6 +251,27 @@ mod tests {
|
||||
assert_eq!(unread.trust(true, 1), 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn believed_rows_for_the_solver_lock() {
|
||||
let r = RangeRead::from_profile(Some(&Profile { river_aggression: Some(0.35), ..p() })).unwrap();
|
||||
let facing = [Act::Fold, Act::Call, Act::Raise(30.0)];
|
||||
assert_eq!(r.believed_row(2, &facing, 10.0, 0.2), Some(vec![1.0, 0.0, 0.0]));
|
||||
assert_eq!(r.believed_row(2, &facing, 10.0, 0.7), Some(vec![0.0, 1.0, 0.0]));
|
||||
let open = [Act::Check, Act::Bet(3.3), Act::Bet(6.6), Act::Bet(10.0)];
|
||||
assert_eq!(r.believed_row(2, &open, 10.0, 0.9), Some(vec![0.0, 0.0, 1.0, 0.0]), "value on the 2/3 size");
|
||||
assert_eq!(r.believed_row(2, &open, 10.0, 0.45), Some(vec![1.0, 0.0, 0.0, 0.0]), "middle checks");
|
||||
let air = r.believed_row(2, &open, 10.0, 0.1).unwrap();
|
||||
// the betting range's air share is the indifference share at 0.66 pot
|
||||
let b = air[2];
|
||||
let share = BLUFF_PCT * b / ((1.0 - VALUE_PCT) + BLUFF_PCT * b);
|
||||
assert!((share - 0.66 / 2.32).abs() < 1e-9, "air share {share}");
|
||||
assert!((air.iter().sum::<f64>() - 1.0).abs() < 1e-12);
|
||||
let unread = RangeRead::from_profile(Some(&Profile { fold_to_bet: None, aggression: None, ..p() })).unwrap();
|
||||
assert_eq!(unread.believed_row(2, &facing, 10.0, 0.2), None, "no fold read, no opinion");
|
||||
assert_eq!(unread.believed_row(2, &open, 10.0, 0.2), None, "no aggression read, no opinion");
|
||||
assert_eq!(r.believed_row(3, &open, 10.0, 0.2), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bluff_trust_is_the_weaker_read() {
|
||||
let thin = Profile { aggression_confidence: Some(0.06), ..p() };
|
||||
|
||||
Reference in New Issue
Block a user