103 lines
3.6 KiB
Rust
103 lines
3.6 KiB
Rust
use super::*;
|
|
use crate::game::{ActionKind, ActionRecord, Choice, SeenAction, Spot, Street, Villain};
|
|
use crate::variant::Variant;
|
|
use std::sync::Mutex;
|
|
|
|
static LOCK: Mutex<()> = Mutex::new(());
|
|
|
|
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() {
|
|
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 _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_and_in_time() {
|
|
let _g = LOCK.lock().unwrap();
|
|
set_river3(true);
|
|
for hero in ["As Ad", "6s 5d", "Kc Qc"] {
|
|
let spot = three_way(hero);
|
|
let t = std::time::Instant::now();
|
|
let d = river3_decision(&spot).expect("3-way river is in the slice");
|
|
assert!(t.elapsed().as_secs_f64() < 2.0);
|
|
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);
|
|
}
|
|
|
|
#[test]
|
|
fn top_set_continues_and_air_folds_three_way() {
|
|
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);
|
|
}
|