Files
pokerfreak/src/engine/river3_spieler/tests.rs
T

121 lines
4.3 KiB
Rust

use super::*;
use crate::game::{ActionKind, ActionRecord, Choice, SeenAction, Spot, Street, Villain};
use crate::variant::Variant;
use crate::engine::SCHALTER_LOCK as LOCK;
fn rec(street: Street, seat: u8, action: SeenAction, amount: Option<f64>) -> ActionRecord {
ActionRecord { street, seat, action, amount }
}
/// Six-max, three-way to the river: button (hero, seat 4) opens 2.5, small blind (5) and big blind
/// (0) call; flop SB check, BB check, BTN bets 3.75, both call; turn checked through; river SB check,
/// BB bets 10, hero to act. Pot before the river 18.75.
fn three_way(hero: &str) -> Spot {
use SeenAction::*;
use Street::*;
let history = vec![
rec(Preflop, 5, PostSmallBlind, Some(0.5)),
rec(Preflop, 0, PostBigBlind, Some(1.0)),
rec(Preflop, 1, Fold, None),
rec(Preflop, 2, Fold, None),
rec(Preflop, 3, Fold, None),
rec(Preflop, 4, Raise, Some(2.5)),
rec(Preflop, 5, Call, Some(2.5)),
rec(Preflop, 0, Call, Some(2.5)),
rec(Flop, 5, Check, None),
rec(Flop, 0, Check, None),
rec(Flop, 4, Bet, Some(3.75)),
rec(Flop, 5, Call, Some(3.75)),
rec(Flop, 0, Call, Some(3.75)),
rec(Turn, 5, Check, None),
rec(Turn, 0, Check, None),
rec(Turn, 4, Check, None),
rec(River, 5, Check, None),
rec(River, 0, Bet, Some(10.0)),
];
Spot {
variant: Variant::Nlhe,
big_blind: 1.0,
seats: 6,
hero_seat: 4,
button_seat: None,
hero_cards: Card::parse_list(hero).unwrap(),
board: Card::parse_list("Ah 7d 2c Ks 3h").unwrap(),
street: Street::River,
pot: 28.75,
to_call: 10.0,
hero_stack: 93.75,
min_raise_to: Some(20.0),
max_raise_to: Some(93.75),
legal: vec![ActionKind::Fold, ActionKind::Call, ActionKind::Raise],
allowed_sizes: None,
villains: vec![
Villain { seat: 5, stack: 93.75, folded: false, profile: None },
Villain { seat: 0, stack: 83.75, folded: false, profile: None },
],
seed: 5,
history,
}
}
#[test]
fn acting_order_starts_at_the_small_blind() {
let _fest = crate::engine::frist::fest_hier();
assert_eq!(acting_order(&three_way("Qc Jc")), Some(vec![5, 0, 4]));
}
#[test]
fn off_decides_nothing_and_heads_up_is_not_in_the_slice() {
let _fest = crate::engine::frist::fest_hier();
let _g = LOCK.lock().unwrap();
set_river3(false);
assert!(river3_decision(&three_way("As Ad")).is_none());
set_river3(true);
let mut hu = three_way("As Ad");
hu.villains.pop();
assert!(river3_decision(&hu).is_none());
set_river3(false);
}
#[test]
fn on_decides_three_way_rivers_legally() {
let _g = LOCK.lock().unwrap();
let _fest = crate::engine::frist::fest_hier();
set_river3(true);
for hero in ["As Ad", "6s 5d", "Kc Qc"] {
let d = river3_decision(&three_way(hero)).expect("3-way river is in the slice");
assert!(d.reason.contains("river3 solver (3 players)"), "{}", d.reason);
assert!(matches!(d.choice, Choice::Fold | Choice::Call | Choice::Raise { .. }), "{:?}", d.choice);
}
set_river3(false);
}
/// The deadline (CPU time of the thread since 19.11.): the hook answers in time. On a busy machine it may answer with
/// fewer iterations or hand back to the heuristic (`None`), but it never runs over.
#[test]
fn on_answers_three_way_rivers_in_time() {
let _g = LOCK.lock().unwrap();
set_river3(true);
for hero in ["As Ad", "6s 5d", "Kc Qc"] {
let t = crate::engine::frist::thread_cpu_ms();
let d = river3_decision(&three_way(hero));
let cpu = (crate::engine::frist::thread_cpu_ms() - t) / 1e3;
assert!(cpu < 2.0, "{cpu} s CPU");
if let Some(d) = d {
assert!(d.reason.contains("river3 solver (3 players)"), "{}", d.reason);
}
}
set_river3(false);
}
#[test]
fn top_set_continues_and_air_folds_three_way() {
let _fest = crate::engine::frist::fest_hier();
let s = solve_river3(&three_way("As Ad")).unwrap();
let fold = |s: &Solved3| s.row.iter().zip(&s.acts).filter(|(_, a)| **a == Act::Fold).map(|(p, _)| p).sum::<f64>();
assert!(fold(&s) < 0.05, "{:?} {:?}", s.row, s.acts);
let s = solve_river3(&three_way("6s 5d")).unwrap();
assert!(fold(&s) > 0.7, "{:?} {:?}", s.row, s.acts);
}