Files
pokerfreak/tests/pipeline_bluff.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

147 lines
6.6 KiB
Rust

//! End-to-end spec for bluffing and bluff catching, steered by opponent frequencies.
mod support;
use rechner::wire::respond::respond;
use support::{action, board_json, cards_json, field, short};
const NIT: &str = r#","profile":{"vpip":0.11,"pfr":0.08,"foldToBet":0.8,"aggression":0.15}"#;
const STATION: &str = r#","profile":{"vpip":0.55,"pfr":0.05,"foldToBet":0.15,"aggression":0.2}"#;
const MANIAC: &str = r#","profile":{"vpip":0.55,"pfr":0.35,"foldToBet":0.35,"aggression":0.8}"#;
const NEVER_FOLDS: &str = r#","profile":{"foldToBet":0.05}"#;
fn reason(out: &str) -> String {
field(out, "reason").unwrap_or("").to_string()
}
/// Heads-up river, checked to hero (button, seat 6) by the villain in seat 1.
fn river_checked_to_hero(hero: &str, board: &str, profile: &str) -> String {
format!(
r#"{{"variant":"NLHE","bigBlind":1,"seats":6,"heroSeat":6,"buttonSeat":6,"heroCards":{},"board":{},"street":"RIVER","pot":20,"toCall":0,"heroStack":100,"minRaiseTo":1,"maxRaiseTo":100,"legalActions":["CHECK","RAISE"],"villains":[{{"seat":1,"stack":100,"folded":false{profile}}}]}}"#,
cards_json(&short(hero)),
board_json(&short(board)),
)
}
/// Hero (button) raised preflop, the small blind called, checked down to the river,
/// where the small blind bets the pot (6 into 6).
fn river_facing_a_pot_bet(hero: &str, board: &str, profile: &str) -> String {
let history = r#"[{"street":"PREFLOP","seat":1,"action":"POST_SB","amount":0.5},{"street":"PREFLOP","seat":2,"action":"POST_BB","amount":1},{"street":"PREFLOP","seat":6,"action":"RAISE","amount":2.5},{"street":"PREFLOP","seat":1,"action":"CALL","amount":2.5},{"street":"PREFLOP","seat":2,"action":"FOLD"},{"street":"FLOP","seat":1,"action":"CHECK"},{"street":"FLOP","seat":6,"action":"CHECK"},{"street":"TURN","seat":1,"action":"CHECK"},{"street":"TURN","seat":6,"action":"CHECK"},{"street":"RIVER","seat":1,"action":"BET","amount":6}]"#;
format!(
r#"{{"variant":"NLHE","bigBlind":1,"seats":6,"heroSeat":6,"buttonSeat":6,"heroCards":{},"board":{},"street":"RIVER","pot":12,"toCall":6,"heroStack":97.5,"minRaiseTo":12,"maxRaiseTo":97.5,"legalActions":["FOLD","CALL","RAISE"],"villains":[{{"seat":1,"stack":91.5,"folded":false{profile}}},{{"seat":2,"stack":99,"folded":true}}],"history":{history}}}"#,
cards_json(&short(hero)),
board_json(&short(board)),
)
}
/// Unopened pot, hero on the button, both blinds with the same profile.
fn steal(hero: &str, profile: &str) -> String {
format!(
r#"{{"variant":"NLHE","bigBlind":1,"seats":6,"heroSeat":6,"buttonSeat":6,"heroCards":{},"street":"PREFLOP","pot":1.5,"toCall":1,"heroStack":100,"minRaiseTo":2,"maxRaiseTo":100,"legalActions":["FOLD","CALL","RAISE"],"villains":[{{"seat":1,"stack":100,"folded":false{profile}}},{{"seat":2,"stack":100,"folded":false{profile}}}]}}"#,
cards_json(&short(hero)),
)
}
/// Air on the river: no pair, no made straight or flush.
const AIR: [(&str, &str); 6] = [
("6h 5h", "As Kd 9c 7s 2d"),
("Qc Jc", "As 8d 5h 3s 2c"),
("Th 9h", "Ac Kd 6s 4c 2d"),
("7d 6d", "Kc Qs Jh 3c 2s"),
("Jd Td", "As 8c 6h 4d 3s"),
("8s 7s", "Ad Qc Th 4h 2c"),
];
fn bluffs(profile: &str) -> usize {
AIR.iter()
.filter(|(hero, board)| action(&respond(&river_checked_to_hero(hero, board, profile))) == "RAISE")
.count()
}
// ---------- Bluffing ----------
#[test]
fn the_nit_gets_bluffed_with_air() {
let out = respond(&river_checked_to_hero("6h 5h", "As Kd 9c 7s 2d", NIT));
assert_eq!(action(&out), "RAISE", "{out}");
assert!(reason(&out).contains("bluff"), "{out}");
}
#[test]
fn the_calling_station_does_not() {
let out = respond(&river_checked_to_hero("6h 5h", "As Kd 9c 7s 2d", STATION));
assert_eq!(action(&out), "CHECK", "{out}");
}
#[test]
fn fewer_bluffs_against_the_station_more_against_the_nit() {
let (nit, unknown, station) = (bluffs(NIT), bluffs(""), bluffs(STATION));
assert!(nit > unknown || nit == AIR.len(), "nit {nit}, unknown {unknown}");
assert!(unknown >= station, "unknown {unknown}, station {station}");
assert_eq!(station, 0);
assert_eq!(nit, AIR.len());
}
#[test]
fn never_bluff_someone_who_never_folds() {
assert_eq!(bluffs(NEVER_FOLDS), 0);
}
// ---------- Stealing ----------
#[test]
fn steal_wider_against_nits_in_the_blinds() {
// The button opens the CFR range (about the top 36 % against both blinds). Against two
// nits the steal widens past it, against two calling stations it shrinks.
let hero = "Kd 4c"; // just outside the range: folded in equilibrium
assert!(["FOLD", "ABSTAIN"].contains(&action(&respond(&steal(hero, ""))).as_str()));
let nit = respond(&steal(hero, NIT));
assert_eq!(action(&nit), "RAISE", "{nit}");
assert!(reason(&nit).contains("exploit"), "{nit}");
assert_eq!(action(&respond(&steal(hero, STATION))), "FOLD");
// K7o is an equilibrium open, no longer stolen against stations.
assert_eq!(action(&respond(&steal("Kd 7c", ""))), "RAISE");
assert_eq!(action(&respond(&steal("Kd 7c", STATION))), "FOLD");
}
// ---------- Bluff catching ----------
#[test]
fn a_bluff_catcher_calls_the_maniac() {
let out = respond(&river_facing_a_pot_bet("Qh 9h", "Ks 9d 4c 2s 7h", MANIAC));
assert_eq!(action(&out), "CALL", "{out}");
}
#[test]
fn the_same_bluff_catcher_folds_to_the_nit() {
let out = respond(&river_facing_a_pot_bet("Qh 9h", "Ks 9d 4c 2s 7h", NIT));
assert!(["FOLD", "ABSTAIN"].contains(&action(&out).as_str()), "{out}");
}
#[test]
fn no_bluff_catch_against_a_range_without_bluffs() {
let honest = r#","profile":{"vpip":0.25,"pfr":0.18,"foldToBet":0.5,"aggression":0.0}"#;
let out = respond(&river_facing_a_pot_bet("Qh 9h", "Ks 9d 4c 2s 7h", honest));
assert!(["FOLD", "ABSTAIN"].contains(&action(&out).as_str()), "{out}");
}
#[test]
fn a_value_hand_still_calls_or_raises_the_nit() {
let out = respond(&river_facing_a_pot_bet("Kh Kc", "Ks 9d 4c 2s 7h", NIT));
assert!(["CALL", "RAISE"].contains(&action(&out).as_str()), "{out}");
}
// ---------- Semibluffs first ----------
#[test]
fn draws_raise_as_semibluffs_not_as_pure_bluffs() {
let line = format!(
r#"{{"variant":"NLHE","bigBlind":1,"seats":6,"heroSeat":6,"buttonSeat":6,"heroCards":{},"board":{},"street":"FLOP","pot":10,"toCall":0,"heroStack":100,"minRaiseTo":1,"maxRaiseTo":100,"legalActions":["CHECK","RAISE"],"villains":[{{"seat":1,"stack":100,"folded":false{NIT}}}]}}"#,
cards_json(&short("8h 7h")),
board_json(&short("Kh 4h 2c")),
);
let out = respond(&line);
assert_eq!(action(&out), "RAISE", "{out}");
assert!(reason(&out).contains("semibluff"), "{out}");
}