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>
99 lines
3.8 KiB
Rust
99 lines
3.8 KiB
Rust
//! Opponent sample size (request extension `villains[].profile.hands`) and what the engine read
|
|
//! (response extension `reads`). Neither is in VERTRAG.md.
|
|
//!
|
|
//! * Without `hands` a profile is used as given (old requests unchanged).
|
|
//! * With `hands`, every frequency is pulled toward the population: `p + w * (x - p)` with
|
|
//! `w = hands / (hands + PRIOR_HANDS)`.
|
|
//! * The response carries `reads`: per villain with a profile `{seat, style, foldChance, trust}`;
|
|
//! none without profiles.
|
|
|
|
use pokerfreak::exploit::profile::Profile;
|
|
use pokerfreak::exploit::sample::{shrink, trust, PRIOR_HANDS, PRIOR};
|
|
use pokerfreak::wire::respond::respond;
|
|
|
|
fn station() -> Profile {
|
|
Profile { vpip: Some(0.60), pfr: Some(0.05), fold_to_bet: Some(0.15), aggression: Some(0.20) }
|
|
}
|
|
|
|
#[test]
|
|
fn trust_grows_with_hands() {
|
|
assert_eq!(trust(0.0), 0.0);
|
|
assert!((trust(PRIOR_HANDS) - 0.5).abs() < 1e-12);
|
|
assert!(trust(1000.0) > 0.95);
|
|
assert_eq!(trust(-5.0), 0.0, "nonsense counts as no hands");
|
|
assert_eq!(trust(f64::NAN), 0.0);
|
|
}
|
|
|
|
#[test]
|
|
fn no_hands_is_the_population() {
|
|
let p = shrink(&station(), 0.0);
|
|
assert_eq!((p.vpip, p.pfr, p.fold_to_bet, p.aggression),
|
|
(Some(PRIOR.vpip.unwrap()), Some(PRIOR.pfr.unwrap()), Some(PRIOR.fold_to_bet.unwrap()),
|
|
Some(PRIOR.aggression.unwrap())));
|
|
}
|
|
|
|
#[test]
|
|
fn many_hands_keep_the_reads() {
|
|
let p = shrink(&station(), 10_000.0);
|
|
assert!((p.vpip.unwrap() - 0.60).abs() < 0.01);
|
|
assert!((p.fold_to_bet.unwrap() - 0.15).abs() < 0.01);
|
|
}
|
|
|
|
#[test]
|
|
fn missing_values_stay_missing() {
|
|
let p = shrink(&Profile { vpip: Some(0.5), ..Profile::default() }, 30.0);
|
|
assert!(p.pfr.is_none() && p.fold_to_bet.is_none() && p.aggression.is_none());
|
|
}
|
|
|
|
fn request(profile: &str) -> String {
|
|
format!(
|
|
r#"{{"variant":"NLHE","bigBlind":1.0,"seats":2,"heroSeat":1,"buttonSeat":2,
|
|
"heroCards":[{{"rank":"ACE","suit":"SPADES"}},{{"rank":"KING","suit":"SPADES"}}],
|
|
"board":{{"FLOP":null,"TURN":null,"RIVER":null}},"street":"PREFLOP","pot":1.5,"toCall":0.5,"heroStack":100.0,
|
|
"legalActions":["FOLD","CALL","RAISE"],"minRaiseTo":2.0,"maxRaiseTo":100.0,
|
|
"villains":[{{"seat":2,"stack":100.0,"folded":false{profile}}}],"seed":7}}"#
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn the_answer_says_how_it_read_each_villain() {
|
|
let answer = respond(&request(r#","profile":{"vpip":0.6,"pfr":0.05,"foldToBet":0.15,"hands":5000}"#));
|
|
assert!(answer.contains("\"reads\":["), "{answer}");
|
|
let reads = &answer;
|
|
assert!(reads.contains(r#""seat":2"#), "{answer}");
|
|
assert!(reads.contains(r#""style":"callingStation""#), "{answer}");
|
|
assert!(reads.contains(r#""trust":0.99"#), "{answer}");
|
|
assert!(reads.contains(r#""foldChance":0.15"#), "{answer}");
|
|
}
|
|
|
|
#[test]
|
|
fn few_hands_read_as_regular() {
|
|
// the same loose numbers over 2 hands: pulled almost to the population - not a station yet
|
|
let answer = respond(&request(r#","profile":{"vpip":0.6,"pfr":0.05,"foldToBet":0.15,"hands":2}"#));
|
|
assert!(answer.contains("\"reads\":["), "{answer}");
|
|
let reads = &answer;
|
|
assert!(reads.contains(r#""style":"regular""#), "{answer}");
|
|
assert!(reads.contains(r#""trust":0.06"#), "{answer}");
|
|
}
|
|
|
|
#[test]
|
|
fn without_hands_the_profile_counts_fully() {
|
|
let answer = respond(&request(r#","profile":{"vpip":0.6,"pfr":0.05,"foldToBet":0.15}"#));
|
|
assert!(answer.contains("\"reads\":["), "{answer}");
|
|
let reads = &answer;
|
|
assert!(reads.contains(r#""style":"callingStation""#), "{answer}");
|
|
assert!(reads.contains(r#""trust":1"#), "{answer}");
|
|
}
|
|
|
|
#[test]
|
|
fn no_profile_no_reads() {
|
|
let answer = respond(&request(""));
|
|
assert!(!answer.contains("\"reads\""), "{answer}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_malformed_hands_count_is_an_invalid_request() {
|
|
let answer = respond(&request(r#","profile":{"vpip":0.6,"hands":"viele"}"#));
|
|
assert!(answer.contains("invalid request"), "{answer}");
|
|
}
|