Files
pokerfreak/tests/pipeline_run_twice.rs
T
mmintel 04d5251acf Welt ohne fremden Namen: Pruefordner vollstaendig mitkopieren, Engine nur im eigenen Baum
Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete
Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
2026-11-01 23:37:11 +01:00

106 lines
4.2 KiB
Rust

//! Extension fields `ritOffered` (in) and `rit` / `ritReason` (out): run it twice.
//!
//! Rule: accept when the equity lies above the break-even point - the win is halved,
//! but so is the risk; otherwise decline. Break-even is `toCall / (pot + toCall)`; with
//! nothing left to call it is the fair share `1 / (players in the pot)`. Without an
//! equity estimate (preflop, ABSTAIN) the answer is `ABSTAIN`.
mod support;
use rechner::wire::respond::respond;
use support::{action, board_json, cards_json, field, short};
fn request(hero: &str, board: &str, pot: f64, to_call: f64, legal: &str, extra: &str) -> String {
let cards = short(board);
let street = match cards.len() {
0 => "PREFLOP",
3 => "FLOP",
4 => "TURN",
_ => "RIVER",
};
format!(
r#"{{"variant":"NLHE","bigBlind":0.1,"seats":6,"heroSeat":5,"buttonSeat":5,"heroCards":{},"board":{},"street":"{street}","pot":{pot},"toCall":{to_call},"heroStack":2.0,"minRaiseTo":2.0,"maxRaiseTo":2.0,"legalActions":{legal},"villains":[{{"seat":2,"stack":0.0,"folded":false}}]{extra}}}"#,
cards_json(&short(hero)),
board_json(&cards),
)
}
const OFFERED: &str = r#","ritOffered":true"#;
const FACING_ALL_IN: &str = r#"["FOLD","CALL"]"#;
fn rit(out: &str) -> String {
field(out, "rit").unwrap_or("<none>").trim_matches('"').to_string()
}
fn equity(out: &str) -> f64 {
field(out, "equity").and_then(|s| s.parse().ok()).unwrap_or_else(|| panic!("no equity: {out}"))
}
#[test]
fn above_break_even_accepts() {
// A set facing 2.0 into 3.0: break-even 0.4, the set is far above.
let out = respond(&request("7h 7d", "7c Ks 2d", 3.0, 2.0, FACING_ALL_IN, OFFERED));
assert!(equity(&out) > 0.4, "{out}");
assert_eq!(rit(&out), "ACCEPT", "{out}");
let reason = field(&out, "ritReason").unwrap_or("");
assert!(reason.contains("break-even"), "{out}");
}
#[test]
fn below_break_even_declines() {
// Seven-high with no draw facing 2.0 into 3.0: far below 0.4.
let out = respond(&request("7h 2c", "Ks Qd 9c", 3.0, 2.0, FACING_ALL_IN, OFFERED));
assert!(equity(&out) < 0.4, "{out}");
assert_eq!(rit(&out), "DECLINE", "{out}");
}
#[test]
fn with_nothing_to_call_the_fair_share_is_the_break_even_point() {
// Already all in: toCall 0, heads-up fair share 0.5.
let ahead = respond(&request("7h 7d", "7c Ks 2d", 5.0, 0.0, r#"["CHECK"]"#, OFFERED));
assert_eq!(rit(&ahead), "ACCEPT", "{ahead}");
let behind = respond(&request("7h 2c", "Ks Qd 9c", 5.0, 0.0, r#"["CHECK"]"#, OFFERED));
assert_eq!(rit(&behind), "DECLINE", "{behind}");
assert!(field(&behind, "ritReason").unwrap_or("").contains("fair share"), "{behind}");
}
#[test]
fn without_an_equity_estimate_it_abstains() {
let out = respond(&request("Ah Ad", "", 3.0, 2.0, FACING_ALL_IN, OFFERED));
assert_eq!(rit(&out), "ABSTAIN", "{out}");
assert!(field(&out, "ritReason").is_some(), "{out}");
}
#[test]
fn the_offer_does_not_change_the_action() {
for (hero, board) in [("7h 7d", "7c Ks 2d"), ("7h 2c", "Ks Qd 9c")] {
let plain = respond(&request(hero, board, 3.0, 2.0, FACING_ALL_IN, ""));
let offered = respond(&request(hero, board, 3.0, 2.0, FACING_ALL_IN, OFFERED));
assert_eq!(action(&plain), action(&offered));
assert_eq!(field(&plain, "equity"), field(&offered, "equity"));
}
}
#[test]
fn no_offer_no_rit_field() {
for extra in ["", r#","ritOffered":false"#, r#","ritOffered":null"#] {
let out = respond(&request("7h 7d", "7c Ks 2d", 3.0, 2.0, FACING_ALL_IN, extra));
assert_eq!(field(&out, "rit"), None, "{extra}: {out}");
assert_eq!(field(&out, "ritReason"), None, "{extra}: {out}");
}
}
#[test]
fn a_non_boolean_offer_is_refused() {
let out = respond(&request("7h 7d", "7c Ks 2d", 3.0, 2.0, FACING_ALL_IN, r#","ritOffered":"yes""#));
assert_eq!(action(&out), "ABSTAIN", "{out}");
assert!(field(&out, "reason").unwrap_or("").contains("ritOffered"), "{out}");
}
#[test]
fn works_together_with_a_double_board() {
let double = format!(r#","boardDouble":{}{OFFERED}"#, board_json(&short("Kc Qs Jd")));
let out = respond(&request("7h 7d", "7c Ks 2d", 3.0, 2.0, FACING_ALL_IN, &double));
assert_eq!(rit(&out), "ACCEPT", "the set on board 1 is the better judgement: {out}");
}