Files
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

149 lines
6.6 KiB
Rust

//! PLO4 (four hole cards, Omaha rule, pot-limit) end to end through `wire::respond::respond`.
//!
//! Spot template: hand 166344000006 of the real client log ("14R PLO 0.02-0.05", bomb pot with
//! double board, blinds 0.02/0.05, ante 0.10, two players left). The boards are the real ones
//! (first board 7d 9d Ks, turn 5d; second board 2d 3s Ad, turn 7c); the hole cards are chosen
//! for the tests because the log does not reveal them. A bomb pot has no preflop betting, so
//! the first decision is on the flop.
mod support;
use rechner::hand::category::Category;
use rechner::hand::showdown::best;
use rechner::variant::HoleUsage;
use rechner::wire::respond::respond;
use support::{action, board_json, cards_json, field, short, size};
/// Real boards of the template hand (flop, then flop + turn).
const BOARD_1: &str = "7d 9d Ks";
const BOARD_2: &str = "2d 3s Ad";
const BOARD_1_TURN: &str = "7d 9d Ks 5d";
const BOARD_2_TURN: &str = "2d 3s Ad 7c";
/// Top set on the first board, only a pair under the ace on the second.
const HERO: &str = "Kh Kd 8c 6c";
#[allow(clippy::too_many_arguments)]
fn request(
variant: &str,
hero: &str,
board: &str,
double: Option<&str>,
pot: f64,
to_call: f64,
legal: &str,
max_raise: f64,
) -> String {
let cards = short(board);
let street = match cards.len() {
0 => "PREFLOP",
3 => "FLOP",
4 => "TURN",
_ => "RIVER",
};
let double = double.map_or(String::new(), |b| format!(r#","boardDouble":{}"#, board_json(&short(b))));
format!(
r#"{{"variant":"{variant}","bigBlind":0.05,"seats":6,"heroSeat":6,"buttonSeat":4,"heroCards":{},"board":{},"street":"{street}","pot":{pot},"toCall":{to_call},"heroStack":3.84,"minRaiseTo":{},"maxRaiseTo":{max_raise},"legalActions":{legal},"villains":[{{"seat":4,"stack":4.89,"folded":false}}]{double}}}"#,
cards_json(&short(hero)),
board_json(&cards),
(to_call * 2.0).max(0.05),
)
}
const FACING_BET: &str = r#"["FOLD","CALL","RAISE"]"#;
const CHECKED_TO: &str = r#"["CHECK","RAISE"]"#;
#[test]
fn a_real_plo4_request_is_answered_not_rejected() {
let out = respond(&request("PLO4", HERO, BOARD_1, None, 0.2, 0.1, FACING_BET, 3.84));
assert_ne!(action(&out), "ABSTAIN", "{out}");
let reason = field(&out, "reason").unwrap_or("");
assert!(!reason.contains("expected"), "{out}");
// Top set on a two-tone board with the nut-flush draw dead: never a fold.
assert_ne!(action(&out), "FOLD", "{out}");
}
#[test]
fn the_bomb_pot_turn_is_answered_too() {
let out = respond(&request("PLO4", HERO, BOARD_1_TURN, None, 0.4, 0.0, CHECKED_TO, 3.84));
assert_ne!(action(&out), "ABSTAIN", "{out}");
}
#[test]
fn any_other_number_of_hole_cards_is_refused() {
for hero in ["Kh Kd", "Kh Kd 8c", "Kh Kd 8c 6c 2h"] {
let out = respond(&request("PLO4", hero, BOARD_1, None, 0.2, 0.1, FACING_BET, 3.84));
assert_eq!(action(&out), "ABSTAIN", "{hero}: {out}");
let reason = field(&out, "reason").unwrap_or("");
assert!(reason.contains("expected 4 cards for PLO4"), "{hero}: {out}");
}
// The neighbours keep their own counts: four cards are not a PLO5 or NLHE hand.
for variant in ["PLO5", "NLHE"] {
let out = respond(&request(variant, HERO, BOARD_1, None, 0.2, 0.1, FACING_BET, 3.84));
assert_eq!(action(&out), "ABSTAIN", "{variant}: {out}");
}
}
#[test]
fn omaha_rule_exactly_two_hole_cards_decide_the_hand() {
// Three hole hearts plus Jh Th would be a royal flush at Hold'em; at Omaha only two hole
// cards may play, so there is no flush and no straight.
let (hole, board) = (short("Ah Kh Qh 2c"), short("Jh Th 3d"));
let omaha = best(HoleUsage::ExactlyTwoHole, &hole, &board).expect("valid");
let holdem = best(HoleUsage::BestFiveOfAll, &hole, &board).expect("valid");
assert_eq!(holdem.category, Category::StraightFlush);
assert!(omaha.category <= Category::Pair, "{:?}", omaha.category);
// And so the pipeline reads the same thing: no made straight or flush.
let line = request("PLO4", "Ah Kh Qh 2c", "Jh Th 3d 8c 4s", None, 1.0, 0.0, CHECKED_TO, 3.84);
let out = respond(&line);
let category = field(&out, "category").unwrap_or("");
assert!(!category.contains("Flush") && !category.contains("Straight"), "{out}");
}
#[test]
fn omaha_rule_four_hole_cards_cannot_be_used_together() {
// Quads in the hand are only one pair for Omaha's two-card pick, never four of a kind.
let (hole, board) = (short("Ah Ad Ac As"), short("2d 7h 9c Js 4h"));
let omaha = best(HoleUsage::ExactlyTwoHole, &hole, &board).expect("valid");
assert_eq!(omaha.category, Category::Pair);
}
#[test]
fn double_board_reason_names_the_judgement_of_both_boards() {
// `board` is the weak one (pair of kings under the ace), `boardDouble` the set board.
let out = respond(&request("PLO4", HERO, BOARD_2, Some(BOARD_1), 0.4, 0.0, CHECKED_TO, 3.84));
let reason = field(&out, "reason").unwrap_or("");
assert!(reason.contains("double board"), "{out}");
assert!(reason.contains("board 2"), "the second board was the better one: {out}");
assert!(reason.contains("pot split"), "{out}");
let same = respond(&request("PLO4", HERO, BOARD_1, Some(BOARD_2), 0.4, 0.0, CHECKED_TO, 3.84));
assert_eq!(field(&same, "equity"), field(&out, "equity"), "board order must not matter");
assert_ne!(action(&out), "ABSTAIN", "{out}");
}
#[test]
fn double_board_works_on_the_turn_as_well() {
let out = respond(&request("PLO4", HERO, BOARD_2_TURN, Some(BOARD_1_TURN), 0.4, 0.0, CHECKED_TO, 3.84));
assert_ne!(action(&out), "ABSTAIN", "{out}");
assert!(field(&out, "reason").unwrap_or("").contains("double board"), "{out}");
}
#[test]
fn raises_never_exceed_the_pot() {
let mut raises = 0;
for (pot, to_call) in [(0.2, 0.0), (0.2, 0.1), (0.5, 0.0), (0.5, 0.25), (1.2, 0.4), (3.0, 1.0), (0.4, 0.4)] {
for (board, hero) in [(BOARD_1, HERO), (BOARD_1_TURN, HERO), (BOARD_1, "Ks Kc 9h 9c"), (BOARD_2, "Ac Ah 5d 4d")] {
let legal = if to_call > 0.0 { FACING_BET } else { CHECKED_TO };
// The table would allow far more than the pot: the core must cap at pot-limit.
let out = respond(&request("PLO4", hero, board, None, pot, to_call, legal, 3.84));
if action(&out) == "RAISE" {
raises += 1;
let s = size(&out).expect("raise carries a size");
let cap = pot + 2.0 * to_call;
assert!(s <= cap + 1e-9, "raise to {s} over pot-limit cap {cap}: {out}");
}
}
}
assert!(raises > 0, "the monsters in the grid must raise at least once");
}