Files
pokerfreak/src/wire/reads.rs
T
mmintelandClaude Opus 5.5 9c318660c2 Stichprobe je Gegner und reads: der Kern vertraut duennen Werten weniger und sagt, wie er sieht
Opponent stats come without a hand count, so 70 % VPIP over two hands
counted like a long record, and nobody could see how the engine read a
player. Optional profile.hands pulls frequencies toward the population
(w = hands / (hands + 30)); without it nothing changes. The response gains
`reads` (seat, style, foldChance, trust) next to the contract keys;
VERTRAG.md is untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 12:00:35 +01:00

61 lines
2.4 KiB
Rust

//! Response extension `reads` (not in VERTRAG.md): how the engine read each villain that came
//! with a profile - the style it acts on, the chance it folds to a two-thirds-pot bet, and how
//! much of the profile it trusts (exploit::sample). The caller shows it; nothing decides on it.
use crate::exploit::fold_chance::{fold_chance, REFERENCE_RATIO};
use crate::exploit::sample::trust;
use crate::exploit::style::{classify, Style};
use crate::game::Villain;
use crate::json::Value;
/// Wire name of a style.
pub fn style_name(style: Style) -> &'static str {
match style {
Style::Unknown => "unknown",
Style::Nit => "nit",
Style::LooseAggressive => "looseAggressive",
Style::CallingStation => "callingStation",
Style::Regular => "regular",
}
}
fn round2(x: f64) -> f64 {
(x * 100.0).round() / 100.0
}
/// `hands` of the villain on `seat` in the request, if it sent one.
fn hands_of(request: &Value, seat: u8) -> Option<f64> {
let Value::Object(root) = request else { return None };
let Some((_, Value::Array(villains))) = root.iter().find(|(k, _)| k == "villains") else { return None };
villains.iter().find_map(|v| {
let Value::Object(f) = v else { return None };
let on_seat = f.iter().any(|(k, s)| k == "seat" && *s == Value::Number(f64::from(seat)));
let Some((_, Value::Object(p))) = f.iter().find(|(k, _)| k == "profile") else { return None };
if !on_seat {
return None;
}
p.iter().find_map(|(k, h)| match (k.as_str(), h) {
("hands", Value::Number(n)) => Some(*n),
_ => None,
})
})
}
/// One entry per villain with a profile; None when there is none.
pub fn reads(request: &Value, villains: &[Villain]) -> Option<Value> {
let out: Vec<Value> = villains
.iter()
.filter_map(|v| {
let p = v.profile.as_ref()?;
let w = hands_of(request, v.seat).map_or(1.0, trust);
Some(Value::Object(vec![
("seat".to_string(), Value::Number(f64::from(v.seat))),
("style".to_string(), Value::String(style_name(classify(p)).to_string())),
("foldChance".to_string(), Value::Number(round2(fold_chance(Some(p), REFERENCE_RATIO, false)))),
("trust".to_string(), Value::Number(round2(w))),
]))
})
.collect();
(!out.is_empty()).then_some(Value::Array(out))
}