Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
73 lines
3.7 KiB
Rust
73 lines
3.7 KiB
Rust
//! `wantEvs`: the request asks for the EV of each legal line, for the trainer's comparison.
|
|
//! The decision itself never changes, and without the flag the answer stays byte-identical.
|
|
|
|
use rechner::json::{parse, Value};
|
|
use rechner::wire::respond::respond;
|
|
|
|
const BASE: &str = r#""variant":"NLHE","bigBlind":0.1,"seats":6,"heroSeat":5,"heroCards":[{"rank":"ACE","suit":"HEARTS"},{"rank":"FIVE","suit":"HEARTS"}],"board":{"FLOP":[{"rank":"ACE","suit":"CLUBS"},{"rank":"NINE","suit":"DIAMONDS"},{"rank":"FOUR","suit":"SPADES"}],"TURN":null,"RIVER":null},"street":"FLOP","pot":1.25,"toCall":0.2,"heroStack":2.4,"minRaiseTo":0.5,"maxRaiseTo":20.0,"legalActions":["FOLD","CALL","RAISE"],"allowedSizes":[0.5,1.15,4.6],"villains":[{"seat":2,"stack":10.4,"folded":false}]"#;
|
|
|
|
fn line(extra: &str) -> String {
|
|
format!("{{{BASE}{extra}}}")
|
|
}
|
|
|
|
fn field<'a>(value: &'a Value, name: &str) -> Option<&'a Value> {
|
|
match value {
|
|
Value::Object(felder) => felder.iter().find(|(k, _)| k == name).map(|(_, v)| v),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
fn evs(answer: &str) -> Vec<(String, f64)> {
|
|
let value = parse(answer).expect("answer is JSON");
|
|
let Some(Value::Array(rows)) = field(&value, "evs") else {
|
|
panic!("no evs in {answer}");
|
|
};
|
|
rows.iter()
|
|
.map(|row| {
|
|
let Some(Value::String(action)) = field(row, "action") else { panic!("action") };
|
|
let Some(Value::Number(ev)) = field(row, "ev") else { panic!("ev") };
|
|
(action.clone(), *ev)
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
#[test]
|
|
fn without_the_flag_the_answer_has_no_evs() {
|
|
assert!(!respond(&line("")).contains("\"evs\""));
|
|
}
|
|
|
|
#[test]
|
|
fn the_flag_changes_nothing_but_the_evs() {
|
|
let plain = parse(&respond(&line(""))).unwrap();
|
|
let asked = parse(&respond(&line(r#","wantEvs":true"#))).unwrap();
|
|
for name in ["action", "size", "confidence", "reason", "equity"] {
|
|
assert_eq!(field(&plain, name), field(&asked, name), "{name}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn fold_is_the_zero_line_and_call_carries_its_price() {
|
|
let rows = evs(&respond(&line(r#","wantEvs":true"#)));
|
|
let of = |name: &str| rows.iter().find(|(a, _)| a == name).map(|(_, ev)| *ev);
|
|
assert_eq!(of("FOLD"), Some(0.0));
|
|
// The reason of this spot prices the call at +0.80 (README example).
|
|
assert!((of("CALL").unwrap() - 0.80).abs() < 0.01, "{rows:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_call_the_rule_would_not_consider_is_still_priced() {
|
|
// Worst hand against a big bet: the rule drops the call, the trainer still needs its cost.
|
|
let spot = r#"{"variant":"NLHE","bigBlind":1.0,"seats":6,"heroSeat":5,"heroCards":[{"rank":"TWO","suit":"HEARTS"},{"rank":"SEVEN","suit":"CLUBS"}],"board":{"FLOP":[{"rank":"ACE","suit":"CLUBS"},{"rank":"KING","suit":"DIAMONDS"},{"rank":"QUEEN","suit":"SPADES"}],"TURN":null,"RIVER":null},"street":"FLOP","pot":10.0,"toCall":10.0,"heroStack":100.0,"minRaiseTo":20.0,"maxRaiseTo":100.0,"legalActions":["FOLD","CALL","RAISE"],"villains":[{"seat":2,"stack":100.0,"folded":false}],"wantEvs":true}"#;
|
|
let answer = respond(spot);
|
|
assert!(answer.contains(r#""action":"FOLD""#), "{answer}");
|
|
let rows = evs(&answer);
|
|
let call = rows.iter().find(|(a, _)| a == "CALL").expect("call priced");
|
|
assert!(call.1 < 0.0, "{rows:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn preflop_has_no_evs_because_the_charts_have_none() {
|
|
let spot = r#"{"variant":"NLHE","bigBlind":1.0,"seats":6,"heroSeat":5,"heroCards":[{"rank":"ACE","suit":"HEARTS"},{"rank":"ACE","suit":"CLUBS"}],"board":{"FLOP":null,"TURN":null,"RIVER":null},"street":"PREFLOP","pot":1.5,"toCall":1.0,"heroStack":100.0,"minRaiseTo":2.0,"maxRaiseTo":100.0,"legalActions":["FOLD","CALL","RAISE"],"villains":[{"seat":2,"stack":100.0,"folded":false}],"wantEvs":true}"#;
|
|
assert!(!respond(spot).contains("\"evs\""));
|
|
}
|