2022-10-31 13:25:32 +00:00
|
|
|
use chs::chess::perft::run_perft;
|
2022-10-31 13:31:34 +00:00
|
|
|
use chs::constants::*;
|
2022-10-31 13:25:32 +00:00
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct TestRunner {
|
|
|
|
passed: usize,
|
|
|
|
failed: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TestRunner {
|
|
|
|
fn run_test<F: Fn() -> bool>(&mut self, f: F) {
|
|
|
|
let result = f();
|
|
|
|
if result {
|
|
|
|
self.passed += 1;
|
|
|
|
} else {
|
|
|
|
self.failed += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn summarise(&self) {
|
2022-10-31 13:31:34 +00:00
|
|
|
println!(
|
|
|
|
"Ran {total} tests: {passed} passed, {failed} failed",
|
|
|
|
total = self.passed + self.failed,
|
|
|
|
passed = self.passed,
|
|
|
|
failed = self.failed
|
|
|
|
);
|
2022-10-31 13:25:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut runner = TestRunner::default();
|
2022-10-31 13:31:34 +00:00
|
|
|
let mut perft = |fen: &str, depth: u64, expected_positions: u64| {
|
|
|
|
runner.run_test(|| run_perft(fen, depth, expected_positions))
|
|
|
|
};
|
2022-10-31 13:25:32 +00:00
|
|
|
|
|
|
|
// Start position
|
|
|
|
println!("Start position");
|
|
|
|
perft(START_FEN, 0, 1);
|
|
|
|
perft(START_FEN, 1, 20);
|
|
|
|
perft(START_FEN, 2, 400);
|
|
|
|
perft(START_FEN, 3, 8_902);
|
|
|
|
perft(START_FEN, 4, 197_281);
|
|
|
|
|
|
|
|
// Other test positions (https://www.chessprogramming.org/Perft_Results)
|
|
|
|
|
|
|
|
// Position 2
|
|
|
|
println!("Position 2");
|
|
|
|
perft(POSITION_2, 1, 48);
|
|
|
|
perft(POSITION_2, 2, 2_039);
|
|
|
|
perft(POSITION_2, 3, 97_862);
|
|
|
|
perft(POSITION_2, 4, 4_085_603);
|
|
|
|
|
|
|
|
// Position 3
|
|
|
|
println!("Position 3");
|
|
|
|
perft(POSITION_3, 1, 14);
|
|
|
|
perft(POSITION_3, 2, 191);
|
|
|
|
perft(POSITION_3, 3, 2_812);
|
|
|
|
perft(POSITION_3, 4, 43_238);
|
|
|
|
perft(POSITION_3, 5, 674_624);
|
|
|
|
perft(POSITION_3, 6, 11_030_083);
|
|
|
|
|
|
|
|
// Position 4
|
|
|
|
println!("Position 4");
|
|
|
|
perft(POSITION_4, 1, 6);
|
|
|
|
perft(POSITION_4, 2, 264);
|
|
|
|
perft(POSITION_4, 3, 9_467);
|
|
|
|
perft(POSITION_4, 4, 422_333);
|
|
|
|
perft(POSITION_4, 5, 15_833_292);
|
|
|
|
|
|
|
|
// Position 5
|
|
|
|
println!("Position 5");
|
|
|
|
perft(POSITION_5, 1, 44);
|
|
|
|
perft(POSITION_5, 2, 1_486);
|
|
|
|
perft(POSITION_5, 3, 62_379);
|
|
|
|
perft(POSITION_5, 4, 2_103_487);
|
|
|
|
|
|
|
|
// Position 6
|
|
|
|
println!("Position 6");
|
|
|
|
perft(POSITION_6, 1, 46);
|
|
|
|
perft(POSITION_6, 2, 2_079);
|
|
|
|
perft(POSITION_6, 3, 89_890);
|
|
|
|
perft(POSITION_6, 4, 3_894_594);
|
|
|
|
|
|
|
|
runner.summarise();
|
|
|
|
}
|