2026-10-28 18:37:42 +03:00
|
|
|
//! Opening names: the table lives in the `chess-openings` crate (the game review uses it
|
|
|
|
|
//! too); here only what a report keeps of it.
|
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 std::collections::HashMap;
|
|
|
|
|
|
2026-10-28 18:37:42 +03:00
|
|
|
pub use chess_openings::*;
|
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
|
|
|
|
|
|
|
|
/// The openings a report refers to, each once, in the order they were first met.
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
pub struct OpeningSet {
|
|
|
|
|
pub list: Vec<Opening>,
|
|
|
|
|
by_table: HashMap<usize, usize>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl OpeningSet {
|
|
|
|
|
/// The place of table entry `id` in [`OpeningSet::list`].
|
|
|
|
|
pub fn intern(&mut self, id: usize) -> usize {
|
|
|
|
|
if let Some(&i) = self.by_table.get(&id) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
self.list.push(get(id).clone());
|
|
|
|
|
self.by_table.insert(id, self.list.len() - 1);
|
|
|
|
|
self.list.len() - 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
2026-10-28 18:37:42 +03:00
|
|
|
use chess_core::shakmaty::Chess;
|
|
|
|
|
use chess_core::shakmaty::Position;
|
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 chess_core::shakmaty::san::San;
|
|
|
|
|
|
|
|
|
|
fn keys(moves: &[&str]) -> Vec<u64> {
|
|
|
|
|
let mut pos = Chess::default();
|
|
|
|
|
let mut out = vec![key(&pos)];
|
|
|
|
|
for s in moves {
|
|
|
|
|
let m = s.parse::<San>().unwrap().to_move(&pos).unwrap();
|
|
|
|
|
pos.play_unchecked(m);
|
|
|
|
|
out.push(key(&pos));
|
|
|
|
|
}
|
|
|
|
|
out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn a_set_keeps_each_opening_once() {
|
|
|
|
|
let mut set = OpeningSet::default();
|
|
|
|
|
let id = deepest(&keys(&["e4", "c5"])).unwrap().1;
|
|
|
|
|
let other = deepest(&keys(&["d4"])).unwrap().1;
|
|
|
|
|
assert_eq!(set.intern(id), 0);
|
|
|
|
|
assert_eq!(set.intern(other), 1);
|
|
|
|
|
assert_eq!(set.intern(id), 0);
|
|
|
|
|
assert_eq!(set.list.len(), 2);
|
|
|
|
|
}
|
|
|
|
|
}
|