SOLVER3_FOHNE, SOLVER3_TOHNE, SOLVER3_FSPERRE (aus, live bitgleich); drei.py DREI_FENSTER; drei_kipp.py Mischarme. Pflicht 39/44, Latenz max 1215 ms, Faustregel 97->78. Bericht messung/solver_kern/STUFE4B.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
189 lines
7.1 KiB
Rust
189 lines
7.1 KiB
Rust
use super::*;
|
|
use crate::card::Card;
|
|
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: button (hero, seat 4) opens 2.5, SB (5) and BB (0) call (pot 7.5). On the flop
|
|
/// SB checks, BB bets 3.75, hero to act. On the turn (flop bet called by all, pot 18.75) SB checks, BB
|
|
/// bets 6, hero to act.
|
|
fn three_way(street: Street, hero: &str) -> Spot {
|
|
use SeenAction::*;
|
|
use Street::*;
|
|
let mut 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, Bet, Some(3.75)),
|
|
];
|
|
let (board, pot, to_call, stack) = if street == Flop {
|
|
("Ah 7d 2c", 11.25, 3.75, 97.5)
|
|
} else {
|
|
history.extend([rec(Flop, 4, Call, Some(3.75)), rec(Flop, 5, Call, Some(3.75)), rec(Turn, 5, Check, None), rec(Turn, 0, Bet, Some(6.0))]);
|
|
("Ah 7d 2c Ks", 24.75, 6.0, 93.75)
|
|
};
|
|
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(board).unwrap(),
|
|
street,
|
|
pot,
|
|
to_call,
|
|
hero_stack: stack,
|
|
min_raise_to: Some(2.0 * to_call),
|
|
max_raise_to: Some(stack),
|
|
legal: vec![ActionKind::Fold, ActionKind::Call, ActionKind::Raise],
|
|
allowed_sizes: None,
|
|
villains: vec![
|
|
Villain { seat: 5, stack, folded: false, profile: None },
|
|
Villain { seat: 0, stack: stack - to_call, folded: false, profile: None },
|
|
],
|
|
seed: 9,
|
|
history,
|
|
}
|
|
}
|
|
|
|
fn fold(s: &SolvedM) -> f64 {
|
|
s.row.iter().zip(&s.acts).filter(|(_, a)| **a == Act::Fold).map(|(p, _)| p).sum()
|
|
}
|
|
|
|
#[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_turn3(false);
|
|
set_flop3(false);
|
|
assert!(multi3_decision(&three_way(Street::Turn, "As Ad")).is_none());
|
|
assert!(multi3_decision(&three_way(Street::Flop, "As Ad")).is_none());
|
|
set_turn3(true);
|
|
set_flop3(true);
|
|
let mut hu = three_way(Street::Turn, "As Ad");
|
|
hu.villains.pop();
|
|
assert!(multi3_decision(&hu).is_none());
|
|
set_turn3(false);
|
|
set_flop3(false);
|
|
}
|
|
|
|
#[test]
|
|
fn on_decides_three_way_turns_and_flops_legally() {
|
|
let _g = LOCK.lock().unwrap();
|
|
let _fest = crate::engine::frist::fest_hier();
|
|
set_turn3(true);
|
|
set_flop3(true);
|
|
for (street, tag) in [(Street::Turn, "solver turn3 (3 players)"), (Street::Flop, "solver flop3 (3 players)")] {
|
|
for hero in ["As Ad", "6s 5d", "Kc Qc"] {
|
|
let d = multi3_decision(&three_way(street, hero)).expect("3-way spot is in the slice");
|
|
assert!(d.reason.contains(tag), "{}", d.reason);
|
|
assert!(matches!(d.choice, Choice::Fold | Choice::Call | Choice::Raise { .. }), "{:?}", d.choice);
|
|
}
|
|
}
|
|
set_turn3(false);
|
|
set_flop3(false);
|
|
}
|
|
|
|
/// The deadline (CPU time of the thread since 19.11.): the hook answers in time.(on a busy machine possibly with `None`,
|
|
/// the heuristic decides), never over.
|
|
#[test]
|
|
fn on_answers_three_way_turns_and_flops_in_time() {
|
|
let _g = LOCK.lock().unwrap();
|
|
set_turn3(true);
|
|
set_flop3(true);
|
|
for (street, limit, tag) in [(Street::Turn, 1.25, "solver turn3 (3 players)"), (Street::Flop, 2.0, "solver flop3 (3 players)")] {
|
|
for hero in ["As Ad", "6s 5d", "Kc Qc"] {
|
|
// Seit 19.11. zählt die Frist Rechenzeit des Threads (Warten auf einen Kern zählt nicht).
|
|
let t = crate::engine::frist::thread_cpu_ms();
|
|
let d = multi3_decision(&three_way(street, hero));
|
|
let cpu = (crate::engine::frist::thread_cpu_ms() - t) / 1e3;
|
|
assert!(cpu < limit, "{street:?} {cpu} s CPU");
|
|
if let Some(d) = d {
|
|
assert!(d.reason.contains(tag), "{}", d.reason);
|
|
}
|
|
}
|
|
}
|
|
set_turn3(false);
|
|
set_flop3(false);
|
|
}
|
|
|
|
#[test]
|
|
fn top_set_continues_and_air_folds_three_way() {
|
|
let _fest = crate::engine::frist::fest_hier();
|
|
for street in [Street::Turn, Street::Flop] {
|
|
let s = solve_multi3(&three_way(street, "As Ad")).unwrap();
|
|
assert!(fold(&s) < 0.05, "{street:?} {:?} {:?}", s.row, s.acts);
|
|
}
|
|
let s = solve_multi3(&three_way(Street::Turn, "6s 5d")).unwrap();
|
|
assert!(fold(&s) > 0.6, "{:?} {:?}", s.row, s.acts);
|
|
}
|
|
|
|
/// Stage 4: `offen` leaves spots with a bet to call to the heuristic, `SOLVER3_OHNE` the named classes;
|
|
/// with both at 0 the gate passes every spot.
|
|
#[test]
|
|
fn lage_limits_open_spots_and_classes() {
|
|
let _g = LOCK.lock().unwrap();
|
|
assert_eq!(ohne_bits("nichts"), Some(1));
|
|
assert_eq!(ohne_bits("nichts/zug"), Some(0b11));
|
|
assert_eq!(ohne_bits(""), Some(0));
|
|
assert_eq!(ohne_bits("luft"), None);
|
|
let facing = three_way(Street::Turn, "As Ad");
|
|
assert!(facing.to_call > 0.0);
|
|
let mut open = facing.clone();
|
|
open.to_call = 0.0;
|
|
set_lage(0, 0);
|
|
assert!(lage_passt(&facing) && lage_passt(&open));
|
|
set_lage(0b010, 0);
|
|
assert!(!lage_passt(&facing) && lage_passt(&open));
|
|
set_lage(0b001, 0);
|
|
assert!(lage_passt(&facing));
|
|
let air = three_way(Street::Turn, "6s 5d");
|
|
let k = crate::sim::poolruf::klasse(&air.hero_cards, &air.board);
|
|
set_lage(0, 1 << k);
|
|
assert!(!lage_passt(&air));
|
|
// River-only classes leave the turn alone.
|
|
set_lage(0, 0);
|
|
set_river_ohne(1 << k);
|
|
assert!(lage_passt(&air));
|
|
set_river_ohne(0);
|
|
assert!(crate::sim::poolruf::klasse(&facing.hero_cards, &facing.board) == k || lage_passt(&facing));
|
|
set_lage(0, 0);
|
|
}
|
|
|
|
/// Owner order 19.11.: per-street class exclusions on flop/turn and the flop fold lock (top pair or better,
|
|
/// bet at most the pot). All off by default.
|
|
#[test]
|
|
fn strassen_ohne_und_flop_sperre() {
|
|
let flop = three_way(Street::Flop, "Ac Kd"); // top pair, 3.75 into 7.5
|
|
let k = crate::sim::poolruf::klasse(&flop.hero_cards, &flop.board);
|
|
assert_eq!(k, 3);
|
|
assert!(lage_passt(&flop));
|
|
set_strassen_ohne(1 << k, 0);
|
|
assert!(!lage_passt(&flop));
|
|
set_strassen_ohne(0, 1 << k);
|
|
assert!(lage_passt(&flop), "turn classes leave the flop alone");
|
|
set_strassen_ohne(0, 0);
|
|
assert!(!fsperre_greift(&flop), "lock off by default");
|
|
set_fsperre(true);
|
|
assert!(fsperre_greift(&flop));
|
|
let mut gross = flop.clone();
|
|
gross.to_call = 9.0;
|
|
gross.pot = 16.5; // 9 into 7.5: over the pot
|
|
assert!(!fsperre_greift(&gross));
|
|
assert!(!fsperre_greift(&three_way(Street::Flop, "6s 5d")), "air is not locked");
|
|
assert!(!fsperre_greift(&three_way(Street::Turn, "Ac Kd")), "flop only");
|
|
set_fsperre(false);
|
|
}
|