For a move that could be brilliant or great and was the engine's best, an optional shallow search (same fixed search, go nodes SHALLOW_NODES = 5000) keeps its best move and evaluation and the move played at that depth (PosEval.shallow, serde default; SEARCH_VERSION unchanged). Ply.difficulty says how much the shallow search underrates the move (Measure::Choice: against its own best move; Measure::Depth: against the deep search). Hardness (report.rs) says how the difficulty counts in !! and ! of the ChessCom rules: ! only for hard moves, gaps, the capture/quiet-retreat bans, !! for a very hard only move. The default changes nothing and makes no shallow search; rules that use it fill old analyses in like the second search (seconds_missing). chesscom_check takes CP_SHALLOW_NODES and the rule parameters for experiments; review_bench CP_SHALLOW_NODES. fake_uci learns --searchmoves and --shallow for the job test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
2.9 KiB
Rust
73 lines
2.9 KiB
Rust
//! Time of the fixed game analysis of one game, and a check that it is the same at any
|
|
//! number of engine processes: prints the time and a digest of every evaluation.
|
|
//!
|
|
//! `cargo run --release -p game-review --example review_bench -- <engine> <pgn> <processes>...`
|
|
//!
|
|
//! `CP_SHALLOW_NODES=S` adds the shallow searches of S nodes (for how hard a move was to
|
|
//! find, `game_review::Hardness`), as rules that use them would.
|
|
|
|
use std::sync::atomic::AtomicBool;
|
|
use std::time::Instant;
|
|
|
|
use game_review::{GameAnalysis, Hardness, JobSettings};
|
|
|
|
fn main() {
|
|
let args: Vec<String> = std::env::args().collect();
|
|
if args.len() < 4 {
|
|
eprintln!("usage: review_bench <engine> <pgn> <processes>...");
|
|
std::process::exit(2);
|
|
}
|
|
let text = std::fs::read_to_string(&args[2]).expect("pgn");
|
|
let game = chess_core::parse_str(&text).game;
|
|
let shallow: Option<u64> = std::env::var("CP_SHALLOW_NODES")
|
|
.ok()
|
|
.map(|n| n.parse().expect("CP_SHALLOW_NODES: a number"));
|
|
let mut digests = Vec::new();
|
|
for p in &args[3..] {
|
|
let processes: usize = p.parse().expect("processes");
|
|
let mut a = GameAnalysis::new(&game, None);
|
|
if let Some(nodes) = shallow {
|
|
a.set_shallow_nodes(nodes);
|
|
a.set_hardness(Hardness {
|
|
brilliant: Some(100.0),
|
|
..Hardness::default()
|
|
});
|
|
}
|
|
let targets = a.begin(&game, true);
|
|
let positions = targets.len();
|
|
let (mut searches, mut shallows) = (0, 0);
|
|
let started = Instant::now();
|
|
game_review::run(
|
|
uci::EngineConfig::new(&args[1]),
|
|
&JobSettings::new(processes, None),
|
|
targets,
|
|
&AtomicBool::new(false),
|
|
&mut |e| {
|
|
if let game_review::JobEvent::Eval { eval, .. } = &e {
|
|
searches += 1 + usize::from(eval.second.is_some());
|
|
if let Some(s) = &eval.shallow {
|
|
shallows += 1 + usize::from(s.best != s.played);
|
|
}
|
|
}
|
|
a.apply(e);
|
|
},
|
|
)
|
|
.expect("engine");
|
|
let secs = started.elapsed().as_secs_f64();
|
|
// Every evaluation, line and second search, in the order of the game.
|
|
let all: Vec<_> = (0..a.line().len()).map(|i| a.eval_at(i).cloned()).collect();
|
|
let bytes = serde_json::to_vec(&all).expect("json");
|
|
let digest = bytes.iter().fold(0xcbf2_9ce4_8422_2325_u64, |h, b| {
|
|
(h ^ u64::from(*b)).wrapping_mul(0x0100_0000_01b3)
|
|
});
|
|
println!(
|
|
"processes {processes:>2}: {positions} positions, {searches} searches \
|
|
(+{shallows} shallow), {secs:.1} s, evaluations {digest:016x}"
|
|
);
|
|
digests.push(digest);
|
|
}
|
|
if digests.windows(2).any(|w| w[0] != w[1]) {
|
|
println!("DIFFERENT evaluations");
|
|
std::process::exit(1);
|
|
}
|
|
}
|