Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
217 lines
7.1 KiB
Rust
217 lines
7.1 KiB
Rust
//! End-to-end spec for the postflop upgrade, short deck and position inference.
|
|
|
|
mod support;
|
|
|
|
use rechner::wire::respond::respond;
|
|
use support::{action, board_json, cards_json, confidence, field, short, size};
|
|
|
|
struct Request<'a> {
|
|
variant: &'a str,
|
|
hero: &'a str,
|
|
board: &'a str,
|
|
street: &'a str,
|
|
pot: f64,
|
|
to_call: f64,
|
|
legal: &'a str,
|
|
villains: usize,
|
|
extra: &'a str,
|
|
}
|
|
|
|
impl Request<'_> {
|
|
fn line(&self) -> String {
|
|
let villains: Vec<String> = (0..self.villains)
|
|
.map(|i| format!(r#"{{"seat":{},"stack":40.0,"folded":false}}"#, i + 1))
|
|
.collect();
|
|
format!(
|
|
r#"{{"variant":"{}","bigBlind":1,"seats":6,"heroSeat":6,"buttonSeat":6,"heroCards":{},"board":{},"street":"{}","pot":{},"toCall":{},"heroStack":40,"minRaiseTo":{},"maxRaiseTo":40,"legalActions":{},"villains":[{}]{}}}"#,
|
|
self.variant,
|
|
cards_json(&short(self.hero)),
|
|
board_json(&short(self.board)),
|
|
self.street,
|
|
self.pot,
|
|
self.to_call,
|
|
(self.to_call * 2.0).max(1.0),
|
|
self.legal,
|
|
villains.join(","),
|
|
self.extra,
|
|
)
|
|
}
|
|
}
|
|
|
|
fn base() -> Request<'static> {
|
|
Request {
|
|
variant: "NLHE",
|
|
hero: "Ah Kd",
|
|
board: "Ks 7c 2d",
|
|
street: "FLOP",
|
|
pot: 10.0,
|
|
to_call: 0.0,
|
|
legal: r#"["CHECK","RAISE"]"#,
|
|
villains: 1,
|
|
extra: "",
|
|
}
|
|
}
|
|
|
|
fn reason(out: &str) -> String {
|
|
field(out, "reason").unwrap_or("").to_string()
|
|
}
|
|
|
|
// ---------- Short deck ----------
|
|
|
|
#[test]
|
|
fn short_deck_and_its_alias_are_accepted() {
|
|
for name in ["SHORT_DECK", "6+"] {
|
|
let out = respond(&Request { variant: name, hero: "Ah Ad", board: "As 9c 7d", ..base() }.line());
|
|
assert_ne!(action(&out), "ABSTAIN", "{name}: {out}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn short_deck_rejects_cards_below_six() {
|
|
let out = respond(&Request { variant: "SHORT_DECK", hero: "5h 5d", board: "As 9c 7d", ..base() }.line());
|
|
assert_eq!(action(&out), "ABSTAIN", "{out}");
|
|
assert_eq!(confidence(&out), 0.0);
|
|
}
|
|
|
|
#[test]
|
|
fn short_deck_flush_is_played_as_a_monster_over_a_full_house_draw() {
|
|
// Hero holds the made flush; in short deck a flush beats a full house, so a
|
|
// villain's set that fills up is still behind — the flush must bet.
|
|
let out = respond(
|
|
&Request { variant: "SHORT_DECK", hero: "Ah 9h", board: "Kh 8h 6h 8c", street: "TURN", ..base() }
|
|
.line(),
|
|
);
|
|
assert_eq!(action(&out), "RAISE", "{out}");
|
|
}
|
|
|
|
#[test]
|
|
fn short_deck_respects_allowed_sizes() {
|
|
let out = respond(
|
|
&Request {
|
|
variant: "SHORT_DECK",
|
|
hero: "Ah Ad",
|
|
board: "As 9c 7d",
|
|
extra: r#","allowedSizes":[3.5,7.25]"#,
|
|
..base()
|
|
}
|
|
.line(),
|
|
);
|
|
if action(&out) == "RAISE" {
|
|
let s = size(&out).unwrap();
|
|
assert!(s == 3.5 || s == 7.25, "{out}");
|
|
}
|
|
}
|
|
|
|
// ---------- Action history ----------
|
|
|
|
#[test]
|
|
fn malformed_history_abstains_with_its_path() {
|
|
let out = respond(
|
|
&Request { extra: r#","history":[{"street":"FLOP","seat":1,"action":"DANCE"}]"#, ..base() }.line(),
|
|
);
|
|
assert_eq!(action(&out), "ABSTAIN", "{out}");
|
|
assert!(reason(&out).contains("history[0]"), "{out}");
|
|
}
|
|
|
|
#[test]
|
|
fn preflop_raiser_betting_flop_and_turn_narrows_range_so_middle_pair_gives_up() {
|
|
// Hero 9-9 on K-7-2-4 facing a turn bet from a player who raised preflop and bet both streets.
|
|
let history = r#","history":[{"street":"PREFLOP","seat":1,"action":"RAISE","amount":3},{"street":"PREFLOP","seat":6,"action":"CALL","amount":3},{"street":"FLOP","seat":1,"action":"BET","amount":5},{"street":"FLOP","seat":6,"action":"CALL","amount":5},{"street":"TURN","seat":1,"action":"BET","amount":14}]"#;
|
|
let narrowed = respond(
|
|
&Request {
|
|
hero: "9h 9c",
|
|
board: "Ks 7c 2d 4h",
|
|
street: "TURN",
|
|
pot: 30.0,
|
|
to_call: 14.0,
|
|
legal: r#"["FOLD","CALL","RAISE"]"#,
|
|
extra: history,
|
|
..base()
|
|
}
|
|
.line(),
|
|
);
|
|
assert!(["FOLD", "ABSTAIN"].contains(&action(&narrowed).as_str()), "{narrowed}");
|
|
}
|
|
|
|
#[test]
|
|
fn position_is_derived_from_history_when_button_is_missing() {
|
|
let line = format!(
|
|
r#"{{"variant":"NLHE","bigBlind":1,"seats":6,"heroSeat":4,"heroCards":{},"street":"PREFLOP","pot":1.5,"toCall":1,"heroStack":100,"minRaiseTo":2,"maxRaiseTo":100,"legalActions":["FOLD","CALL","RAISE"],"villains":[{{"seat":2,"stack":100,"folded":false}},{{"seat":3,"stack":100,"folded":false}}],"history":[{{"street":"PREFLOP","seat":2,"action":"POST_SB","amount":0.5}},{{"street":"PREFLOP","seat":3,"action":"POST_BB","amount":1}}]}}"#,
|
|
cards_json(&short("Ah Kh"))
|
|
);
|
|
let out = respond(&line);
|
|
assert!(!reason(&out).contains("pos?"), "{out}");
|
|
}
|
|
|
|
// ---------- Multiway and semibluff ----------
|
|
|
|
#[test]
|
|
fn top_pair_continues_heads_up_but_folds_four_way() {
|
|
let spot = |villains| Request {
|
|
hero: "Qh Jd",
|
|
board: "Qs 8c 3d",
|
|
pot: 12.0,
|
|
to_call: 6.0,
|
|
legal: r#"["FOLD","CALL","RAISE"]"#,
|
|
villains,
|
|
..base()
|
|
};
|
|
let heads_up = respond(&spot(1).line());
|
|
let four_way = respond(&spot(4).line());
|
|
// Heads-up top pair continues (call or value raise); four-way the same price is a fold.
|
|
assert!(["CALL", "RAISE"].contains(&action(&heads_up).as_str()), "{heads_up}");
|
|
assert!(["FOLD", "ABSTAIN"].contains(&action(&four_way).as_str()), "{four_way}");
|
|
}
|
|
|
|
#[test]
|
|
fn reasons_name_the_hand_read() {
|
|
let out = respond(&base().line());
|
|
let text = reason(&out).to_lowercase();
|
|
assert!(text.contains("top pair"), "{out}");
|
|
}
|
|
|
|
#[test]
|
|
fn no_semibluff_on_the_river() {
|
|
let river = Request {
|
|
hero: "Jh Th",
|
|
board: "9h 8h 2c 3d Ks",
|
|
street: "RIVER",
|
|
legal: r#"["CHECK","RAISE"]"#,
|
|
..base()
|
|
}
|
|
.line();
|
|
// A missed draw has no cards to come: it is never a semibluff. Against an unknown
|
|
// opponent it may still be a pure bluff (pipeline_bluff), against a station it checks.
|
|
let unknown = respond(&river);
|
|
assert!(!reason(&unknown).contains("semibluff"), "{unknown}");
|
|
assert!(action(&unknown) == "CHECK" || reason(&unknown).contains("bluff raise"), "{unknown}");
|
|
let station = respond(&river.replace(
|
|
r#""folded":false}"#,
|
|
r#""folded":false,"profile":{"vpip":0.55,"pfr":0.05,"foldToBet":0.15}}"#,
|
|
));
|
|
assert_eq!(action(&station), "CHECK", "missed draw on the river: {station}");
|
|
}
|
|
|
|
#[test]
|
|
fn uncertain_abstain_carries_small_but_positive_confidence() {
|
|
// Scan pot sizes around the breakpoint; any uncertainty ABSTAIN must have 0 < c <= 0.3.
|
|
(1..40).for_each(|i| {
|
|
let to_call = i as f64 * 0.5;
|
|
let out = respond(
|
|
&Request {
|
|
hero: "Ad 5c",
|
|
board: "Ks 9c 4h",
|
|
pot: 10.0,
|
|
to_call,
|
|
legal: r#"["FOLD","CALL"]"#,
|
|
..base()
|
|
}
|
|
.line(),
|
|
);
|
|
if action(&out) == "ABSTAIN" && reason(&out).contains("uncertain") {
|
|
let c = confidence(&out);
|
|
assert!(c > 0.0 && c <= 0.3, "{out}");
|
|
}
|
|
});
|
|
}
|