Opponent prep: the tester's and designer's review
Core: the most precise opening name stays down a line (a deeper position the table names more generally, «Sicilian Defense» after 3.d4, does not take it back), in the games' names and in the tree; one name per position across move orders; the games and the last date of a position over all its move orders; `evaluated()` (evaluations from the cache count). Report version 3. Screen: errors judged from cached evaluations show without a run; «Checked N of M positions · Continue» after «Stop» or a new depth; the report shows the book only when it was computed with the chosen one; the dialog keeps the remembered book and the same player reopens with the dialog's colour and book; «Deeper» and the depth list share one path (setting kept, report from the cache); a chosen error survives re-judging during the run; quitting during the run asks first; Ctrl+W returns from a game opened from the report; a game opened at an error opens after the move, a repeated error at its newest game. Design (§12): the summary as a grid whose columns give way, counts in the colours of the signs; result bars without numbers, faint over few games; move lines numbered at White's moves; whole-move first-move lines; colour icons in the openings table; ECO kept beside the name; the errors tab as one table with row selection and keys (↑/↓/→/←/Enter); colour lines there only in the stack; «Inaccuracies» switch (kept in settings) for the tab, the summary, the tree and the games; «▾» at the right end; one colour order; the depth caption by the room left; names first in narrow game lists; two-row games minimum in a low window; the caption beside the stacked board; «others (N)» when narrow. Designer's review recorded in docs/design/opponent-prep.md §12. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5cfadcc7f6
commit
d654223665
9 changed files with 1720 additions and 748 deletions
|
|
@ -138,7 +138,7 @@ pub struct BookInfo {
|
|||
pub left: u32,
|
||||
}
|
||||
|
||||
const REPORT_VERSION: u32 = 2;
|
||||
const REPORT_VERSION: u32 = 3;
|
||||
|
||||
/// Everything the preparation knows about the player.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
|
|
@ -400,6 +400,12 @@ impl PrepReport {
|
|||
out
|
||||
}
|
||||
|
||||
/// Some position has an engine evaluation (from a run or from the cache): the
|
||||
/// errors are judged.
|
||||
pub fn evaluated(&self) -> bool {
|
||||
self.evals.values().any(|e| e.nodes != EXACT)
|
||||
}
|
||||
|
||||
/// Distinct positions an engine run looks at.
|
||||
pub fn distinct_positions(&self) -> usize {
|
||||
self.positions().len()
|
||||
|
|
@ -890,6 +896,7 @@ mod tests {
|
|||
}
|
||||
assert_eq!(report.missing(1000), 0);
|
||||
assert_eq!(report.missing(2000), total);
|
||||
assert!(report.evaluated());
|
||||
report.refresh();
|
||||
assert_eq!(report.engine.as_ref().map(|e| e.nodes), Some(1000));
|
||||
let w = &report.white;
|
||||
|
|
@ -921,7 +928,9 @@ mod tests {
|
|||
assert!(PrepReport::load(&dir, &db, &other, &Options::default()).is_none());
|
||||
let mut fresh = build(&db, &player, &Options::default(), &AtomicUsize::new(0), &never)
|
||||
.expect("report");
|
||||
assert!(!fresh.evaluated());
|
||||
assert_eq!(fresh.take_cached(&cache, 1000), total);
|
||||
assert!(fresh.evaluated(), "evaluations from the cache judge the errors too");
|
||||
assert_eq!(fresh.white.repeated, report.white.repeated);
|
||||
assert_eq!(fresh.take_cached(&cache, 1000), 0);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
|
|
|
|||
|
|
@ -122,13 +122,34 @@ pub fn get(id: usize) -> &'static Opening {
|
|||
&table().entries[id]
|
||||
}
|
||||
|
||||
/// The deepest named position among `keys` (the positions of a line, in order): its
|
||||
/// index in `keys` and its entry.
|
||||
/// The name of a line (the positions `keys`, in order): its deepest named position,
|
||||
/// its index in `keys` and its entry — but a deeper position whose name is only a
|
||||
/// more general one ("Sicilian Defense" after 3.d4 in the "Modern Variations") does
|
||||
/// not take the name back: the most precise name met stays.
|
||||
pub fn deepest(keys: &[u64]) -> Option<(usize, usize)> {
|
||||
keys.iter()
|
||||
.enumerate()
|
||||
.rev()
|
||||
.find_map(|(i, k)| by_position(*k).map(|id| (i, id)))
|
||||
let mut out: Option<(usize, usize)> = None;
|
||||
for (i, k) in keys.iter().enumerate() {
|
||||
if let Some(id) = by_position(*k)
|
||||
&& out.is_none_or(|(_, cur)| !more_general(id, cur))
|
||||
{
|
||||
out = Some((i, id));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Entry `a`'s name is a more general form of entry `b`'s ("Sicilian Defense" of
|
||||
/// "Sicilian Defense: Modern Variations"; "…: Najdorf Variation" of "…: Najdorf
|
||||
/// Variation, English Attack").
|
||||
pub fn more_general(a: usize, b: usize) -> bool {
|
||||
is_prefix_name(&get(a).name, &get(b).name)
|
||||
}
|
||||
|
||||
/// `general` names a family or a variation `precise` is part of.
|
||||
pub fn is_prefix_name(general: &str, precise: &str) -> bool {
|
||||
precise.len() > general.len()
|
||||
&& precise.starts_with(general)
|
||||
&& matches!(precise[general.len()..].chars().next(), Some(':' | ','))
|
||||
}
|
||||
|
||||
/// The openings a report refers to, each once, in the order they were first met.
|
||||
|
|
@ -198,6 +219,17 @@ mod tests {
|
|||
assert_eq!(o.variation(), None);
|
||||
// Nothing before the first move.
|
||||
assert_eq!(deepest(&keys(&[])), None);
|
||||
// A deeper position with a more general name keeps the precise one: the
|
||||
// table names 1.e4 c5 2.Nf3 d6 3.d4 just «Sicilian Defense».
|
||||
let line = keys(&["e4", "c5", "Nf3", "d6", "d4"]);
|
||||
let after_d4 = by_position(line[5]).map(|id| get(id).name.clone());
|
||||
assert_eq!(after_d4.as_deref(), Some("Sicilian Defense"));
|
||||
let (at, id) = deepest(&line).expect("named");
|
||||
assert_eq!((at, get(id).name.as_str()), (4, "Sicilian Defense: Modern Variations"));
|
||||
assert!(is_prefix_name("Sicilian Defense", "Sicilian Defense: Modern Variations"));
|
||||
assert!(is_prefix_name("A: B", "A: B, C"));
|
||||
assert!(!is_prefix_name("Sicilian Defense", "Sicilian Defense"));
|
||||
assert!(!is_prefix_name("English", "English Opening"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -96,7 +96,14 @@ impl Tree {
|
|||
Some(&c) => c as usize,
|
||||
None => {
|
||||
let key = game.keys[i + 1];
|
||||
let named = openings::by_position(key);
|
||||
// A more general name than the path's keeps the path's
|
||||
// (see `openings::deepest`).
|
||||
let parent = tree.nodes[at].opening.map(|o| openings.list[o].name.clone());
|
||||
let named = openings::by_position(key).filter(|&id| {
|
||||
parent
|
||||
.as_deref()
|
||||
.is_none_or(|p| !openings::is_prefix_name(&openings::get(id).name, p))
|
||||
});
|
||||
let opening = named
|
||||
.map(|id| openings.intern(id))
|
||||
.or(tree.nodes[at].opening);
|
||||
|
|
@ -139,9 +146,52 @@ impl Tree {
|
|||
for n in &mut tree.nodes {
|
||||
n.transposition = seen.get(&n.key).is_some_and(|c| *c > 1);
|
||||
}
|
||||
// One position, one name: the most precise of its move orders' names; a node
|
||||
// is «named» where its name differs from its parent's.
|
||||
let mut best: HashMap<u64, usize> = HashMap::new();
|
||||
for n in tree.nodes.iter().filter(|n| n.transposition) {
|
||||
if let Some(o) = n.opening {
|
||||
let e = best.entry(n.key).or_insert(o);
|
||||
if openings::is_prefix_name(&openings.list[*e].name, &openings.list[o].name) {
|
||||
*e = o;
|
||||
}
|
||||
}
|
||||
}
|
||||
for i in 0..tree.nodes.len() {
|
||||
if let Some(&o) = best.get(&tree.nodes[i].key) {
|
||||
tree.nodes[i].opening = Some(o);
|
||||
}
|
||||
let parent = tree.nodes[i].parent.and_then(|p| tree.nodes[p as usize].opening);
|
||||
let name = |o: Option<usize>| o.map(|o| openings.list[o].name.as_str());
|
||||
tree.nodes[i].named = tree.nodes[i].opening.is_some() && name(tree.nodes[i].opening) != name(parent);
|
||||
}
|
||||
tree
|
||||
}
|
||||
|
||||
/// The games through the position `key` by any move order (indices into
|
||||
/// [`crate::PrepReport::games`], in order).
|
||||
pub fn position_games(&self, key: u64) -> Vec<u32> {
|
||||
let mut out: Vec<u32> = self
|
||||
.nodes
|
||||
.iter()
|
||||
.filter(|n| n.key == key)
|
||||
.flat_map(|n| n.games.iter().copied())
|
||||
.collect();
|
||||
out.sort_unstable();
|
||||
out.dedup();
|
||||
out
|
||||
}
|
||||
|
||||
/// The latest date among the games through the position `key`.
|
||||
pub fn position_last_date(&self, key: u64) -> &str {
|
||||
self.nodes
|
||||
.iter()
|
||||
.filter(|n| n.key == key)
|
||||
.map(|n| n.last_date.as_str())
|
||||
.max_by_key(|d| chess_import::pgn_catalog::date_number(d))
|
||||
.unwrap_or("")
|
||||
}
|
||||
|
||||
fn count(&mut self, node: usize, g: u32, game: &GameInfo) {
|
||||
let n = &mut self.nodes[node];
|
||||
n.tally.add(game.outcome);
|
||||
|
|
@ -244,6 +294,8 @@ pub(crate) mod tests {
|
|||
let after_d4 = tree.nodes.iter().find(|n| n.ply == 3 && n.san == "d4").unwrap();
|
||||
assert_eq!(after_nf3.key, after_d4.key);
|
||||
assert_eq!(tree.position_tally(after_nf3.key).games, 2);
|
||||
assert_eq!(tree.position_games(after_nf3.key), vec![0, 1]);
|
||||
assert_eq!(tree.position_last_date(after_nf3.key), "2026.03.01");
|
||||
assert!(!tree.nodes.iter().find(|n| n.san == "c4").unwrap().transposition);
|
||||
assert_eq!(tree.path(after_d4.parent.unwrap() as usize), vec!["Nf3", "d5"]);
|
||||
// Names: 1.d4 d5 2.Nf3 is named in the table, 2...Nf6 is too (Zukertort);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue