Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
//! Opening errors found by the engine: every distinct position of the first plies of
|
|
|
|
|
|
//! the player's games is evaluated once (the games repeat their openings, so about
|
|
|
|
|
|
//! half the positions are shared), and the player's moves are judged from the
|
|
|
|
|
|
//! evaluations before and after them with the rules of the game analysis. The same
|
|
|
|
|
|
//! error in several games — the same position and the same move — is what matters
|
|
|
|
|
|
//! most for preparation, so those are listed on their own.
|
|
|
|
|
|
//!
|
|
|
|
|
|
//! Evaluations are kept per position in a cache file shared by every report: another
|
|
|
|
|
|
//! player of the same database, or the same player later, is judged from the cache.
|
|
|
|
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
|
|
|
|
|
|
|
use chess_core::shakmaty::san::SanPlus;
|
|
|
|
|
|
use chess_core::shakmaty::uci::UciMove;
|
2026-11-06 00:26:01 +03:00
|
|
|
|
use chess_core::shakmaty::{Chess, Position};
|
Review: one fixed engine search everywhere, in parallel engine processes
Every position of a game analysis (and of the opening errors) is searched by
ChessPenguin's Stockfish 19 to 1M nodes with one thread, a 32 MB hash and
ucinewgame before each search, so the evaluations depend on the position
alone: the same marks on every computer and phone, whatever the number of
engine processes (one per CPU, at most 8 on a computer and 4 on a phone, and
what the free memory holds) or the order of the positions.
- ReviewMeta.search: analyses of another search are stale; shown, but
Update makes them all again. The prep caches drop such evaluations.
- Desktop: no launch dialog (engine, quality, threads, memory are gone);
Analyse starts at once, its tooltip gives the time; the prep dialog keeps
the colour. Without the own Stockfish the download is offered.
- settings.review and prep.quality removed; old settings files still read.
- fake_uci --hash-memory; tests of determinism on processes and order.
- chesscom_check in the fixed search (CP_REVIEW_NODES for experiments);
review_bench example for times and determinism on a real engine.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 19:19:44 +03:00
|
|
|
|
use game_review::{Eval, Judgement, PosEval, SEARCH_VERSION};
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::games::{GameInfo, Tally};
|
|
|
|
|
|
|
|
|
|
|
|
/// Nodes of an evaluation that needs no engine (checkmate, stalemate): better than any
|
|
|
|
|
|
/// search.
|
|
|
|
|
|
pub const EXACT: u64 = u64::MAX;
|
|
|
|
|
|
|
|
|
|
|
|
/// The engine's result for one position.
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
|
|
pub struct PositionEval {
|
|
|
|
|
|
/// Nodes of the search ([`EXACT`] for a position without legal moves).
|
|
|
|
|
|
pub nodes: u64,
|
|
|
|
|
|
pub eval: Eval,
|
|
|
|
|
|
/// The engine's line in UCI; the first move is its best move.
|
|
|
|
|
|
pub pv: Vec<String>,
|
|
|
|
|
|
pub depth: u32,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl PositionEval {
|
|
|
|
|
|
pub fn from_engine(nodes: u64, e: &PosEval) -> PositionEval {
|
|
|
|
|
|
PositionEval {
|
|
|
|
|
|
nodes,
|
|
|
|
|
|
eval: e.eval,
|
|
|
|
|
|
pv: e.pv.iter().take(8).cloned().collect(),
|
|
|
|
|
|
depth: e.depth,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn best(&self) -> Option<&str> {
|
|
|
|
|
|
self.pv.first().map(String::as_str)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// How many inaccuracies, mistakes and blunders.
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
|
|
|
|
pub struct ErrorCounts {
|
|
|
|
|
|
pub inaccuracies: u32,
|
|
|
|
|
|
pub mistakes: u32,
|
|
|
|
|
|
pub blunders: u32,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl ErrorCounts {
|
|
|
|
|
|
pub fn add(&mut self, j: Judgement) {
|
|
|
|
|
|
match j {
|
|
|
|
|
|
Judgement::Inaccuracy => self.inaccuracies += 1,
|
|
|
|
|
|
Judgement::Mistake => self.mistakes += 1,
|
|
|
|
|
|
Judgement::Blunder => self.blunders += 1,
|
|
|
|
|
|
Judgement::Great | Judgement::Brilliant => {}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn total(&self) -> u32 {
|
|
|
|
|
|
self.inaccuracies + self.mistakes + self.blunders
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A move of the player judged an inaccuracy, a mistake or a blunder.
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
|
|
pub struct OpeningError {
|
|
|
|
|
|
/// Index into [`crate::PrepReport::games`].
|
|
|
|
|
|
pub game: u32,
|
|
|
|
|
|
/// The move's place in the line (0-based; see [`GameInfo::move_label`]).
|
|
|
|
|
|
pub ply: u32,
|
|
|
|
|
|
/// The position before the move.
|
|
|
|
|
|
pub key: u64,
|
|
|
|
|
|
pub uci: String,
|
|
|
|
|
|
pub san: String,
|
|
|
|
|
|
/// The engine's move instead.
|
|
|
|
|
|
pub best_uci: String,
|
|
|
|
|
|
pub best_san: String,
|
|
|
|
|
|
pub judgement: Judgement,
|
|
|
|
|
|
pub before: Eval,
|
|
|
|
|
|
pub after: Eval,
|
|
|
|
|
|
/// The game's opening ([`crate::PrepReport::openings`]).
|
|
|
|
|
|
pub opening: Option<usize>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The same error in several games: the same position and the same move.
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
|
|
pub struct RepeatedError {
|
|
|
|
|
|
pub key: u64,
|
|
|
|
|
|
pub ply: u32,
|
|
|
|
|
|
pub uci: String,
|
|
|
|
|
|
pub san: String,
|
|
|
|
|
|
pub best_san: String,
|
|
|
|
|
|
pub judgement: Judgement,
|
|
|
|
|
|
/// The games (indices into [`crate::PrepReport::games`]), in order.
|
|
|
|
|
|
pub games: Vec<u32>,
|
|
|
|
|
|
/// How those games ended.
|
|
|
|
|
|
pub tally: Tally,
|
|
|
|
|
|
/// The opening of the first of them.
|
|
|
|
|
|
pub opening: Option<usize>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl RepeatedError {
|
|
|
|
|
|
pub fn times(&self) -> u32 {
|
|
|
|
|
|
self.games.len() as u32
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Judges the player's moves in `games[g]` for `g` in `which` from `evals`: the
|
|
|
|
|
|
/// move is not the engine's best, and the evaluations before and after it say it
|
2026-11-06 00:26:01 +03:00
|
|
|
|
/// lost enough (the rules of the game analysis, [`game_review::judge`]). Only the
|
|
|
|
|
|
/// prefix before the opponent's first inaccuracy/mistake/blunder is eligible.
|
|
|
|
|
|
/// A missing opponent evaluation or best move stops the prefix too: later player
|
|
|
|
|
|
/// errors are not published until those preceding moves have been checked.
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
pub fn judge_games(
|
|
|
|
|
|
games: &[GameInfo],
|
|
|
|
|
|
which: &[u32],
|
|
|
|
|
|
evals: &HashMap<u64, PositionEval>,
|
|
|
|
|
|
) -> Vec<OpeningError> {
|
|
|
|
|
|
let mut out = Vec::new();
|
|
|
|
|
|
for &g in which {
|
|
|
|
|
|
let game = &games[g as usize];
|
|
|
|
|
|
let mut pos = Chess::default();
|
|
|
|
|
|
for (i, uci) in game.ucis.iter().enumerate() {
|
2026-10-28 20:37:06 +03:00
|
|
|
|
let Some(m) = uci
|
|
|
|
|
|
.parse::<UciMove>()
|
|
|
|
|
|
.ok()
|
|
|
|
|
|
.and_then(|u| u.to_move(&pos).ok())
|
|
|
|
|
|
else {
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
break;
|
|
|
|
|
|
};
|
2026-11-06 00:26:01 +03:00
|
|
|
|
let evaluated = evals
|
|
|
|
|
|
.get(&game.keys[i])
|
|
|
|
|
|
.and_then(|before| Some((before, evals.get(&game.keys[i + 1])?, before.best()?)));
|
|
|
|
|
|
if !game.player_moves_at(i) && evaluated.is_none() {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some((before, after, best)) = evaluated
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
&& best != uci
|
2026-11-06 00:26:01 +03:00
|
|
|
|
&& let Some(judgement) = game_review::judge(before.eval, after.eval, pos.turn())
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
{
|
2026-11-06 00:26:01 +03:00
|
|
|
|
if !game.player_moves_at(i) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
let best_san = best
|
|
|
|
|
|
.parse::<UciMove>()
|
|
|
|
|
|
.ok()
|
|
|
|
|
|
.and_then(|u| u.to_move(&pos).ok())
|
|
|
|
|
|
.map(|bm| SanPlus::from_move(pos.clone(), bm).to_string())
|
|
|
|
|
|
.unwrap_or_else(|| best.to_owned());
|
|
|
|
|
|
out.push(OpeningError {
|
|
|
|
|
|
game: g,
|
|
|
|
|
|
ply: i as u32,
|
|
|
|
|
|
key: game.keys[i],
|
|
|
|
|
|
uci: uci.clone(),
|
|
|
|
|
|
san: game.sans.get(i).cloned().unwrap_or_default(),
|
|
|
|
|
|
best_uci: best.to_owned(),
|
|
|
|
|
|
best_san,
|
|
|
|
|
|
judgement,
|
|
|
|
|
|
before: before.eval,
|
|
|
|
|
|
after: after.eval,
|
|
|
|
|
|
opening: game.opening,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
pos.play_unchecked(m);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The errors made in two or more games (same position, same move), most repeated
|
|
|
|
|
|
/// first, then the worst first.
|
|
|
|
|
|
pub fn repeated(errors: &[OpeningError], games: &[GameInfo]) -> Vec<RepeatedError> {
|
|
|
|
|
|
let mut groups: HashMap<(u64, &str), Vec<&OpeningError>> = HashMap::new();
|
|
|
|
|
|
for e in errors {
|
|
|
|
|
|
groups.entry((e.key, e.uci.as_str())).or_default().push(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut out: Vec<RepeatedError> = groups
|
|
|
|
|
|
.into_values()
|
|
|
|
|
|
.filter(|g| g.len() >= 2)
|
|
|
|
|
|
.map(|g| {
|
|
|
|
|
|
let first = g[0];
|
|
|
|
|
|
let mut tally = Tally::default();
|
|
|
|
|
|
let mut list: Vec<u32> = g.iter().map(|e| e.game).collect();
|
|
|
|
|
|
list.sort_unstable();
|
|
|
|
|
|
list.dedup();
|
|
|
|
|
|
for &game in &list {
|
|
|
|
|
|
tally.add(games[game as usize].outcome);
|
|
|
|
|
|
}
|
|
|
|
|
|
RepeatedError {
|
|
|
|
|
|
key: first.key,
|
|
|
|
|
|
ply: first.ply,
|
|
|
|
|
|
uci: first.uci.clone(),
|
|
|
|
|
|
san: first.san.clone(),
|
|
|
|
|
|
best_san: first.best_san.clone(),
|
|
|
|
|
|
judgement: first.judgement,
|
|
|
|
|
|
games: list,
|
|
|
|
|
|
tally,
|
|
|
|
|
|
opening: first.opening,
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.filter(|r| r.games.len() >= 2)
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
out.sort_by(|a, b| {
|
|
|
|
|
|
b.games
|
|
|
|
|
|
.len()
|
|
|
|
|
|
.cmp(&a.games.len())
|
|
|
|
|
|
.then(b.judgement.cmp(&a.judgement))
|
|
|
|
|
|
.then(a.ply.cmp(&b.ply))
|
|
|
|
|
|
.then(a.games.cmp(&b.games))
|
|
|
|
|
|
});
|
|
|
|
|
|
out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----- the cache of evaluations by position --------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
const CACHE_FILE: &str = "positions.json";
|
|
|
|
|
|
const CACHE_VERSION: u32 = 1;
|
|
|
|
|
|
/// Positions kept at most (about 100 bytes each on disk).
|
|
|
|
|
|
const CACHE_LIMIT: usize = 1_000_000;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
|
|
struct CacheFile {
|
|
|
|
|
|
version: u32,
|
Review: one fixed engine search everywhere, in parallel engine processes
Every position of a game analysis (and of the opening errors) is searched by
ChessPenguin's Stockfish 19 to 1M nodes with one thread, a 32 MB hash and
ucinewgame before each search, so the evaluations depend on the position
alone: the same marks on every computer and phone, whatever the number of
engine processes (one per CPU, at most 8 on a computer and 4 on a phone, and
what the free memory holds) or the order of the positions.
- ReviewMeta.search: analyses of another search are stale; shown, but
Update makes them all again. The prep caches drop such evaluations.
- Desktop: no launch dialog (engine, quality, threads, memory are gone);
Analyse starts at once, its tooltip gives the time; the prep dialog keeps
the colour. Without the own Stockfish the download is offered.
- settings.review and prep.quality removed; old settings files still read.
- fake_uci --hash-memory; tests of determinism on processes and order.
- chesscom_check in the fixed search (CP_REVIEW_NODES for experiments);
review_bench example for times and determinism on a real engine.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 19:19:44 +03:00
|
|
|
|
/// The version of the fixed search the evaluations come from ([`SEARCH_VERSION`];
|
|
|
|
|
|
/// 0: from before it). Those of another one are not used.
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
search: u32,
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
positions: Vec<(u64, PositionEval)>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Engine evaluations by position, shared by every report: the best quality (most
|
|
|
|
|
|
/// nodes) seen for each position is kept.
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
|
pub struct PositionCache {
|
|
|
|
|
|
entries: HashMap<u64, PositionEval>,
|
|
|
|
|
|
dirty: bool,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl PositionCache {
|
|
|
|
|
|
fn path(dir: &Path) -> PathBuf {
|
|
|
|
|
|
dir.join(CACHE_FILE)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The cache in `dir` (empty when there is none, or it cannot be read).
|
|
|
|
|
|
pub fn load(dir: &Path) -> PositionCache {
|
|
|
|
|
|
let entries = std::fs::read(Self::path(dir))
|
|
|
|
|
|
.ok()
|
|
|
|
|
|
.and_then(|bytes| serde_json::from_slice::<CacheFile>(&bytes).ok())
|
Review: one fixed engine search everywhere, in parallel engine processes
Every position of a game analysis (and of the opening errors) is searched by
ChessPenguin's Stockfish 19 to 1M nodes with one thread, a 32 MB hash and
ucinewgame before each search, so the evaluations depend on the position
alone: the same marks on every computer and phone, whatever the number of
engine processes (one per CPU, at most 8 on a computer and 4 on a phone, and
what the free memory holds) or the order of the positions.
- ReviewMeta.search: analyses of another search are stale; shown, but
Update makes them all again. The prep caches drop such evaluations.
- Desktop: no launch dialog (engine, quality, threads, memory are gone);
Analyse starts at once, its tooltip gives the time; the prep dialog keeps
the colour. Without the own Stockfish the download is offered.
- settings.review and prep.quality removed; old settings files still read.
- fake_uci --hash-memory; tests of determinism on processes and order.
- chesscom_check in the fixed search (CP_REVIEW_NODES for experiments);
review_bench example for times and determinism on a real engine.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 19:19:44 +03:00
|
|
|
|
.filter(|f| f.version == CACHE_VERSION && f.search == SEARCH_VERSION)
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
.map(|f| f.positions.into_iter().collect())
|
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
|
PositionCache {
|
|
|
|
|
|
entries,
|
|
|
|
|
|
dirty: false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn len(&self) -> usize {
|
|
|
|
|
|
self.entries.len()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
|
|
self.entries.is_empty()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get(&self, key: u64) -> Option<&PositionEval> {
|
|
|
|
|
|
self.entries.get(&key)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Keeps `eval` unless the cache has one with more nodes; says whether it was kept.
|
|
|
|
|
|
pub fn insert(&mut self, key: u64, eval: PositionEval) -> bool {
|
2026-10-28 20:37:06 +03:00
|
|
|
|
if self
|
|
|
|
|
|
.entries
|
|
|
|
|
|
.get(&key)
|
|
|
|
|
|
.is_some_and(|e| e.nodes >= eval.nodes)
|
|
|
|
|
|
{
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.entries.insert(key, eval);
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Something was added since the load or the last save.
|
|
|
|
|
|
pub fn dirty(&self) -> bool {
|
|
|
|
|
|
self.dirty
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Writes the cache to `dir` (through a temporary file, so a crash never leaves
|
|
|
|
|
|
/// half a file); nothing when nothing changed.
|
|
|
|
|
|
pub fn save(&mut self, dir: &Path) -> std::io::Result<()> {
|
|
|
|
|
|
if !self.dirty {
|
|
|
|
|
|
return Ok(());
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut positions: Vec<(u64, PositionEval)> =
|
|
|
|
|
|
self.entries.iter().map(|(k, v)| (*k, v.clone())).collect();
|
|
|
|
|
|
if positions.len() > CACHE_LIMIT {
|
|
|
|
|
|
// Over the limit the searches with the fewest nodes go first.
|
|
|
|
|
|
positions.sort_by_key(|a| std::cmp::Reverse(a.1.nodes));
|
|
|
|
|
|
positions.truncate(CACHE_LIMIT);
|
|
|
|
|
|
}
|
|
|
|
|
|
let file = CacheFile {
|
|
|
|
|
|
version: CACHE_VERSION,
|
Review: one fixed engine search everywhere, in parallel engine processes
Every position of a game analysis (and of the opening errors) is searched by
ChessPenguin's Stockfish 19 to 1M nodes with one thread, a 32 MB hash and
ucinewgame before each search, so the evaluations depend on the position
alone: the same marks on every computer and phone, whatever the number of
engine processes (one per CPU, at most 8 on a computer and 4 on a phone, and
what the free memory holds) or the order of the positions.
- ReviewMeta.search: analyses of another search are stale; shown, but
Update makes them all again. The prep caches drop such evaluations.
- Desktop: no launch dialog (engine, quality, threads, memory are gone);
Analyse starts at once, its tooltip gives the time; the prep dialog keeps
the colour. Without the own Stockfish the download is offered.
- settings.review and prep.quality removed; old settings files still read.
- fake_uci --hash-memory; tests of determinism on processes and order.
- chesscom_check in the fixed search (CP_REVIEW_NODES for experiments);
review_bench example for times and determinism on a real engine.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 19:19:44 +03:00
|
|
|
|
search: SEARCH_VERSION,
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
positions,
|
|
|
|
|
|
};
|
|
|
|
|
|
let bytes = serde_json::to_vec(&file).map_err(std::io::Error::other)?;
|
|
|
|
|
|
write_atomic(&Self::path(dir), &bytes)?;
|
|
|
|
|
|
self.dirty = false;
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Writes through a temporary file and a rename.
|
|
|
|
|
|
pub(crate) fn write_atomic(path: &Path, bytes: &[u8]) -> std::io::Result<()> {
|
|
|
|
|
|
if let Some(dir) = path.parent() {
|
|
|
|
|
|
std::fs::create_dir_all(dir)?;
|
|
|
|
|
|
}
|
|
|
|
|
|
let tmp = path.with_extension("json.tmp");
|
|
|
|
|
|
std::fs::write(&tmp, bytes)?;
|
|
|
|
|
|
std::fs::rename(&tmp, path)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod tests {
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
use crate::tree::tests::game;
|
|
|
|
|
|
|
|
|
|
|
|
fn eval(nodes: u64, cp: i32, best: &str) -> PositionEval {
|
|
|
|
|
|
PositionEval {
|
|
|
|
|
|
nodes,
|
|
|
|
|
|
eval: Eval::Cp(cp),
|
|
|
|
|
|
pv: vec![best.to_owned()],
|
|
|
|
|
|
depth: 10,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn the_same_error_in_two_games_is_repeated() {
|
|
|
|
|
|
// Three games of the player with White: 1.e4 e5 2.Qh5?! twice, 2.Nf3 once.
|
|
|
|
|
|
let games = vec![
|
|
|
|
|
|
game(0, true, &["e4", "e5", "Qh5", "Nc6"], "1-0", "", 0),
|
|
|
|
|
|
game(1, true, &["e4", "e5", "Qh5", "Nf6"], "0-1", "", 0),
|
|
|
|
|
|
game(2, true, &["e4", "e5", "Nf3", "Nc6"], "1/2-1/2", "", 0),
|
|
|
|
|
|
game(3, false, &["e4", "e5", "Qh5", "Nc6"], "0-1", "", 0),
|
|
|
|
|
|
];
|
|
|
|
|
|
let mut evals = HashMap::new();
|
|
|
|
|
|
evals.insert(games[0].keys[0], eval(1000, 30, "e2e4"));
|
|
|
|
|
|
evals.insert(games[0].keys[1], eval(1000, 30, "e7e5"));
|
|
|
|
|
|
// 2.Qh5 drops from +0.3 to −1.0: a mistake; 2.Nf3 is the engine's move.
|
|
|
|
|
|
evals.insert(games[0].keys[2], eval(1000, 30, "g1f3"));
|
|
|
|
|
|
evals.insert(games[0].keys[3], eval(1000, -100, "b8c6"));
|
|
|
|
|
|
evals.insert(games[1].keys[3], eval(1000, -100, "g8f6"));
|
|
|
|
|
|
evals.insert(games[2].keys[3], eval(1000, 30, "b8c6"));
|
|
|
|
|
|
let errors = judge_games(&games, &[0, 1, 2], &evals);
|
|
|
|
|
|
assert_eq!(errors.len(), 2);
|
|
|
|
|
|
assert_eq!(errors[0].game, 0);
|
|
|
|
|
|
assert_eq!(errors[0].ply, 2);
|
|
|
|
|
|
assert_eq!(errors[0].san, "Qh5");
|
|
|
|
|
|
assert_eq!(errors[0].best_san, "Nf3");
|
|
|
|
|
|
assert_eq!(errors[0].judgement, Judgement::Mistake);
|
|
|
|
|
|
assert_eq!(errors[1].game, 1);
|
|
|
|
|
|
let rep = repeated(&errors, &games);
|
|
|
|
|
|
assert_eq!(rep.len(), 1);
|
|
|
|
|
|
assert_eq!(rep[0].games, vec![0, 1]);
|
|
|
|
|
|
assert_eq!(rep[0].times(), 2);
|
|
|
|
|
|
assert_eq!((rep[0].tally.wins, rep[0].tally.losses), (1, 1));
|
|
|
|
|
|
// Black's moves in game 3 are the player's: 2.Qh5 is the opponent's there.
|
|
|
|
|
|
let evals_black = evals.clone();
|
|
|
|
|
|
assert!(judge_games(&games, &[3], &evals_black).is_empty());
|
|
|
|
|
|
// A position without an evaluation after the move is not judged (the two
|
|
|
|
|
|
// games share the position after 2.Qh5).
|
|
|
|
|
|
let mut partial = evals.clone();
|
|
|
|
|
|
partial.remove(&games[1].keys[3]);
|
|
|
|
|
|
assert!(judge_games(&games, &[0, 1, 2], &partial).is_empty());
|
|
|
|
|
|
// One game less: nothing repeats.
|
|
|
|
|
|
assert!(repeated(&judge_games(&games, &[0, 2], &evals), &games).is_empty());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-06 00:26:01 +03:00
|
|
|
|
fn line_evals(game: &GameInfo, values: &[i32]) -> HashMap<u64, PositionEval> {
|
|
|
|
|
|
game.keys
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.enumerate()
|
|
|
|
|
|
.map(|(ply, &key)| {
|
|
|
|
|
|
(
|
|
|
|
|
|
key,
|
|
|
|
|
|
eval(
|
|
|
|
|
|
1000,
|
|
|
|
|
|
values[ply],
|
|
|
|
|
|
game.ucis.get(ply).map_or("", String::as_str),
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn every_opponent_error_category_stops_later_errors_for_both_colours() {
|
|
|
|
|
|
for white in [true, false] {
|
|
|
|
|
|
for (loss, category) in [
|
|
|
|
|
|
(60, Judgement::Inaccuracy),
|
|
|
|
|
|
(150, Judgement::Mistake),
|
|
|
|
|
|
(500, Judgement::Blunder),
|
|
|
|
|
|
] {
|
|
|
|
|
|
let game = game(0, white, &["e4", "e5", "Qh5", "Nc6"], "*", "", 0);
|
|
|
|
|
|
let (opponent_ply, player_ply, values) = if white {
|
|
|
|
|
|
(1, 2, vec![0, 0, loss, -150, -150])
|
|
|
|
|
|
} else {
|
|
|
|
|
|
(0, 1, vec![0, -loss, 150, 150, 150])
|
|
|
|
|
|
};
|
|
|
|
|
|
let mut evals = line_evals(&game, &values);
|
|
|
|
|
|
evals.get_mut(&game.keys[opponent_ply]).unwrap().pv =
|
|
|
|
|
|
vec![if white { "c7c5" } else { "d2d4" }.to_owned()];
|
|
|
|
|
|
evals.get_mut(&game.keys[player_ply]).unwrap().pv =
|
|
|
|
|
|
vec![if white { "g1f3" } else { "c7c5" }.to_owned()];
|
|
|
|
|
|
let mover = if white {
|
|
|
|
|
|
chess_core::shakmaty::Color::Black
|
|
|
|
|
|
} else {
|
|
|
|
|
|
chess_core::shakmaty::Color::White
|
|
|
|
|
|
};
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
|
game_review::judge(
|
|
|
|
|
|
Eval::Cp(values[opponent_ply]),
|
|
|
|
|
|
Eval::Cp(values[opponent_ply + 1]),
|
|
|
|
|
|
mover
|
|
|
|
|
|
),
|
|
|
|
|
|
Some(category)
|
|
|
|
|
|
);
|
|
|
|
|
|
assert!(judge_games(std::slice::from_ref(&game), &[0], &evals).is_empty());
|
|
|
|
|
|
// The engine's own best move is exempt even if evaluations differ.
|
|
|
|
|
|
evals.get_mut(&game.keys[opponent_ply]).unwrap().pv =
|
|
|
|
|
|
vec![game.ucis[opponent_ply].clone()];
|
|
|
|
|
|
let errors = judge_games(std::slice::from_ref(&game), &[0], &evals);
|
|
|
|
|
|
assert_eq!(errors.len(), 1);
|
|
|
|
|
|
assert_eq!(errors[0].ply, player_ply as u32);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn earlier_player_errors_survive_but_the_whole_later_suffix_is_excluded() {
|
|
|
|
|
|
for white in [true, false] {
|
|
|
|
|
|
let game = game(
|
|
|
|
|
|
0,
|
|
|
|
|
|
white,
|
|
|
|
|
|
&["e4", "e5", "Qh5", "Nc6", "Bc4", "Nf6"],
|
|
|
|
|
|
"*",
|
|
|
|
|
|
"",
|
|
|
|
|
|
0,
|
|
|
|
|
|
);
|
|
|
|
|
|
let values = if white {
|
|
|
|
|
|
vec![0, -150, 0, -150, -150, -300, -300]
|
|
|
|
|
|
} else {
|
|
|
|
|
|
vec![0, 0, 150, 0, 150, 0, 150]
|
|
|
|
|
|
};
|
|
|
|
|
|
let mut evals = line_evals(&game, &values);
|
|
|
|
|
|
let first_player = usize::from(!white);
|
|
|
|
|
|
let opponent = first_player + 1;
|
|
|
|
|
|
let alternatives = if white {
|
|
|
|
|
|
["d2d4", "c7c5", "g1f3", "d2d3"]
|
|
|
|
|
|
} else {
|
|
|
|
|
|
["c7c5", "g1f3", "g8f6", "d7d6"]
|
|
|
|
|
|
};
|
|
|
|
|
|
for (ply, best) in [first_player, opponent, first_player + 2, first_player + 4]
|
|
|
|
|
|
.into_iter()
|
|
|
|
|
|
.zip(alternatives)
|
|
|
|
|
|
{
|
|
|
|
|
|
evals.get_mut(&game.keys[ply]).unwrap().pv = vec![best.to_owned()];
|
|
|
|
|
|
}
|
|
|
|
|
|
let errors = judge_games(std::slice::from_ref(&game), &[0], &evals);
|
|
|
|
|
|
assert_eq!(errors.len(), 1);
|
|
|
|
|
|
assert_eq!(errors[0].ply, first_player as u32);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn incomplete_opponent_prefix_withholds_errors_until_checked() {
|
|
|
|
|
|
let game = game(0, true, &["e4", "e5", "Qh5", "Nc6"], "*", "", 0);
|
|
|
|
|
|
let mut complete = line_evals(&game, &[0, 0, 0, -150, -150]);
|
|
|
|
|
|
complete.get_mut(&game.keys[2]).unwrap().pv = vec!["g1f3".to_owned()];
|
|
|
|
|
|
for missing in [game.keys[1], game.keys[2]] {
|
|
|
|
|
|
let mut partial = complete.clone();
|
|
|
|
|
|
partial.remove(&missing);
|
|
|
|
|
|
assert!(judge_games(std::slice::from_ref(&game), &[0], &partial).is_empty());
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut missing_best = complete.clone();
|
|
|
|
|
|
missing_best.get_mut(&game.keys[1]).unwrap().pv.clear();
|
|
|
|
|
|
assert!(judge_games(std::slice::from_ref(&game), &[0], &missing_best).is_empty());
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
|
judge_games(std::slice::from_ref(&game), &[0], &complete).len(),
|
|
|
|
|
|
1
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn opponent_allowing_mate_is_judged_from_the_actual_mover() {
|
|
|
|
|
|
for white in [true, false] {
|
|
|
|
|
|
let game = game(0, white, &["e4", "e5", "Qh5", "Nc6"], "*", "", 0);
|
|
|
|
|
|
let opponent = usize::from(white);
|
|
|
|
|
|
let mut evals = line_evals(&game, &[0, 0, 0, 0, 0]);
|
|
|
|
|
|
evals.get_mut(&game.keys[opponent]).unwrap().pv =
|
|
|
|
|
|
vec![if white { "c7c5" } else { "d2d4" }.to_owned()];
|
|
|
|
|
|
evals.get_mut(&game.keys[opponent + 1]).unwrap().eval = Eval::Mate { white, moves: 3 };
|
|
|
|
|
|
evals.get_mut(&game.keys[opponent + 1]).unwrap().pv =
|
|
|
|
|
|
vec![if white { "g1f3" } else { "c7c5" }.to_owned()];
|
|
|
|
|
|
// The player's next move lets that forced mate go, normally an error.
|
|
|
|
|
|
assert!(judge_games(std::slice::from_ref(&game), &[0], &evals).is_empty());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn the_position_cache_keeps_the_best_quality_and_survives_a_save() {
|
|
|
|
|
|
let dir = std::env::temp_dir().join(format!("prep-cache-test-{}", std::process::id()));
|
|
|
|
|
|
let _ = std::fs::remove_dir_all(&dir);
|
|
|
|
|
|
let mut c = PositionCache::load(&dir);
|
|
|
|
|
|
assert!(c.is_empty());
|
|
|
|
|
|
assert!(c.insert(1, eval(1000, 10, "e2e4")));
|
|
|
|
|
|
assert!(!c.insert(1, eval(250, 20, "d2d4")), "fewer nodes: not kept");
|
|
|
|
|
|
assert!(c.insert(1, eval(3000, 30, "c2c4")));
|
|
|
|
|
|
assert!(c.insert(2, eval(EXACT, 0, "")));
|
|
|
|
|
|
assert_eq!(c.get(1).map(|e| e.nodes), Some(3000));
|
|
|
|
|
|
assert!(c.dirty());
|
|
|
|
|
|
c.save(&dir).expect("saved");
|
|
|
|
|
|
assert!(!c.dirty());
|
|
|
|
|
|
let d = PositionCache::load(&dir);
|
|
|
|
|
|
assert_eq!(d.len(), 2);
|
|
|
|
|
|
assert_eq!(d.get(1), c.get(1));
|
|
|
|
|
|
assert_eq!(d.get(2).map(|e| e.nodes), Some(EXACT));
|
|
|
|
|
|
assert_eq!(d.get(3), None);
|
Review: one fixed engine search everywhere, in parallel engine processes
Every position of a game analysis (and of the opening errors) is searched by
ChessPenguin's Stockfish 19 to 1M nodes with one thread, a 32 MB hash and
ucinewgame before each search, so the evaluations depend on the position
alone: the same marks on every computer and phone, whatever the number of
engine processes (one per CPU, at most 8 on a computer and 4 on a phone, and
what the free memory holds) or the order of the positions.
- ReviewMeta.search: analyses of another search are stale; shown, but
Update makes them all again. The prep caches drop such evaluations.
- Desktop: no launch dialog (engine, quality, threads, memory are gone);
Analyse starts at once, its tooltip gives the time; the prep dialog keeps
the colour. Without the own Stockfish the download is offered.
- settings.review and prep.quality removed; old settings files still read.
- fake_uci --hash-memory; tests of determinism on processes and order.
- chesscom_check in the fixed search (CP_REVIEW_NODES for experiments);
review_bench example for times and determinism on a real engine.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 19:19:44 +03:00
|
|
|
|
// A cache from before the fixed search of the game analysis is not used.
|
|
|
|
|
|
let path = PositionCache::path(&dir);
|
|
|
|
|
|
let mut json: serde_json::Value =
|
|
|
|
|
|
serde_json::from_slice(&std::fs::read(&path).expect("cache")).expect("json");
|
|
|
|
|
|
json.as_object_mut().expect("cache").remove("search");
|
|
|
|
|
|
std::fs::write(&path, serde_json::to_vec(&json).expect("json")).expect("written");
|
|
|
|
|
|
assert!(PositionCache::load(&dir).is_empty());
|
Opponent prep: the `prep` crate (openings only)
A new crate shared by the apps, no UI: what a player of a database plays
in the opening and where in the opening he goes wrong.
- Player: candidates from the database's names (initials with a full
stop work), one or several ids, White, Black or both.
- Lines: the first N plies (default 20) of the main lines, position keys,
UCI/SAN, result from the player's side, full date, opponent's Elo;
games from a set-up position are skipped.
- Repertoire tree per colour by move order with position keys:
games (+/=/-), last date, average opponent Elo, game list,
transpositions marked.
- Opening names from lichess-org/chess-openings (CC0; revision and
SHA-256 pinned, files in crates/prep/data, THIRD_PARTY_NOTICES): the
deepest named position of a line, families and variations with their
first moves, grouped by name.
- Book: a second database (or the same one without the player's games)
says where each game left it (first position with fewer than T games,
T = 5) and whose move it was.
- Engine: every distinct position of the lines once through
game_review::run, judged with the game analysis rules for the player's
moves only; errors by opening and the repeated ones (same position,
same move in two or more games); evaluations cached per position across
reports, the report cached by database, player and plies.
- examples/prep_report.rs prints it all for a database and a player.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-28 12:32:39 +03:00
|
|
|
|
let _ = std::fs::remove_dir_all(&dir);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|