D1c: Leseschicht im River-Veto hinter GEGNER_RANGE (aus), Werte auf echten Gegnern, Messarme eingereiht
- river_subgame: river_tree_weighted (Gewicht je Gegner-Kombi), read_belief (gekippte Range, festgelegter geglaubter Gegner aus Fold/Bluffanteil), KL gegen das ungekippte Gleichgewicht, Vertrauen aus RangeRead::trust; ohne Schalter bitgleich. - range_read::on() (GEGNER_RANGE=1), decide.py kennt den Schalter. - bin/range_read_scan + messung_zaehlung/range_read.py: 634 echte Gegner-Spots; gezaehlt 85/123 River-Spots mit Bluff-Vertrauen >= 0,5 (live 0). - Leiter range-an + LBR range-lbr-typ eingereiht; STAND §10, PLAN D1c. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
//! Read layer on real villains (plan D1c): one wire-form profile object per stdin line, decoded as a
|
||||
//! live request's `villains[].profile`, then `exploit::range_read::RangeRead`. Prints one tab line
|
||||
//! per profile: tilt, bluff share river (pot bet / 2/3 pot), fold river, confidence, bluff trust
|
||||
//! river, or `-` without a read.
|
||||
//!
|
||||
//! messung_zaehlung/range_read.py writes the profiles and reads this back.
|
||||
|
||||
use rechner::exploit::range_read::RangeRead;
|
||||
use std::io::BufRead;
|
||||
|
||||
fn main() {
|
||||
let stdin = std::io::stdin();
|
||||
for line in stdin.lock().lines() {
|
||||
let Ok(line) = line else { break };
|
||||
let text = format!("{{\"villains\":[{{\"seat\":1,\"stack\":100,\"folded\":false,\"profile\":{}}}]}}", line.trim());
|
||||
let profile = rechner::json::parse::parse(&text)
|
||||
.ok()
|
||||
.and_then(|root| rechner::wire::decode_villain::villains(&root).ok())
|
||||
.and_then(|v| v.into_iter().next())
|
||||
.and_then(|v| v.profile);
|
||||
match RangeRead::from_profile(profile.as_ref()) {
|
||||
Some(r) => println!(
|
||||
"{:.4}\t{:.4}\t{:.4}\t{}\t{:.4}\t{:.4}",
|
||||
r.tilt,
|
||||
r.bluff_share(2, 1.0),
|
||||
r.bluff_share(2, 0.66),
|
||||
r.fold_to_bet(2).map_or("-".to_string(), |f| format!("{f:.4}")),
|
||||
r.confidence,
|
||||
r.trust(true, 2)
|
||||
),
|
||||
None => println!("-"),
|
||||
}
|
||||
}
|
||||
}
|
||||
+127
-14
@@ -50,6 +50,7 @@ use crate::cfr::tree::{Node, Tree};
|
||||
use crate::exploit::fold_chance::DEFAULT_FOLD_TO_BET;
|
||||
use crate::exploit::posterior::DEFAULT_AGGRESSION;
|
||||
use crate::exploit::profile::Profile;
|
||||
use crate::exploit::range_read::{self, RangeRead};
|
||||
use crate::game::{Choice, Decision, SeenAction, Spot, Street, Villain};
|
||||
use crate::hand::showdown::judge;
|
||||
use crate::hand::strength::Strength;
|
||||
@@ -145,16 +146,36 @@ fn subgame(spot: &Spot, hero_combos: &[Vec<Card>], villain_combos: &[Vec<Card>],
|
||||
|
||||
/// The card-exact river tree and its strength ladder, unsolved (see `subgame`).
|
||||
fn river_tree(spot: &Spot, hero_combos: &[Vec<Card>], villain_combos: &[Vec<Card>], pot: f64, bet: f64) -> Option<(Tree, Vec<Strength>)> {
|
||||
river_tree_weighted(spot, hero_combos, villain_combos, None, pot, bet)
|
||||
}
|
||||
|
||||
/// `river_tree` with a weight per villain combo (the read's range tilt, `RangeRead::reweigh`):
|
||||
/// each deal counts its villain combo's weight instead of 1. `None` = all 1 (bit-identical).
|
||||
fn river_tree_weighted(
|
||||
spot: &Spot,
|
||||
hero_combos: &[Vec<Card>],
|
||||
villain_combos: &[Vec<Card>],
|
||||
villain_weights: Option<&[f64]>,
|
||||
pot: f64,
|
||||
bet: f64,
|
||||
) -> Option<(Tree, Vec<Strength>)> {
|
||||
let rules = spot.rules();
|
||||
let judged = |combos: &[Vec<Card>]| -> Vec<(Vec<Card>, Strength)> {
|
||||
combos.iter().filter_map(|c| judge(&rules, c, &spot.board).ok().map(|s| (c.clone(), s))).collect()
|
||||
let judged = |combos: &[Vec<Card>], weights: Option<&[f64]>| -> Vec<(Vec<Card>, Strength, f64)> {
|
||||
combos
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, c)| {
|
||||
let w = weights.and_then(|w| w.get(i).copied()).unwrap_or(1.0);
|
||||
judge(&rules, c, &spot.board).ok().map(|s| (c.clone(), s, w))
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
let hero = judged(hero_combos);
|
||||
let villain = judged(villain_combos);
|
||||
let hero = judged(hero_combos, None);
|
||||
let villain = judged(villain_combos, villain_weights);
|
||||
if hero.is_empty() || villain.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let mut ladder: Vec<Strength> = hero.iter().chain(&villain).map(|(_, s)| *s).collect();
|
||||
let mut ladder: Vec<Strength> = hero.iter().chain(&villain).map(|(_, s, _)| *s).collect();
|
||||
ladder.sort();
|
||||
ladder.dedup();
|
||||
let n = ladder.len();
|
||||
@@ -163,11 +184,11 @@ fn river_tree(spot: &Spot, hero_combos: &[Vec<Card>], villain_combos: &[Vec<Card
|
||||
}
|
||||
let bucket = |s: Strength| ladder.partition_point(|d| *d < s).min(n - 1);
|
||||
let mut chance = vec![0.0; n * n];
|
||||
for (hc, hs) in &hero {
|
||||
for (hc, hs, _) in &hero {
|
||||
let hb = bucket(*hs);
|
||||
for (vc, vs) in &villain {
|
||||
for (vc, vs, w) in &villain {
|
||||
if disjoint(hc, vc) {
|
||||
chance[hb * n + bucket(*vs)] += 1.0;
|
||||
chance[hb * n + bucket(*vs)] += *w;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -257,14 +278,68 @@ pub(crate) fn river_bluff_aggression(profile: Option<&Profile>, pot: f64, bet: f
|
||||
if gto_bluff <= 0.0 {
|
||||
return a;
|
||||
}
|
||||
let s = share.clamp(0.0, 0.999);
|
||||
let bluff_prob = (s * (1.0 - VALUE_RANK) / (BLUFF_RANK * (1.0 - s))).clamp(0.0, 1.0);
|
||||
let shown = (bluff_prob * DEFAULT_AGGRESSION / gto_bluff).clamp(0.0, 1.0);
|
||||
let shown = aggression_for_share(share, gto_bluff);
|
||||
let base = a.unwrap_or(DEFAULT_AGGRESSION);
|
||||
let w = n / (n + SHOWN_HALF);
|
||||
Some(base + w * (shown - base))
|
||||
}
|
||||
|
||||
/// The aggression at which `believed_villain` bets a range whose air share is `share` (bets = value
|
||||
/// above `VALUE_RANK` + `bluff_prob` of the range below `BLUFF_RANK`, `bluff_prob = gto_bluff · a /
|
||||
/// DEFAULT_AGGRESSION`), inverted. `gto_bluff = bet/(pot+bet)` > 0.
|
||||
fn aggression_for_share(share: f64, gto_bluff: f64) -> f64 {
|
||||
let s = share.clamp(0.0, 0.999);
|
||||
let bluff_prob = (s * (1.0 - VALUE_RANK) / (BLUFF_RANK * (1.0 - s))).clamp(0.0, 1.0);
|
||||
(bluff_prob * DEFAULT_AGGRESSION / gto_bluff).clamp(0.0, 1.0)
|
||||
}
|
||||
|
||||
/// Strength percentile of each villain combo within its own range (mid-rank, equal weight per
|
||||
/// combo, ties share their middle): the `p` of `RangeRead::reweigh`. Unjudgeable combos get ½.
|
||||
fn range_percentiles(spot: &Spot, combos: &[Vec<Card>]) -> Vec<f64> {
|
||||
let rules = spot.rules();
|
||||
let strengths: Vec<Option<Strength>> = combos.iter().map(|c| judge(&rules, c, &spot.board).ok()).collect();
|
||||
let mut sorted: Vec<Strength> = strengths.iter().flatten().copied().collect();
|
||||
sorted.sort();
|
||||
let n = sorted.len().max(1) as f64;
|
||||
strengths
|
||||
.iter()
|
||||
.map(|s| match s {
|
||||
Some(s) => {
|
||||
let below = sorted.partition_point(|d| d < s) as f64;
|
||||
let equal = sorted.partition_point(|d| d <= s) as f64 - below;
|
||||
(below + equal / 2.0) / n
|
||||
}
|
||||
None => 0.5,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The read layer (`exploit::range_read`, switch `GEGNER_RANGE=1`) applied to the river gearbox: the
|
||||
/// game the believed villain plays on (villain range tilted), the believed villain (fold-to-bet and
|
||||
/// the air share of its betting range for this size, node-locked) and the trust behind it. Hero's
|
||||
/// reference stays the UNtilted equilibrium, so the KL bound covers the tilt too.
|
||||
fn read_belief(spot: &Spot, game: &Subgame, villain_combos: &[Vec<Card>], read: &RangeRead, profile: Option<&Profile>, pot: f64, bet: f64) -> Option<(Tree, Strategy)> {
|
||||
let tree = if read.tilt != 0.0 {
|
||||
let pct = range_percentiles(spot, villain_combos);
|
||||
let weights = read.reweigh(&pct.iter().map(|p| (1.0, *p)).collect::<Vec<_>>());
|
||||
let (tree, ladder) = river_tree_weighted(spot, villain_combos, villain_combos, Some(&weights), pot, bet)?;
|
||||
if ladder != game.ladder {
|
||||
return None;
|
||||
}
|
||||
tree
|
||||
} else {
|
||||
game.tree.clone()
|
||||
};
|
||||
let gto_bluff = if pot + bet > 0.0 { bet / (pot + bet) } else { 0.0 };
|
||||
if gto_bluff <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
let share = read.bluff_share(2, if pot > 0.0 { bet / pot } else { 0.0 });
|
||||
let believed = Profile { fold_to_bet: read.fold_to_bet(2).or(profile.and_then(|p| p.fold_to_bet)), ..profile.copied().unwrap_or_default() };
|
||||
let opponent = believed_villain(&tree, game.ladder.len(), Some(&believed), pot, bet, Some(aggression_for_share(share, gto_bluff)));
|
||||
Some((tree, opponent))
|
||||
}
|
||||
|
||||
/// The KL trust radius from the read's confidence (payoff/chip units). `λ = LAMBDA_POT_SCALE · pot ·
|
||||
/// (1−c)/c`: no confidence (`None`/0) → `∞` → `kl_best_response` returns exact GTO (the proven
|
||||
/// unexploitable baseline — it can never again balance against a fish it cannot read); confidence → 1
|
||||
@@ -339,7 +414,12 @@ pub fn river_exploit_plan(spot: &Spot, villain_combos: &[Vec<Card>], profile: Op
|
||||
}
|
||||
// Only exploit on a read strong enough to trust; otherwise the heuristic keeps the edge.
|
||||
// The gearbox exploits a belief about BLUFFING: trust it only as far as the aggression read goes.
|
||||
let confidence = profile.and_then(Profile::bluff_read_confidence);
|
||||
// With the read layer on (GEGNER_RANGE=1), its own bluff trust (shown river bets count too).
|
||||
let read = if range_read::on() { RangeRead::from_profile(profile) } else { None };
|
||||
let confidence = match &read {
|
||||
Some(r) => Some(r.trust(true, 2)),
|
||||
None => profile.and_then(Profile::bluff_read_confidence),
|
||||
};
|
||||
if confidence.unwrap_or(0.0) < CONFIDENCE_FLOOR {
|
||||
return None;
|
||||
}
|
||||
@@ -358,9 +438,14 @@ pub fn river_exploit_plan(spot: &Spot, villain_combos: &[Vec<Card>], profile: Op
|
||||
|
||||
let game = subgame(spot, villain_combos, villain_combos, pot, bet)?;
|
||||
let n = game.ladder.len();
|
||||
let opponent = believed_villain(&game.tree, n, profile, pot, bet, river_bluff_aggression(profile, pot, bet));
|
||||
let lambda = lambda_from_confidence(confidence, pot);
|
||||
let tilted = kl_best_response(&game.tree, &opponent, &game.solved.strategy, 0, lambda);
|
||||
let tilted = match read.as_ref().and_then(|r| read_belief(spot, &game, villain_combos, r, profile, pot, bet)) {
|
||||
Some((tree, opponent)) => kl_best_response(&tree, &opponent, &game.solved.strategy, 0, lambda),
|
||||
None => {
|
||||
let opponent = believed_villain(&game.tree, n, profile, pot, bet, river_bluff_aggression(profile, pot, bet));
|
||||
kl_best_response(&game.tree, &opponent, &game.solved.strategy, 0, lambda)
|
||||
}
|
||||
};
|
||||
let hb = game.bucket(hero_strength);
|
||||
|
||||
// Node 0 "hero" [check, bet] when first to act; node 4 "hero_vs_bet" [fold, call] facing a bet.
|
||||
@@ -1039,6 +1124,34 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// The read layer (`GEGNER_RANGE`): a looser range (tilt < 0) and more believed air both make
|
||||
/// hero call a bluff-catcher more; the tilt keeps the ladder, and a population read with no
|
||||
/// shown bets leaves the believed fold-to-bet as read.
|
||||
#[test]
|
||||
fn the_read_layer_tilts_the_range_and_locks_the_believed_bettor() {
|
||||
let board = Card::parse_list("Ah Kd 7c 2s 9h").unwrap();
|
||||
let villain = sample_villain();
|
||||
let spot = river_vs_bet(&board, "Jc Js", 6.0, 6.0, None);
|
||||
let game = subgame(&spot, &villain, &villain, 6.0, 6.0).unwrap();
|
||||
let hb = game.bucket(judge(&spot.rules(), &spot.hero_cards, &board).unwrap());
|
||||
let call = |p: Profile| {
|
||||
let r = RangeRead::from_profile(Some(&p)).unwrap();
|
||||
let (tree, opp) = read_belief(&spot, &game, &villain, &r, Some(&p), 6.0, 6.0).unwrap();
|
||||
let lambda = lambda_from_confidence(Some(r.trust(true, 2)), 6.0);
|
||||
kl_best_response(&tree, &opp, &game.solved.strategy, 0, lambda).row(4, hb)[1]
|
||||
};
|
||||
let base = Profile { vpip: Some(0.28), ..prof(0.45, 0.35, 0.85) };
|
||||
let loose = call(Profile { vpip: Some(0.84), ..base });
|
||||
let tight = call(Profile { vpip: Some(0.10), ..base });
|
||||
assert!(loose > tight, "a looser range is called more: {loose:.3} vs {tight:.3}");
|
||||
let bluffer = call(Profile { river_aggression: Some(0.9), ..base });
|
||||
let honest = call(Profile { river_aggression: Some(0.03), ..base });
|
||||
assert!(bluffer > honest, "more believed air is called more: {bluffer:.3} vs {honest:.3}");
|
||||
let pct = range_percentiles(&spot, &villain);
|
||||
assert!(pct.iter().all(|p| (0.0..=1.0).contains(p)));
|
||||
assert!(pct[0] > pct[5], "AJ (aces) above 54 (nothing)");
|
||||
}
|
||||
|
||||
/// The veto never touches hero's offense: a base that is not a call is returned unchanged even
|
||||
/// though a plan exists (guards against the −43/−48 full-replacement regression returning).
|
||||
#[test]
|
||||
|
||||
@@ -50,6 +50,13 @@ pub struct RangeRead {
|
||||
pub bluff_confidence: f64,
|
||||
}
|
||||
|
||||
/// Measurement switch (read once): `GEGNER_RANGE=1` lets the river gearbox (`engine::river_subgame`)
|
||||
/// apply the read layer. Default off: bit-identical to before.
|
||||
pub fn on() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| std::env::var("GEGNER_RANGE").as_deref() == Ok("1"))
|
||||
}
|
||||
|
||||
fn ok(x: Option<f64>) -> Option<f64> {
|
||||
x.filter(|v| v.is_finite())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user