//! Enforces the example-com strength ladder: Fire beats Random, decisively and //! across both colors. The strategies are shared with the `arena` / `fire_com` //! examples via the same module, so this test guards the very com that ships. //! //! The contract is "the stronger com always beats the weaker one": the stronger //! com must *never lose* a game, and must win the overwhelming majority (the //! rest being the occasional draw). Colors alternate game-to-game so neither //! first-move advantage nor a single lucky seed can carry the result. #[path = "../examples/strategy/mod.rs"] mod strategy; use strategy::{run_series, Series, Strategy}; const GAMES: u32 = 40; const BOARD_SIZE: i32 = 5; /// The stronger com must never lose, and win at least this fraction of games. const MIN_WIN_FRAC: f64 = 0.85; fn assert_dominates(strong: Strategy, weak: Strategy) { let s: Series = run_series(strong, weak, GAMES, BOARD_SIZE); let win_frac = s.a_wins as f64 / s.games() as f64; assert_eq!( s.b_wins, 0, "{} lost {} game(s) to {} (won {}, drew {}); ladder requires the stronger com never loses", strong.name(), s.b_wins, weak.name(), s.a_wins, s.draws, ); assert!( win_frac >= MIN_WIN_FRAC, "{} only won {:.0}% vs {} ({} win / {} draw / {} loss); expected >= {:.0}%", strong.name(), 100.0 * win_frac, weak.name(), s.a_wins, s.draws, s.b_wins, 100.0 * MIN_WIN_FRAC, ); } #[test] fn fire_beats_random() { assert_dominates(Strategy::Fire, Strategy::Random); }