Die Welt nannte 'pokerfreak' nur noch in zwei Harness-Zeilen - der Rest waren veraltete Rust-Pruefungen im Pruefordner, die der Aufbau nie auffrischte.
173 lines
8.1 KiB
Rust
173 lines
8.1 KiB
Rust
//! The generator reproduces the frozen tables; the recorded convergence iteration is real.
|
|
//!
|
|
//! Full reproduction (same seed, same iteration count => identical permille tables and
|
|
//! metadata) is checked for a few representative spots, because every spot costs thousands of
|
|
//! full-width CFR iterations. For the remaining spots the claim "the argmax chart is final from
|
|
//! `stable_since` on" is checked by re-running only to that iteration, on a seeded sample of
|
|
//! spots (`SAMPLE`). Three-player open spots cost minutes each at test optimisation, so the
|
|
//! sampled `stable_since` check covers the push/fold spots of both decks and the open spots of
|
|
//! the small blind (two players); the three-player open solver is the same generic `solve` and
|
|
//! is covered through the three-player push/fold spots and the Nash test.
|
|
use rechner::cfr::chart_deck::ChartDeck;
|
|
use rechner::cfr::chart_signature::signature;
|
|
use rechner::cfr::environment::Environment;
|
|
use rechner::cfr::frozen_spot::PushFoldSpot;
|
|
use rechner::cfr::frozen_strategy::{open_strategy, push_fold3_strategy, push_fold_strategy};
|
|
use rechner::cfr::open_game::open_tree;
|
|
use rechner::cfr::push_fold3_game::push_fold3_tree;
|
|
use rechner::cfr::push_fold_game::push_fold_tree;
|
|
use rechner::cfr::render_charts::render_charts;
|
|
use rechner::cfr::run_plan::{open_iterations, push_fold_iterations, CFR_SEED};
|
|
use rechner::cfr::seat::Seat;
|
|
use rechner::cfr::solve::solve;
|
|
use rechner::cfr::spot_solver::{solve_open_spot, solve_push_fold_spot};
|
|
use rechner::preflop::generated_charts::{AOF_PUSH_FOLD, OPEN, PUSH_FOLD};
|
|
use rechner::preflop::generated_charts_short as short;
|
|
use rechner::rng::Rng;
|
|
use rechner::variant::{rules, Variant};
|
|
|
|
/// How many spots of each kind are re-run up to `stable_since`.
|
|
const SAMPLE: u64 = 3;
|
|
|
|
#[test]
|
|
fn iteration_counts_in_the_tables_are_the_plan() {
|
|
for push in [&PUSH_FOLD[..], &short::PUSH_FOLD[..]] {
|
|
assert!(push.iter().all(|s| s.meta.iterations == push_fold_iterations(s.seat)));
|
|
}
|
|
for open in [&OPEN[..], &short::OPEN[..]] {
|
|
assert!(open.iter().all(|s| s.meta.iterations == open_iterations(s.seat)));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_push_fold_spot_is_reproduced_bit_for_bit() {
|
|
// One three-player spot (button against both blinds) and one two-player spot.
|
|
let env = Environment::frozen();
|
|
for (seat, depth) in [(Seat::Button, 10u8), (Seat::SmallBlind, 5)] {
|
|
let frozen = PUSH_FOLD.iter().find(|s| s.seat == seat && s.depth_bb == depth).expect("spot");
|
|
let again = solve_push_fold_spot(&env, seat, depth).expect("spot");
|
|
assert_eq!(&again, frozen, "{} {depth}bb", seat.label());
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_short_deck_push_fold_spot_is_reproduced_bit_for_bit() {
|
|
let env = Environment::frozen_for(ChartDeck::Short);
|
|
let frozen = short::PUSH_FOLD.iter().find(|s| s.seat == Seat::Early && s.depth_bb == 15).expect("spot");
|
|
assert_eq!(&solve_push_fold_spot(&env, Seat::Early, 15).expect("spot"), frozen);
|
|
}
|
|
|
|
#[test]
|
|
fn an_open_spot_is_reproduced_bit_for_bit() {
|
|
let env = Environment::frozen();
|
|
let frozen = OPEN.iter().find(|s| s.seat == Seat::SmallBlind && s.depth_bb == 40).expect("spot");
|
|
let again = solve_open_spot(&env, Seat::SmallBlind, 40).expect("spot");
|
|
assert_eq!(&again, frozen);
|
|
}
|
|
|
|
#[test]
|
|
fn the_all_in_or_fold_rules_generate_the_same_push_fold_tables() {
|
|
// Generic over rules: the AOF rule set (binary action shape) yields the identical spot.
|
|
let nlhe = Environment::frozen();
|
|
let aof = Environment::new(&rules(Variant::Aof), rechner::cfr::frozen_equity::frozen_equity())
|
|
.expect("environment");
|
|
let aof = Environment { rake: nlhe.rake, antes: nlhe.antes, ..aof };
|
|
let a = solve_push_fold_spot(&aof, Seat::Middle, 12).expect("spot");
|
|
let b = solve_push_fold_spot(&nlhe, Seat::Middle, 12).expect("spot");
|
|
assert_eq!(a, b);
|
|
assert_eq!(&a, AOF_PUSH_FOLD.iter().find(|s| s.seat == Seat::Middle && s.depth_bb == 12).expect("spot"));
|
|
}
|
|
|
|
fn sample_indices(len: usize, count: u64, seed: u64) -> Vec<usize> {
|
|
let (picks, _) = (0..count).fold((Vec::new(), Rng::seeded(seed)), |(mut picks, rng), _| {
|
|
let (k, rng) = rng.below(len as u64);
|
|
picks.push(k as usize);
|
|
(picks, rng)
|
|
});
|
|
picks
|
|
}
|
|
|
|
fn push_fold_is_final_from_stable_since(env: &Environment, spot: &PushFoldSpot) {
|
|
let label = format!("{} {}bb", spot.seat.label(), spot.depth_bb);
|
|
if spot.seat == Seat::SmallBlind {
|
|
let tree = push_fold_tree(env, spot.seat, spot.depth_bb as f64).expect("tree");
|
|
let frozen = signature(&push_fold_strategy(&tree, spot).expect("strategy"));
|
|
let early = solve(&tree, spot.meta.stable_since, Rng::seeded(CFR_SEED));
|
|
assert_eq!(signature(&early.strategy), frozen, "{label}");
|
|
} else {
|
|
let tree = push_fold3_tree(env, spot.seat, spot.depth_bb as f64).expect("tree");
|
|
let frozen = signature(&push_fold3_strategy(&tree, spot).expect("strategy"));
|
|
let early = solve(&tree, spot.meta.stable_since, Rng::seeded(CFR_SEED));
|
|
assert_eq!(signature(&early.strategy), frozen, "{label}");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn the_argmax_chart_is_final_from_the_recorded_iteration_on_sampled_push_fold_spots() {
|
|
let env = Environment::frozen();
|
|
for k in sample_indices(PUSH_FOLD.len(), SAMPLE, 3) {
|
|
push_fold_is_final_from_stable_since(&env, &PUSH_FOLD[k]);
|
|
}
|
|
let env = Environment::frozen_for(ChartDeck::Short);
|
|
for k in sample_indices(short::PUSH_FOLD.len(), SAMPLE, 4) {
|
|
push_fold_is_final_from_stable_since(&env, &short::PUSH_FOLD[k]);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn the_argmax_chart_is_final_from_the_recorded_iteration_on_the_small_blind_open_spots() {
|
|
let decks = [(Environment::frozen(), &OPEN[..]), (Environment::frozen_for(ChartDeck::Short), &short::OPEN[..])];
|
|
for (env, open) in decks {
|
|
for spot in open.iter().filter(|s| s.seat == Seat::SmallBlind) {
|
|
let tree = open_tree(&env, spot.seat, spot.depth_bb as f64).expect("tree");
|
|
let frozen = signature(&open_strategy(&tree, spot).expect("strategy"));
|
|
let early = solve(&tree, spot.meta.stable_since, Rng::seeded(CFR_SEED));
|
|
assert_eq!(signature(&early.strategy), frozen, "{} {}bb", spot.seat.label(), spot.depth_bb);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn rendering_is_pure_and_describes_every_spot() {
|
|
let text = render_charts(ChartDeck::Full, &PUSH_FOLD[..2], &OPEN[..1]);
|
|
assert_eq!(text, render_charts(ChartDeck::Full, &PUSH_FOLD[..2], &OPEN[..1]));
|
|
assert!(text.contains("PushFoldSpot {"));
|
|
assert!(text.contains("OpenSpot {"));
|
|
assert!(text.contains("cargo run --release --bin chartgen"));
|
|
assert!(text.contains(&format!("{}", PUSH_FOLD[0].meta.iterations)));
|
|
}
|
|
|
|
fn unix(text: &str) -> String {
|
|
text.replace("\r\n", "\n")
|
|
}
|
|
|
|
#[test]
|
|
fn the_frozen_chart_file_is_exactly_what_the_generator_prints() {
|
|
// `chartgen charts` renders its spots with `render_charts`; rendering the frozen spots back
|
|
// must give the committed file, byte for byte (header, convergence table and data).
|
|
let committed = unix(include_str!("../src/preflop/generated_charts.rs"));
|
|
assert!(committed == render_charts(ChartDeck::Full, &PUSH_FOLD, &OPEN), "generated_charts.rs differs from the renderer output");
|
|
let committed = unix(include_str!("../src/preflop/generated_charts_short.rs"));
|
|
assert!(
|
|
committed == render_charts(ChartDeck::Short, &short::PUSH_FOLD, &short::OPEN),
|
|
"generated_charts_short.rs differs from the renderer output"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn the_frozen_equity_file_is_exactly_what_the_generator_prints() {
|
|
use rechner::cfr::generated_equity as frozen;
|
|
use rechner::cfr::render_equity::render_equity;
|
|
let committed = unix(include_str!("../src/cfr/generated_equity.rs"));
|
|
assert!(
|
|
committed == render_equity(rechner::cfr::chart_deck::ChartDeck::Full, frozen::SEED, frozen::SAMPLES, &frozen::TRIANGLE),
|
|
"generated_equity.rs differs from the renderer output"
|
|
);
|
|
use rechner::cfr::generated_equity_short as short_equity;
|
|
let committed = unix(include_str!("../src/cfr/generated_equity_short.rs"));
|
|
assert!(
|
|
committed == render_equity(ChartDeck::Short, short_equity::SEED, short_equity::SAMPLES, &short_equity::TRIANGLE),
|
|
"generated_equity_short.rs differs from the renderer output"
|
|
);
|
|
}
|