From 262c0b17119a069218d0d7e223398da264bd81c2 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Wed, 28 Oct 2026 20:37:06 +0300 Subject: [PATCH] Release 2.1.0 Preparing against an opponent (openings), one fixed engine search for the game review everywhere, !! and ! recalibrated on chess.com (check set of 15 games), 100 classic sample games that update with the program. Formatting by cargo fmt. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 21 + Cargo.lock | 26 +- Cargo.toml | 2 +- apps/desktop/src/app.rs | 2 +- apps/desktop/src/game_view.rs | 3 +- apps/desktop/src/i18n.rs | 30 +- apps/desktop/src/large_db.rs | 5 +- apps/desktop/src/library.rs | 5 +- apps/desktop/src/prep_ui.rs | 1466 +++++++++++++---- apps/desktop/src/reference.rs | 4 +- apps/desktop/src/review.rs | 21 +- apps/desktop/src/settings.rs | 16 +- crates/chess-import/src/chessbase/base.rs | 3 +- crates/chess-import/src/position.rs | 16 +- crates/game-review/examples/chesscom_check.rs | 11 +- crates/game-review/src/features.rs | 29 +- crates/game-review/src/job.rs | 18 +- crates/game-review/src/lib.rs | 10 +- crates/game-review/src/report.rs | 5 +- crates/mobile-api/src/lib.rs | 5 +- crates/mobile-api/src/review.rs | 4 +- crates/openings/src/lib.rs | 41 +- crates/prep/examples/prep_report.rs | 58 +- crates/prep/src/errors.rs | 18 +- crates/prep/src/games.rs | 11 +- crates/prep/src/lib.rs | 197 ++- crates/prep/src/tree.rs | 84 +- ...thub.vrubelroman.chessPenguin.metainfo.xml | 5 + 28 files changed, 1621 insertions(+), 495 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1e9df2..0258fae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,27 @@ All notable changes are listed here. Versions follow [Semantic Versioning](https ## [Unreleased] +## [2.1.0] — 2026-10-28 + +- Desktop: preparing against an opponent. Pick a player of a database (similar names + shown apart, spellings can be joined) and get their opening repertoire: a tree of + their moves for each colour with opening names (the Lichess opening table), games, + score and the last game, a table of openings and variations with their first moves, + and — on request — the engine's look at their opening mistakes, by opening, with the + mistakes they repeat. A book from the shelf shows where they leave theory. Every + table sorts by its columns; the tree starts folded. +- The game review always uses the same engine search, on every computer and phone: + Stockfish 19 of ChessPenguin, one million nodes a position, one thread per engine + process and several processes side by side. The same game gets the same marks + everywhere; nothing to choose any more (the analysis dialog is gone). An analysis made + with other settings says so and offers «Update». +- Brilliant (!!) and great (!) moves recalibrated on chess.com's marks of 15 famous + games (a check set the program keeps): !! now agree with chess.com 96 % of the time. + Great moves are rarer and surer: never for a capture, only when every other move is + clearly worse; no ! or !! for a book move. +- The sample «Classic games» grow from 38 to 100 famous games; a new version of a + sample replaces the old one on update (desktop and Android). + ## [2.0.0] — 2026-10-28 - The databases downloaded from Lichess and Chess.com get the games played since on their diff --git a/Cargo.lock b/Cargo.lock index e33a577..0bd4748 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -768,7 +768,7 @@ dependencies = [ [[package]] name = "chess-core" -version = "2.0.0" +version = "2.1.0" dependencies = [ "encoding_rs", "pgn-reader", @@ -778,7 +778,7 @@ dependencies = [ [[package]] name = "chess-import" -version = "2.0.0" +version = "2.1.0" dependencies = [ "chess-core", "encoding_rs", @@ -791,7 +791,7 @@ dependencies = [ [[package]] name = "chess-openings" -version = "2.0.0" +version = "2.1.0" dependencies = [ "chess-import", "serde", @@ -800,7 +800,7 @@ dependencies = [ [[package]] name = "chesspenguin" -version = "2.0.0" +version = "2.1.0" dependencies = [ "arboard", "base64 0.22.1", @@ -1678,7 +1678,7 @@ dependencies = [ [[package]] name = "game-review" -version = "2.0.0" +version = "2.1.0" dependencies = [ "chess-core", "chess-openings", @@ -2396,7 +2396,7 @@ dependencies = [ [[package]] name = "maia" -version = "2.0.0" +version = "2.1.0" dependencies = [ "serde_json", "shakmaty", @@ -2473,7 +2473,7 @@ dependencies = [ [[package]] name = "mobile-api" -version = "2.0.0" +version = "2.1.0" dependencies = [ "chess-core", "chess-import", @@ -3072,7 +3072,7 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] name = "online-games" -version = "2.0.0" +version = "2.1.0" dependencies = [ "chess-core", "serde", @@ -3339,7 +3339,7 @@ checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" [[package]] name = "play" -version = "2.0.0" +version = "2.1.0" dependencies = [ "chess-core", "getrandom 0.3.4", @@ -3440,7 +3440,7 @@ checksum = "196a7c80b9a7652aba7cc070827516c2abe4ccdf53d128e1944003cf5726cff1" [[package]] name = "prep" -version = "2.0.0" +version = "2.1.0" dependencies = [ "chess-core", "chess-import", @@ -3639,7 +3639,7 @@ dependencies = [ [[package]] name = "releases" -version = "2.0.0" +version = "2.1.0" dependencies = [ "serde_json", "ureq", @@ -4634,7 +4634,7 @@ dependencies = [ [[package]] name = "trainer" -version = "2.0.0" +version = "2.1.0" dependencies = [ "chess-core", "chrono", @@ -4676,7 +4676,7 @@ checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "uci" -version = "2.0.0" +version = "2.1.0" dependencies = [ "libc", "thiserror 2.0.21", diff --git a/Cargo.toml b/Cargo.toml index 884239a..b032d0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ members = [ ] [workspace.package] -version = "2.0.0" +version = "2.1.0" edition = "2024" rust-version = "1.97" license = "GPL-3.0-or-later" diff --git a/apps/desktop/src/app.rs b/apps/desktop/src/app.rs index f53ad4d..71976bc 100644 --- a/apps/desktop/src/app.rs +++ b/apps/desktop/src/app.rs @@ -13,11 +13,11 @@ use crate::analysis::Analysis; use crate::assets::Sound; use crate::game_view::{GameAction, GameSource, GameView}; use crate::library::{Library, LibraryAction}; -use crate::prep_ui::{DialogOutcome, PrepAction, PrepDialog, PrepScreen}; use crate::own_db::{ self, Answer, ChooserFor, ChooserOutcome, EditorMode, EditorOutcome, NewBaseOutcome, QuestionKind, }; +use crate::prep_ui::{DialogOutcome, PrepAction, PrepDialog, PrepScreen}; use crate::settings::{EngineConfig, Settings}; use crate::settings_ui::{SettingsAction, SettingsWindow, Tab}; use crate::sound::SoundPlayer; diff --git a/apps/desktop/src/game_view.rs b/apps/desktop/src/game_view.rs index 78f4fc4..fc68f5e 100644 --- a/apps/desktop/src/game_view.rs +++ b/apps/desktop/src/game_view.rs @@ -787,7 +787,8 @@ impl GameView { if std::mem::take(&mut self.review_asked) { if self.engine_busy { actions.push(GameAction::Toast( - tr("Opening errors are being searched — wait or stop it in the report").to_owned(), + tr("Opening errors are being searched — wait or stop it in the report") + .to_owned(), )); } else { self.start_review(false, ui.ctx(), &mut actions); diff --git a/apps/desktop/src/i18n.rs b/apps/desktop/src/i18n.rs index 6ab26b1..3d8a66d 100644 --- a/apps/desktop/src/i18n.rs +++ b/apps/desktop/src/i18n.rs @@ -13775,15 +13775,7 @@ const ROWS: &[[&str; 9]] = &[ "Екеуі", ], [ - "None", - "Нет", - "Aucun", - "Keines", - "Ninguno", - "Nessuno", - "Nenhum", - "Yo‘q", - "Жоқ", + "None", "Нет", "Aucun", "Keines", "Ninguno", "Nessuno", "Nenhum", "Yo‘q", "Жоқ", ], [ "A book is a large database that shows up to which move his line is common and where he plays a rare move. A rare move is not a mistake.", @@ -13819,15 +13811,7 @@ const ROWS: &[[&str; 9]] = &[ "Аты немесе оның бөлігі", ], [ - "Colour", - "Цвет", - "Couleur", - "Farbe", - "Color", - "Colore", - "Cor", - "Rang", - "Түс", + "Colour", "Цвет", "Couleur", "Farbe", "Color", "Colore", "Cor", "Rang", "Түс", ], [ "Book", @@ -14919,15 +14903,7 @@ const ROWS: &[[&str; 9]] = &[ "{n} жүріс", ], [ - "{n} m.", - "{n} х.", - "{n} c.", - "{n} Z.", - "{n} j.", - "{n} m.", - "{n} l.", - "{n} yur.", - "{n} ж.", + "{n} m.", "{n} х.", "{n} c.", "{n} Z.", "{n} j.", "{n} m.", "{n} l.", "{n} yur.", "{n} ж.", ], [ "Continue ≈ {time}", diff --git a/apps/desktop/src/large_db.rs b/apps/desktop/src/large_db.rs index cc908fb..94953be 100644 --- a/apps/desktop/src/large_db.rs +++ b/apps/desktop/src/large_db.rs @@ -1306,7 +1306,10 @@ impl LargeView { // dialog offers the names that match the text (opponent-prep.md §2.1). if player_set { let label = match self.form.player.exact { - Some(_) => trf("♟ Prepare against {name}…", &[("name", &self.form.player.text)]), + Some(_) => trf( + "♟ Prepare against {name}…", + &[("name", &self.form.player.text)], + ), None => tr("♟ Prepare against an opponent…").to_owned(), }; if ui diff --git a/apps/desktop/src/library.rs b/apps/desktop/src/library.rs index a917dbf..bd099e3 100644 --- a/apps/desktop/src/library.rs +++ b/apps/desktop/src/library.rs @@ -652,7 +652,10 @@ impl Library { if !matches!(self.slots.get(&path), Some(Slot::Ready(_))) { return None; } - Some((path.clone(), self.large.get(&path).and_then(|v| v.prep_entry()))) + Some(( + path.clone(), + self.large.get(&path).and_then(|v| v.prep_entry()), + )) } fn notes_window(&mut self, ctx: &egui::Context) { diff --git a/apps/desktop/src/prep_ui.rs b/apps/desktop/src/prep_ui.rs index 452da7a..dd0bdbc 100644 --- a/apps/desktop/src/prep_ui.rs +++ b/apps/desktop/src/prep_ui.rs @@ -15,12 +15,12 @@ use chess_import::Database; use chess_import::chessbase::base::{Side, fold}; use egui::{Color32, Key, KeyboardShortcut, Modifiers, RichText, Sense, Ui, vec2}; use egui_extras::{Column, TableBuilder}; -use serde::{Deserialize, Serialize}; use game_review::{JobEvent, JobFailure, JobSettings, Judgement}; use prep::{ - BookExit, BookOptions, Candidate, ErrorCounts, GameInfo, Options, Player, - PositionCache, PrepReport, Tally, + BookExit, BookOptions, Candidate, ErrorCounts, GameInfo, Options, Player, PositionCache, + PrepReport, Tally, }; +use serde::{Deserialize, Serialize}; use shakmaty::uci::UciMove; use shakmaty::{Chess, Color, Move, Position, Square}; @@ -132,11 +132,26 @@ impl Default for PrepSorts { fn default() -> Self { // Most played, most repeated, worst, newest first. PrepSorts { - tree: SortBy { key: TreeSort::Games, ascending: false }, - openings: SortBy { key: OpeningSort::Games, ascending: false }, - repeated: SortBy { key: RepeatedSort::Times, ascending: false }, - variations: SortBy { key: VariationSort::Errors, ascending: false }, - games: SortBy { key: GameSort::Date, ascending: false }, + tree: SortBy { + key: TreeSort::Games, + ascending: false, + }, + openings: SortBy { + key: OpeningSort::Games, + ascending: false, + }, + repeated: SortBy { + key: RepeatedSort::Times, + ascending: false, + }, + variations: SortBy { + key: VariationSort::Errors, + ascending: false, + }, + games: SortBy { + key: GameSort::Date, + ascending: false, + }, } } } @@ -181,7 +196,11 @@ fn sort_col( ) { h.col(|ui| { let r = crate::widgets::sort_header(ui, text, (sort.key == key).then_some(sort.ascending)); - let r = if hint.is_empty() { r } else { r.on_hover_text(hint) }; + let r = if hint.is_empty() { + r + } else { + r.on_hover_text(hint) + }; if r.clicked() { *clicked = Some(key); } @@ -476,8 +495,10 @@ impl PrepDialog { } let (db, q) = (db.clone(), query.clone()); let now = ctx.input(|i| i.time); - self.search = Background::spawn(ctx, now, move |_, _| Some(prep::candidates(&db, &q, CANDIDATES))) - .map(|j| (query, j)); + self.search = Background::spawn(ctx, now, move |_, _| { + Some(prep::candidates(&db, &q, CANDIDATES)) + }) + .map(|j| (query, j)); } fn poll(&mut self, ctx: &egui::Context, db: &Arc) { @@ -547,7 +568,11 @@ impl PrepDialog { if self.book.is_none() && !self.dbs.is_empty() { // The book chosen last time, else the largest database on the shelf: once // the shelf is known. - self.book = Some(BookChoice::from_setting(settings.prep.book.as_deref(), &self.path, &self.dbs)); + self.book = Some(BookChoice::from_setting( + settings.prep.book.as_deref(), + &self.path, + &self.dbs, + )); } let book = self.book.clone().unwrap_or(BookChoice::None); let mut outcome = None; @@ -733,7 +758,10 @@ impl PrepDialog { if modal.should_close() { outcome = Some(DialogOutcome::Cancel); } - if outcome.is_none() && ready && ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::Enter)) { + if outcome.is_none() + && ready + && ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::Enter)) + { outcome = Some(DialogOutcome::Open(self.start())); } if outcome.is_none() && ready && self.auto_open && self.search.is_none() { @@ -768,7 +796,10 @@ impl PrepDialog { if self.query.trim().is_empty() { ui.horizontal(|ui| { ui.add_space(indent); - ui.label(RichText::new(tr("Type a name: the players of the database are offered")).weak()); + ui.label( + RichText::new(tr("Type a name: the players of the database are offered")) + .weak(), + ); }); return; } @@ -968,9 +999,18 @@ struct Mark { /// A row of the repertoire tree as laid out. #[derive(Clone, Copy, PartialEq, Eq)] enum TreeRow { - Node { white: bool, node: u32, depth: usize }, + Node { + white: bool, + node: u32, + depth: usize, + }, /// «other moves (n)» under a node. - Others { white: bool, parent: u32, depth: usize, count: usize }, + Others { + white: bool, + parent: u32, + depth: usize, + count: usize, + }, } /// A row of the errors tab. @@ -980,11 +1020,25 @@ enum ErrRow { RepeatedTitle, OpeningsTitle, /// A repeated error (colour, index into `repeated`) and one of its games. - Repeated { white: bool, index: usize }, - RepeatedGame { white: bool, index: usize, game: u32 }, + Repeated { + white: bool, + index: usize, + }, + RepeatedGame { + white: bool, + index: usize, + game: u32, + }, /// A variation with errors (colour, family, variation) and one of its errors. - Variation { white: bool, family: usize, variation: usize }, - Error { white: bool, index: usize }, + Variation { + white: bool, + family: usize, + variation: usize, + }, + Error { + white: bool, + index: usize, + }, } impl ErrRow { @@ -997,9 +1051,15 @@ impl ErrRow { enum EngineTexts { Running, /// A button to start or go on, and a note beside it. - Button { label: String, note: Option }, + Button { + label: String, + note: Option, + }, /// Done: a quiet label. - Done { label: String, note: Option }, + Done { + label: String, + note: Option, + }, } /// Where the engine run stands for the colour(s) shown. @@ -1009,8 +1069,13 @@ enum EngineState { /// No evaluation yet. NotRun, /// Some positions evaluated (a run stopped, a new depth, new games). - Partial { done: usize, total: usize }, - Complete { total: usize }, + Partial { + done: usize, + total: usize, + }, + Complete { + total: usize, + }, } /// Fewer games: the percentages are shown weak. @@ -1141,7 +1206,12 @@ fn table_line(line: &str) -> Vec { let mut out: Vec = Vec::new(); let mut number: Option<&str> = None; for tok in line.split_whitespace() { - if tok.ends_with('.') && tok.trim_end_matches('.').chars().all(|c| c.is_ascii_digit()) { + if tok.ends_with('.') + && tok + .trim_end_matches('.') + .chars() + .all(|c| c.is_ascii_digit()) + { number = Some(tok); } else { out.push(match number.take() { @@ -1193,7 +1263,9 @@ fn period(games: &[GameInfo]) -> String { let month = |g: &GameInfo| -> String { let parts: Vec<&str> = g.date.split('.').collect(); match parts.as_slice() { - [y, m, ..] if m.chars().all(|c| c.is_ascii_digit()) && !m.is_empty() => format!("{m}.{y}"), + [y, m, ..] if m.chars().all(|c| c.is_ascii_digit()) && !m.is_empty() => { + format!("{m}.{y}") + } [y, ..] => (*y).to_string(), _ => String::new(), } @@ -1212,7 +1284,11 @@ fn period(games: &[GameInfo]) -> String { /// player's, the percentages are in its tooltip. Faint over few games. fn score_bar(ui: &mut Ui, t: &Tally, white: bool, few: bool) { let (rect, resp) = ui.allocate_exact_size(vec2(56.0, 12.0), Sense::hover()); - let (white_wins, black_wins) = if white { (t.wins, t.losses) } else { (t.losses, t.wins) }; + let (white_wins, black_wins) = if white { + (t.wins, t.losses) + } else { + (t.losses, t.wins) + }; let decided = white_wins + t.draws + black_wins; let fade = |c: Color32| if few { c.gamma_multiply(0.45) } else { c }; let painter = ui.painter(); @@ -1231,7 +1307,10 @@ fn score_bar(ui: &mut Ui, t: &Tally, white: bool, few: bool) { let w = rect.width() * n as f32 / decided as f32; if w > 0.0 { painter.rect_filled( - egui::Rect::from_min_max(egui::pos2(x, rect.top()), egui::pos2(x + w, rect.bottom())), + egui::Rect::from_min_max( + egui::pos2(x, rect.top()), + egui::pos2(x + w, rect.bottom()), + ), 0.0, fade(fill), ); @@ -1239,18 +1318,28 @@ fn score_bar(ui: &mut Ui, t: &Tally, white: bool, few: bool) { x += w; } } - painter.rect_stroke(rect, 2.0, egui::Stroke::new(1.0, fade(outline)), egui::StrokeKind::Inside); + painter.rect_stroke( + rect, + 2.0, + egui::Stroke::new(1.0, fade(outline)), + egui::StrokeKind::Inside, + ); if decided > 0 { let pct = |n: u32| 100 * n / decided; resp.on_hover_text(trf( "White wins {w} % · draws {d} % · Black wins {b} %", - &[("w", &pct(white_wins)), ("d", &pct(t.draws)), ("b", &pct(black_wins))], + &[ + ("w", &pct(white_wins)), + ("d", &pct(t.draws)), + ("b", &pct(black_wins)), + ], )); } } fn score_text(t: &Tally) -> String { - t.score().map_or_else(|| "—".to_owned(), |s| format!("{:.0} %", 100.0 * s)) + t.score() + .map_or_else(|| "—".to_owned(), |s| format!("{:.0} %", 100.0 * s)) } /// "+10 =1 −3". @@ -1271,15 +1360,15 @@ fn judgement_weight(j: Judgement) -> u32 { fn pill(ui: &mut Ui, j: Judgement) -> egui::Response { let text = review::judgement_symbol(j); let font = egui::FontId::proportional(11.0); - let galley = ui.painter().layout_no_wrap(text.to_owned(), font, Color32::WHITE); + let galley = ui + .painter() + .layout_no_wrap(text.to_owned(), font, Color32::WHITE); let size = vec2(galley.size().x + 8.0, 16.0); let (rect, resp) = ui.allocate_exact_size(size, Sense::hover()); - ui.painter().rect_filled(rect, 8.0, review::judgement_color(j)); - ui.painter().galley( - rect.center() - galley.size() / 2.0, - galley, - Color32::WHITE, - ); + ui.painter() + .rect_filled(rect, 8.0, review::judgement_color(j)); + ui.painter() + .galley(rect.center() - galley.size() / 2.0, galley, Color32::WHITE); resp } @@ -1321,7 +1410,12 @@ fn counts_text(ui: &mut Ui, c: &ErrorCounts) { } impl PrepScreen { - pub fn new(start: PrepStart, db: Arc, settings: &Settings, ctx: &egui::Context) -> Self { + pub fn new( + start: PrepStart, + db: Arc, + settings: &Settings, + ctx: &egui::Context, + ) -> Self { let dir = cache_dir(); let cache = dir.as_deref().map(PositionCache::load).unwrap_or_default(); let plies = settings.prep.plies.clamp(2, 60); @@ -1531,8 +1625,7 @@ impl PrepScreen { let Some(report) = &self.report else { return false; }; - self.book_fp.is_some() - && report.book.as_ref().map(|b| b.fingerprint) == self.book_fp + self.book_fp.is_some() && report.book.as_ref().map(|b| b.fingerprint) == self.book_fp } /// The judgement is shown (inaccuracies can be hidden). @@ -1577,22 +1670,35 @@ impl PrepScreen { /// rebuilt, so a chosen error is found again in them by what it is, not by its /// place (else the choice is dropped). fn rejudge(&mut self, f: impl FnOnce(&mut PrepReport)) { - let Some(report) = self.report.as_mut() else { return }; + let Some(report) = self.report.as_mut() else { + return; + }; // What the selection and the errors tab's row are, by content. let error_id = |r: &PrepReport, white: bool, i: usize| { r.color(white).errors.get(i).map(|e| (e.game, e.ply)) }; let repeated_id = |r: &PrepReport, white: bool, i: usize| { - r.color(white).repeated.get(i).map(|x| (x.key, x.uci.clone())) + r.color(white) + .repeated + .get(i) + .map(|x| (x.key, x.uci.clone())) }; let sel = match &self.selection { - Selection::Error { white, index } => error_id(report, *white, *index).map(|id| (*white, Ok(id))), - Selection::Repeated { white, index } => repeated_id(report, *white, *index).map(|id| (*white, Err(id))), + Selection::Error { white, index } => { + error_id(report, *white, *index).map(|id| (*white, Ok(id))) + } + Selection::Repeated { white, index } => { + repeated_id(report, *white, *index).map(|id| (*white, Err(id))) + } _ => None, }; let cursor = match self.err_cursor { - Some(ErrRow::Error { white, index }) => error_id(report, white, index).map(|id| (white, Ok(id))), - Some(ErrRow::Repeated { white, index }) => repeated_id(report, white, index).map(|id| (white, Err(id))), + Some(ErrRow::Error { white, index }) => { + error_id(report, white, index).map(|id| (white, Ok(id))) + } + Some(ErrRow::Repeated { white, index }) => { + repeated_id(report, white, index).map(|id| (white, Err(id))) + } _ => None, }; let open: Vec<(bool, (u64, String))> = self @@ -1601,17 +1707,34 @@ impl PrepScreen { .filter_map(|&(w, i)| repeated_id(report, w, i).map(|id| (w, id))) .collect(); f(report); - let find = |r: &PrepReport, white: bool, id: &Result<(u32, u32), (u64, String)>| -> Option { + let find = |r: &PrepReport, + white: bool, + id: &Result<(u32, u32), (u64, String)>| + -> Option { match id { - Ok((game, ply)) => r.color(white).errors.iter().position(|e| e.game == *game && e.ply == *ply), - Err((key, uci)) => r.color(white).repeated.iter().position(|x| x.key == *key && x.uci == *uci), + Ok((game, ply)) => r + .color(white) + .errors + .iter() + .position(|e| e.game == *game && e.ply == *ply), + Err((key, uci)) => r + .color(white) + .repeated + .iter() + .position(|x| x.key == *key && x.uci == *uci), } }; if let Some((white, id)) = &sel { let found = find(report, *white, id); self.selection = match (found, id) { - (Some(index), Ok(_)) => Selection::Error { white: *white, index }, - (Some(index), Err(_)) => Selection::Repeated { white: *white, index }, + (Some(index), Ok(_)) => Selection::Error { + white: *white, + index, + }, + (Some(index), Err(_)) => Selection::Repeated { + white: *white, + index, + }, (None, _) => Selection::None, }; if found.is_none() { @@ -1620,8 +1743,14 @@ impl PrepScreen { } if let Some((white, id)) = &cursor { self.err_cursor = match (find(report, *white, id), id) { - (Some(index), Ok(_)) => Some(ErrRow::Error { white: *white, index }), - (Some(index), Err(_)) => Some(ErrRow::Repeated { white: *white, index }), + (Some(index), Ok(_)) => Some(ErrRow::Error { + white: *white, + index, + }), + (Some(index), Err(_)) => Some(ErrRow::Repeated { + white: *white, + index, + }), (None, _) => None, }; } else if matches!(self.err_cursor, Some(ErrRow::RepeatedGame { .. })) { @@ -1630,7 +1759,11 @@ impl PrepScreen { self.open_repeated = open .into_iter() .filter_map(|(w, (key, uci))| { - let i = report.color(w).repeated.iter().position(|x| x.key == key && x.uci == uci)?; + let i = report + .color(w) + .repeated + .iter() + .position(|x| x.key == key && x.uci == uci)?; Some((w, i)) }) .collect(); @@ -1694,7 +1827,10 @@ impl PrepScreen { } } None => { - self.book_failed = Some((fp, tr("the position search failed (not enough memory?)").to_owned())) + self.book_failed = Some(( + fp, + tr("the position search failed (not enough memory?)").to_owned(), + )) } } } @@ -1790,7 +1926,12 @@ impl PrepScreen { } /// The button: the dialog the first time, at once with the colour chosen before. - fn engine_asked(&mut self, settings: &Settings, ctx: &egui::Context, actions: &mut Vec) { + fn engine_asked( + &mut self, + settings: &Settings, + ctx: &egui::Context, + actions: &mut Vec, + ) { if crate::engines::own_stockfish().is_none() { actions.push(PrepAction::NeedEngine); return; @@ -1815,10 +1956,14 @@ impl PrepScreen { self.rejudge(|r| taken = r.take_cached(&cache)); self.cache = cache; self.dirty |= taken > 0; - let Some(report) = self.report.as_ref() else { return }; + let Some(report) = self.report.as_ref() else { + return; + }; let targets = report.targets_for(self.color.side()); if targets.is_empty() { - actions.push(PrepAction::Toast(tr("Every position is already evaluated").to_owned())); + actions.push(PrepAction::Toast( + tr("Every position is already evaluated").to_owned(), + )); self.tab = Tab::Errors; return; } @@ -1869,7 +2014,9 @@ impl PrepScreen { fn poll_engine(&mut self, ctx: &egui::Context, actions: &mut Vec) { let Some(job) = self.job.as_mut() else { return }; - let Some(report) = self.report.as_mut() else { return }; + let Some(report) = self.report.as_mut() else { + return; + }; let mut ended = false; let mut got = false; while let Ok(msg) = job.rx.try_recv() { @@ -1950,7 +2097,12 @@ impl PrepScreen { } /// The launch dialog (§4.2). - fn engine_dialog(&mut self, ctx: &egui::Context, settings: &mut Settings, actions: &mut Vec) { + fn engine_dialog( + &mut self, + ctx: &egui::Context, + settings: &mut Settings, + actions: &mut Vec, + ) { if !self.dialog_open { return; } @@ -2112,7 +2264,8 @@ impl PrepScreen { if g.opening.is_none() { continue; } - let ply = family_ply(g, &fam.name).unwrap_or(g.named.unwrap_or(0) as usize); + let ply = family_ply(g, &fam.name) + .unwrap_or(g.named.unwrap_or(0) as usize); if best.is_none_or(|(_, p)| ply < p) { best = Some((g, ply)); } @@ -2130,7 +2283,15 @@ impl PrepScreen { let r = cr.repeated.get(*index)?; let g = &report.games[*r.games.first()? as usize]; let mut s = from_game(g, r.ply as usize, *white); - s.arrows = error_arrows(&s.positions[s.ply], &r.uci, cr.errors.iter().find(|e| e.key == r.key && e.uci == r.uci).map(|e| e.best_uci.as_str()), r.judgement); + s.arrows = error_arrows( + &s.positions[s.ply], + &r.uci, + cr.errors + .iter() + .find(|e| e.key == r.key && e.uci == r.uci) + .map(|e| e.best_uci.as_str()), + r.judgement, + ); s.note = cr .errors .iter() @@ -2144,7 +2305,8 @@ impl PrepScreen { let e = cr.errors.get(*index)?; let g = &report.games[e.game as usize]; let mut s = from_game(g, e.ply as usize, *white); - s.arrows = error_arrows(&s.positions[s.ply], &e.uci, Some(&e.best_uci), e.judgement); + s.arrows = + error_arrows(&s.positions[s.ply], &e.uci, Some(&e.best_uci), e.judgement); s.note = Some(error_note(e)); s.opening = e.opening; Some(s) @@ -2181,8 +2343,16 @@ impl PrepScreen { .families .get(*family) .map(|f| match variation { - Some(v) => f.variations.get(*v).map(|v| v.games.clone()).unwrap_or_default(), - None => f.variations.iter().flat_map(|v| v.games.iter().copied()).collect(), + Some(v) => f + .variations + .get(*v) + .map(|v| v.games.clone()) + .unwrap_or_default(), + None => f + .variations + .iter() + .flat_map(|v| v.games.iter().copied()) + .collect(), }) .unwrap_or_default(), Selection::Repeated { white, index } => report @@ -2209,17 +2379,23 @@ impl PrepScreen { GameSort::BlackElo => num(r.black_elo), GameSort::Result => SortVal::Text(r.result.to_owned()), GameSort::Date => num(g.date_number()), - GameSort::Then => SortVal::Text(g.sans.iter().skip(self.game_ply(gi)).take(3).cloned().collect::>().join(" ")), - GameSort::Event => SortVal::Text(fold(&r.event)), - GameSort::Errors => num( - report - .color(g.white) - .errors + GameSort::Then => SortVal::Text( + g.sans .iter() - .filter(|e| e.game == gi && self.visible(e.judgement)) - .map(|e| judgement_weight(e.judgement)) - .sum::(), + .skip(self.game_ply(gi)) + .take(3) + .cloned() + .collect::>() + .join(" "), ), + GameSort::Event => SortVal::Text(fold(&r.event)), + GameSort::Errors => num(report + .color(g.white) + .errors + .iter() + .filter(|e| e.game == gi && self.visible(e.judgement)) + .map(|e| judgement_weight(e.judgement)) + .sum::()), } }; let mut keyed: Vec<(SortVal, u32)> = list.into_iter().map(|g| (val(g), g)).collect(); @@ -2237,7 +2413,10 @@ impl PrepScreen { fn game_ply(&self, gi: u32) -> usize { if let (Selection::Node { white, node }, Some(report)) = (&self.selection, &self.report) && let Some(n) = report.color(*white).tree.nodes.get(*node as usize) - && let Some(p) = report.games[gi as usize].keys.iter().position(|k| *k == n.key) + && let Some(p) = report.games[gi as usize] + .keys + .iter() + .position(|k| *k == n.key) { return p; } @@ -2246,7 +2425,10 @@ impl PrepScreen { /// The move to open game `gi` at: the chosen position, or after the error. fn open_ply(&self, gi: u32) -> usize { - let after = matches!(self.selection, Selection::Error { .. } | Selection::Repeated { .. }); + let after = matches!( + self.selection, + Selection::Error { .. } | Selection::Repeated { .. } + ); self.game_ply(gi) + usize::from(after) } @@ -2307,12 +2489,17 @@ impl PrepScreen { ui.add_space(4.0); }); } - egui::CentralPanel::default().show(ui, |ui| self.right_column(ui, settings, &mut actions)); + egui::CentralPanel::default() + .show(ui, |ui| self.right_column(ui, settings, &mut actions)); if low && self.board_popup { self.board_overlay(&ctx, settings, &mut actions); } } else { - let board_side = (h - 120.0).min(420.0).min(w - BOARD_MIN - 24.0 - RIGHT_MIN + BOARD_MIN).max(BOARD_MIN).floor(); + let board_side = (h - 120.0) + .min(420.0) + .min(w - BOARD_MIN - 24.0 - RIGHT_MIN + BOARD_MIN) + .max(BOARD_MIN) + .floor(); egui::Panel::left("prep_board") .exact_size(board_side + 24.0) .resizable(false) @@ -2324,7 +2511,8 @@ impl PrepScreen { self.board_info(ui, &mut actions); }); }); - egui::CentralPanel::default().show(ui, |ui| self.right_column(ui, settings, &mut actions)); + egui::CentralPanel::default() + .show(ui, |ui| self.right_column(ui, settings, &mut actions)); } self.engine_dialog(&ctx, settings, &mut actions); if !typing && !overlay { @@ -2340,7 +2528,9 @@ impl PrepScreen { fn header(&mut self, ui: &mut Ui, actions: &mut Vec) { let gap = ui.spacing().item_spacing.x; let button_w = |ui: &Ui, text: &str| { - text_width(ui, text, egui::TextStyle::Button) + 2.0 * ui.spacing().button_padding.x + gap + text_width(ui, text, egui::TextStyle::Button) + + 2.0 * ui.spacing().button_padding.x + + gap }; let row = ui.available_width(); let compact = row < 700.0; @@ -2382,10 +2572,14 @@ impl PrepScreen { } let skipped = self.report.as_ref().map_or(0, |r| r.skipped); let r = ui.add( - egui::Label::new(RichText::new(format!("· {}", parts.join(" · "))).weak()).truncate(), + egui::Label::new(RichText::new(format!("· {}", parts.join(" · "))).weak()) + .truncate(), ); if skipped > 0 { - r.on_hover_text(trf("not counted: from a set position — {n}", &[("n", &skipped)])); + r.on_hover_text(trf( + "not counted: from a set position — {n}", + &[("n", &skipped)], + )); } }); }); @@ -2402,7 +2596,13 @@ impl PrepScreen { } /// The colour switch, the book, the depth and the engine button or its progress. - fn controls(&mut self, ui: &mut Ui, settings: &mut Settings, low: bool, actions: &mut Vec) { + fn controls( + &mut self, + ui: &mut Ui, + settings: &mut Settings, + low: bool, + actions: &mut Vec, + ) { let width = ui.available_width(); let gap = ui.spacing().item_spacing.x; let pad = 2.0 * ui.spacing().button_padding.x; @@ -2410,17 +2610,28 @@ impl PrepScreen { // The engine part on the right is measured first: the rest gets what it leaves. let engine = self.engine_texts(state, width); let engine_w = match &engine { - EngineTexts::Running => (width * 0.35).clamp(90.0, 360.0) + text_width(ui, tr("Stop"), egui::TextStyle::Button) + pad + 2.0 * gap, + EngineTexts::Running => { + (width * 0.35).clamp(90.0, 360.0) + + text_width(ui, tr("Stop"), egui::TextStyle::Button) + + pad + + 2.0 * gap + } EngineTexts::Button { label, note } | EngineTexts::Done { label, note } => { text_width(ui, label, egui::TextStyle::Button) + pad - + note.as_deref().map_or(0.0, |n| text_width(ui, n, egui::TextStyle::Body) + gap) + + note + .as_deref() + .map_or(0.0, |n| text_width(ui, n, egui::TextStyle::Body) + gap) + gap } - } + 26.0 + gap; + } + 26.0 + + gap; ui.horizontal(|ui| { for choice in [ColorChoice::White, ColorChoice::Black, ColorChoice::Both] { - if ui.selectable_label(self.color == choice, choice.label()).clicked() { + if ui + .selectable_label(self.color == choice, choice.label()) + .clicked() + { self.set_color(choice); } } @@ -2430,7 +2641,15 @@ impl PrepScreen { ui.label(tr("Book")); } let book_w = if width < 900.0 { 150.0 } else { 240.0 }; - if let Some(b) = book_picker(ui, "prep_book", &self.book, &self.path, &self.dbs, book_w, !caption_apart) { + if let Some(b) = book_picker( + ui, + "prep_book", + &self.book, + &self.path, + &self.dbs, + book_w, + !caption_apart, + ) { self.book = b; self.book_failed = None; self.book_asked = None; @@ -2444,7 +2663,11 @@ impl PrepScreen { ui.separator(); // The depth's caption by the room left: «Opening: 10 moves», «10 moves», «10 m.». let moves = self.plies.div_ceil(2); - let board_w = if low { text_width(ui, "♙", egui::TextStyle::Button) + pad + 2.0 * gap } else { 0.0 }; + let board_w = if low { + text_width(ui, "♙", egui::TextStyle::Button) + pad + 2.0 * gap + } else { + 0.0 + }; let room = ui.available_width() - engine_w - board_w; let depth_label = [ trf("Opening: {n} moves", &[("n", &moves)]), @@ -2460,7 +2683,10 @@ impl PrepScreen { .show_ui(ui, |ui| { for m in [6usize, 10, 15] { if ui - .selectable_label(self.plies == m * 2, trf("Opening: {n} moves", &[("n", &m)])) + .selectable_label( + self.plies == m * 2, + trf("Opening: {n} moves", &[("n", &m)]), + ) .clicked() { new_plies = Some(m * 2); @@ -2553,7 +2779,11 @@ impl PrepScreen { } else { trf( "Finding errors: {done} of {total} positions · ≈ {time}", - &[("done", &grouped(done)), ("total", &grouped(total)), ("time", &review::format_duration(secs))], + &[ + ("done", &grouped(done)), + ("total", &grouped(total)), + ("time", &review::format_duration(secs)), + ], ) }; ui.add( @@ -2573,7 +2803,10 @@ impl PrepScreen { ui.label(RichText::new(label).weak()).on_hover_text(hint); } EngineTexts::Button { label, note } => { - if crate::widgets::primary(ui, &label).on_hover_text(hint).clicked() { + if crate::widgets::primary(ui, &label) + .on_hover_text(hint) + .clicked() + { self.engine_asked(settings, ui.ctx(), actions); } if let Some(n) = note { @@ -2595,13 +2828,15 @@ impl PrepScreen { return None; } let n = grouped(report.distinct_positions_for(self.color.side())); - Some(match report.engine.as_ref().filter(|e| !e.name.is_empty()) { - Some(e) => trf( - "Errors found · {engine} · {n} positions", - &[("engine", &e.name), ("n", &n)], - ), - None => trf("Errors found · {n} positions", &[("n", &n)]), - }) + Some( + match report.engine.as_ref().filter(|e| !e.name.is_empty()) { + Some(e) => trf( + "Errors found · {engine} · {n} positions", + &[("engine", &e.name), ("n", &n)], + ), + None => trf("Errors found · {n} positions", &[("n", &n)]), + }, + ) } /// The summary: a row per colour in columns — colour, games, score, opponents, @@ -2609,7 +2844,11 @@ impl PrepScreen { /// last game, the book, the opponents) instead of wrapping. fn summary(&self, ui: &mut Ui, stacked: bool) { let Some(report) = &self.report else { return }; - let colours = if stacked { self.color.colours() } else { vec![true, false] }; + let colours = if stacked { + self.color.colours() + } else { + vec![true, false] + }; let evaluated = report.evaluated() && !stacked; let book = self.book_ok(); // Texts per colour: [games, score, opponents, last, book]. @@ -2618,7 +2857,11 @@ impl PrepScreen { let cr = report.color(white); let root = &cr.tree.nodes[0]; let tally = &root.tally; - let title = if white { tr("As White") } else { tr("As Black") }; + let title = if white { + tr("As White") + } else { + tr("As Black") + }; let games = format!("{title} {}", tally.games); let score = if tally.games > 0 { format!("{} ({})", score_text(tally), tally_hint(tally)) @@ -2630,7 +2873,11 @@ impl PrepScreen { .map(|elo| trf("opponents ≈ {elo}", &[("elo", &elo)])) .unwrap_or_default(); let last = crate::library::display_date(&root.last_date); - let last = if last.is_empty() { String::new() } else { trf("last {date}", &[("date", &last)]) }; + let last = if last.is_empty() { + String::new() + } else { + trf("last {date}", &[("date", &last)]) + }; let book_text = if book { let mut plies: Vec = cr .games @@ -2661,7 +2908,12 @@ impl PrepScreen { .map(|e| e.game) .collect(); let p = 100 * with_errors.len() / cr.games.len().max(1); - rows.push((white, [games, score, opponents, last, book_text], self.shown_counts(&cr.counts), p)); + rows.push(( + white, + [games, score, opponents, last, book_text], + self.shown_counts(&cr.counts), + p, + )); } // Which columns fit: the errors stay; last, book, opponents give way in turn. let gap = 14.0; @@ -2673,7 +2925,13 @@ impl PrepScreen { let errors_w = if evaluated { rows.iter() .map(|(_, _, c, p)| { - errors_text_width(ui, c) + text_width(ui, &trf("in {p} % of games", &[("p", p)]), egui::TextStyle::Body) + 12.0 + errors_text_width(ui, c) + + text_width( + ui, + &trf("in {p} % of games", &[("p", p)]), + egui::TextStyle::Body, + ) + + 12.0 }) .fold(0.0, f32::max) } else { @@ -2682,7 +2940,11 @@ impl PrepScreen { let width = ui.available_width(); let mut shown = [true; 5]; let used = |shown: &[bool; 5]| -> f32 { - (0..5).filter(|&k| shown[k]).map(|k| col_w(k) + gap).sum::() + errors_w + (0..5) + .filter(|&k| shown[k]) + .map(|k| col_w(k) + gap) + .sum::() + + errors_w }; for k in [3, 4, 2, 1] { if used(&shown) <= width { @@ -2709,7 +2971,9 @@ impl PrepScreen { ui.spacing_mut().item_spacing.x = 4.0; if counts.total() > 0 { counts_text(ui, counts); - ui.label(RichText::new(trf("in {p} % of games", &[("p", p)])).weak()); + ui.label( + RichText::new(trf("in {p} % of games", &[("p", p)])).weak(), + ); } else { ui.label(RichText::new(tr("no errors")).weak()); } @@ -2771,7 +3035,11 @@ impl PrepScreen { } else { tr("Black to move") }; - match s.ply.checked_sub(1).and_then(|p| s.sans.get(p).map(|san| short_label(p, san))) { + match s + .ply + .checked_sub(1) + .and_then(|p| s.sans.get(p).map(|san| short_label(p, san))) + { Some(m) => format!("{side} · {}", trf("after {move}", &[("move", &m)])), None => side.to_owned(), } @@ -2783,43 +3051,52 @@ impl PrepScreen { fn board(&mut self, ui: &mut Ui, settings: &Settings, side: f32) { let start = Chess::default(); - let (pos, last_move, arrows): (&Chess, Option<(Square, Square)>, Vec) = match &self.shown_pos { - Some(s) => { - let pos = &s.positions[s.ply]; - let last = s - .ply - .checked_sub(1) - .and_then(|p| s.ucis.get(p)) - .and_then(|u| u.parse::().ok()) - .and_then(|u| u.to_move(&s.positions[s.ply - 1]).ok()) - .and_then(|m| Some((m.from()?, crate::board::ui_target(&m)))); - let mut arrows = if s.ply + 1 == s.positions.len() { s.arrows.clone() } else { Vec::new() }; - if let Some((from, to)) = self.hover_arrow { - arrows.push(Arrow { - from, - to, - color: PREVIEW_ARROW, - weight: 1.0, - }); + let (pos, last_move, arrows): (&Chess, Option<(Square, Square)>, Vec) = + match &self.shown_pos { + Some(s) => { + let pos = &s.positions[s.ply]; + let last = s + .ply + .checked_sub(1) + .and_then(|p| s.ucis.get(p)) + .and_then(|u| u.parse::().ok()) + .and_then(|u| u.to_move(&s.positions[s.ply - 1]).ok()) + .and_then(|m| Some((m.from()?, crate::board::ui_target(&m)))); + let mut arrows = if s.ply + 1 == s.positions.len() { + s.arrows.clone() + } else { + Vec::new() + }; + if let Some((from, to)) = self.hover_arrow { + arrows.push(Arrow { + from, + to, + color: PREVIEW_ARROW, + weight: 1.0, + }); + } + (pos, last, arrows) } - (pos, last, arrows) - } - None => { - let mut arrows = Vec::new(); - if let Some((from, to)) = self.hover_arrow { - arrows.push(Arrow { - from, - to, - color: PREVIEW_ARROW, - weight: 1.0, - }); + None => { + let mut arrows = Vec::new(); + if let Some((from, to)) = self.hover_arrow { + arrows.push(Arrow { + from, + to, + color: PREVIEW_ARROW, + weight: 1.0, + }); + } + (&start, None, arrows) } - (&start, None, arrows) - } - }; + }; let view = BoardView { pos, - orientation: if self.board_white() { Color::White } else { Color::Black }, + orientation: if self.board_white() { + Color::White + } else { + Color::Black + }, last_move, arrows: &arrows, circles: &[], @@ -2844,7 +3121,12 @@ impl PrepScreen { ui.add_space(4.0); let Some(report) = &self.report else { return }; let Some(s) = &self.shown_pos else { - ui.label(RichText::new(tr("Choose a move in the tree, an opening or an error: its position is shown here")).weak()); + ui.label( + RichText::new(tr( + "Choose a move in the tree, an opening or an error: its position is shown here", + )) + .weak(), + ); return; }; let mut goto = None; @@ -2866,18 +3148,31 @@ impl PrepScreen { } else { RichText::new(label) }; - if ui.add(egui::Label::new(text).sense(Sense::click())).clicked() { + if ui + .add(egui::Label::new(text).sense(Sense::click())) + .clicked() + { goto = Some(i + 1); } } }); if let Some(o) = s.opening.and_then(|o| report.openings.get(o)) { - ui.label(RichText::new(format!("{} · {}", o.name, o.eco)).weak().small()); + ui.label( + RichText::new(format!("{} · {}", o.name, o.eco)) + .weak() + .small(), + ); } if let Some(note) = &s.note { ui.label(RichText::new(note).small()); } - let (sans, ucis, pos, white, ply) = (s.sans.clone(), s.ucis.clone(), s.positions[s.ply].clone(), s.white, s.ply); + let (sans, ucis, pos, white, ply) = ( + s.sans.clone(), + s.ucis.clone(), + s.positions[s.ply].clone(), + s.white, + s.ply, + ); ui.horizontal(|ui| { if ui .button(tr("Open as a game")) @@ -2899,7 +3194,9 @@ impl PrepScreen { }) .collect() }; - let last = moves.last().and_then(|m| Some((m.from()?, crate::board::ui_target(m)))); + let last = moves + .last() + .and_then(|m| Some((m.from()?, crate::board::ui_target(m)))); let after = ply.checked_sub(1).map(|p| prep::move_label(p, &sans[p])); actions.push(PrepAction::PlayFrom(Box::new(crate::play::StartFrom { start_fen: None, @@ -2913,7 +3210,10 @@ impl PrepScreen { }))); ui.close(); } - if ui.button(tr("Find this position in a database (Ctrl+Shift+F)")).clicked() { + if ui + .button(tr("Find this position in a database (Ctrl+Shift+F)")) + .clicked() + { let mut p = Chess::default(); let moves: Vec = ucis[..ply] .iter() @@ -2923,16 +3223,26 @@ impl PrepScreen { Some(m) }) .collect(); - actions.push(PrepAction::FindPosition(self.path.clone(), Chess::default(), moves, !self.board_white())); + actions.push(PrepAction::FindPosition( + self.path.clone(), + Chess::default(), + moves, + !self.board_white(), + )); ui.close(); } if ui.button(tr("Copy FEN")).clicked() { - let fen = shakmaty::fen::Fen::from_position(&pos, shakmaty::EnPassantMode::Legal).to_string(); + let fen = + shakmaty::fen::Fen::from_position(&pos, shakmaty::EnPassantMode::Legal) + .to_string(); actions.push(PrepAction::CopyText(fen, tr("FEN copied"))); ui.close(); } if ui.button(tr("Copy moves (PGN)")).clicked() { - actions.push(PrepAction::CopyText(self.line_pgn(&sans[..ply], white), tr("PGN copied"))); + actions.push(PrepAction::CopyText( + self.line_pgn(&sans[..ply], white), + tr("PGN copied"), + )); ui.close(); } }); @@ -2948,7 +3258,11 @@ impl PrepScreen { /// The line as a PGN game: the player on his side, the opponent unnamed. fn line_pgn(&self, sans: &[String], white: bool) -> String { let name = self.names.first().cloned().unwrap_or_default(); - let (w, b) = if white { (name, "?".to_owned()) } else { ("?".to_owned(), name) }; + let (w, b) = if white { + (name, "?".to_owned()) + } else { + ("?".to_owned(), name) + }; let mut moves = String::new(); for (i, san) in sans.iter().enumerate() { if i.is_multiple_of(2) { @@ -2957,11 +3271,19 @@ impl PrepScreen { moves.push_str(san); moves.push(' '); } - format!("[Event \"{}\"]\n[White \"{w}\"]\n[Black \"{b}\"]\n[Result \"*\"]\n\n{moves}*\n", self.title()) + format!( + "[Event \"{}\"]\n[White \"{w}\"]\n[Black \"{b}\"]\n[Result \"*\"]\n\n{moves}*\n", + self.title() + ) } /// In a low window: the board over the right bottom of the screen. - fn board_overlay(&mut self, ctx: &egui::Context, settings: &Settings, actions: &mut Vec) { + fn board_overlay( + &mut self, + ctx: &egui::Context, + settings: &Settings, + actions: &mut Vec, + ) { let screen = ctx.content_rect(); let size = vec2(264.0, 300.0); let rect = egui::Rect::from_min_size(screen.right_bottom() - size, size); @@ -2986,7 +3308,9 @@ impl PrepScreen { if ui.button(tr("Open as a game")).clicked() && let Some(s) = &self.shown_pos { - actions.push(PrepAction::OpenPgn(self.line_pgn(&s.sans[..s.ply], s.white))); + actions.push(PrepAction::OpenPgn( + self.line_pgn(&s.sans[..s.ply], s.white), + )); } }); }); @@ -3001,11 +3325,20 @@ impl PrepScreen { /// The tabs over the games list, the border between them draggable. (A nested /// bottom panel would not do: in a top-down `Ui` egui's available rect ignores /// the cursor's bottom, so the content above overlaps it.) - fn right_column(&mut self, ui: &mut Ui, settings: &mut Settings, actions: &mut Vec) { + fn right_column( + &mut self, + ui: &mut Ui, + settings: &mut Settings, + actions: &mut Vec, + ) { let height = ui.available_height(); let width = ui.available_width(); // In a low window the tabs keep the most: two rows of games at least, a quarter. - let (rows, share) = if self.low_window { (2.0, 0.25) } else { (4.0, 0.35) }; + let (rows, share) = if self.low_window { + (2.0, 0.25) + } else { + (4.0, 0.35) + }; let least = rows * ROW_H + 60.0; let most = (height - 160.0).max(least); let games_h = self @@ -3014,11 +3347,15 @@ impl PrepScreen { .clamp(least, most) .floor(); let tabs_h = (height - games_h - 10.0).max(0.0); - ui.allocate_ui_with_layout(vec2(width, tabs_h), egui::Layout::top_down(egui::Align::Min), |ui| { - ui.set_min_height(tabs_h); - ui.set_max_height(tabs_h); - self.tabs(ui, settings, actions); - }); + ui.allocate_ui_with_layout( + vec2(width, tabs_h), + egui::Layout::top_down(egui::Align::Min), + |ui| { + ui.set_min_height(tabs_h); + ui.set_max_height(tabs_h); + self.tabs(ui, settings, actions); + }, + ); // The border: dragged, it gives the games list more or less. let (rect, resp) = ui.allocate_exact_size(vec2(width, 10.0), Sense::drag()); if resp.hovered() || resp.dragged() { @@ -3033,11 +3370,15 @@ impl PrepScreen { ui.visuals().widgets.noninteractive.bg_stroke }; ui.painter().hline(rect.x_range(), rect.center().y, stroke); - ui.allocate_ui_with_layout(vec2(width, games_h), egui::Layout::top_down(egui::Align::Min), |ui| { - ui.set_min_height(games_h); - ui.set_max_height(games_h); - self.games_list(ui, actions); - }); + ui.allocate_ui_with_layout( + vec2(width, games_h), + egui::Layout::top_down(egui::Align::Min), + |ui| { + ui.set_min_height(games_h); + ui.set_max_height(games_h); + self.games_list(ui, actions); + }, + ); } fn tabs(&mut self, ui: &mut Ui, settings: &mut Settings, actions: &mut Vec) { @@ -3048,7 +3389,8 @@ impl PrepScreen { (Tab::Openings, tr("Openings"), "Ctrl+2"), (Tab::Errors, tr("Errors"), "Ctrl+3"), ] { - ui.selectable_value(&mut self.tab, tab, label).on_hover_text(key); + ui.selectable_value(&mut self.tab, tab, label) + .on_hover_text(key); } if self.tab == Tab::Repertoire { ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { @@ -3063,7 +3405,11 @@ impl PrepScreen { .selected_text(trf("Branches from {n} games", &[("n", &n)])) .show_ui(ui, |ui| { for k in [2u32, 3, 5] { - ui.selectable_value(&mut n, k, trf("Branches from {n} games", &[("n", &k)])); + ui.selectable_value( + &mut n, + k, + trf("Branches from {n} games", &[("n", &k)]), + ); } }) .response @@ -3164,7 +3510,9 @@ impl PrepScreen { TreeSort::Games => num(tree.position_tally(m.key).games), TreeSort::Share => num(m.tally.games), TreeSort::Score => score_val(&tree.position_tally(m.key)), - TreeSort::Last => num(chess_import::pgn_catalog::date_number(tree.position_last_date(m.key))), + TreeSort::Last => num(chess_import::pgn_catalog::date_number( + tree.position_last_date(m.key), + )), } }; // Ties: most played first, as the tree has them. @@ -3208,7 +3556,9 @@ impl PrepScreen { if rows.len() <= 1 { self.no_games_note(ui); } - let Some(report) = self.report.as_ref() else { return }; + let Some(report) = self.report.as_ref() else { + return; + }; let width = ui.available_width(); let gap = ui.spacing().item_spacing.x; let has_book = self.book_ok() || (self.book_job.is_some() && self.book != BookChoice::None); @@ -3224,7 +3574,11 @@ impl PrepScreen { let show_bar = fits(64.0, true); let show_last = fits(84.0, true); let show_book = fits(80.0, has_book); - let book_title = if self.book == BookChoice::Same { tr("In database") } else { tr("Book") }; + let book_title = if self.book == BookChoice::Same { + tr("In database") + } else { + tr("Book") + }; ui.style_mut().interaction.selectable_labels = false; let mut table = TableBuilder::new(ui) .id_salt("prep_tree") @@ -3236,7 +3590,9 @@ impl PrepScreen { if show_opening { table = table.column(Column::remainder().at_least(160.0).clip(true)); } - table = table.column(Column::exact(76.0)).column(Column::exact(48.0)); + table = table + .column(Column::exact(76.0)) + .column(Column::exact(48.0)); table = table.column(Column::exact(if show_bar { 110.0 } else { 50.0 })); if show_last { table = table.column(Column::exact(84.0)); @@ -3245,7 +3601,13 @@ impl PrepScreen { table = table.column(Column::exact(80.0)); } let selected_row = rows.iter().position(|r| match (r, &self.selection) { - (TreeRow::Node { white, node, .. }, Selection::Node { white: sw, node: sn }) => white == sw && node == sn, + ( + TreeRow::Node { white, node, .. }, + Selection::Node { + white: sw, + node: sn, + }, + ) => white == sw && node == sn, _ => false, }); if self.scroll_to_selected @@ -3257,7 +3619,10 @@ impl PrepScreen { let mut clicked: Option = None; let mut toggled: Option = None; let mut hovered: Option<(bool, u32)> = None; - let threshold = report.book.as_ref().map_or(prep::DEFAULT_BOOK_THRESHOLD, |b| b.threshold); + let threshold = report + .book + .as_ref() + .map_or(prep::DEFAULT_BOOK_THRESHOLD, |b| b.threshold); let mut tree_click = None; table .header(ROW_H, |mut h| { @@ -3457,7 +3822,13 @@ impl PrepScreen { self.sorts.tree.click(k, false); } // A child of the chosen node under the pointer: its move as an arrow. - if let (Some((white, node)), Selection::Node { white: sw, node: sn }) = (hovered, &self.selection) + if let ( + Some((white, node)), + Selection::Node { + white: sw, + node: sn, + }, + ) = (hovered, &self.selection) && white == *sw { let cr = report.color(white); @@ -3465,7 +3836,11 @@ impl PrepScreen { if n.parent == Some(*sn) && let Some(s) = &self.shown_pos && s.ply + 1 == s.positions.len() - && let Some(m) = n.uci.parse::().ok().and_then(|u| u.to_move(&s.positions[s.ply]).ok()) + && let Some(m) = n + .uci + .parse::() + .ok() + .and_then(|u| u.to_move(&s.positions[s.ply]).ok()) { self.hover_arrow = m.from().map(|f| (f, crate::board::ui_target(&m))); } @@ -3505,11 +3880,22 @@ impl PrepScreen { return; } let other_n = report.color(other).games.len(); - let (colour, other_name) = if shown { (tr("White"), tr("Black")) } else { (tr("Black"), tr("White")) }; + let (colour, other_name) = if shown { + (tr("White"), tr("Black")) + } else { + (tr("Black"), tr("White")) + }; ui.add_space(12.0); ui.horizontal_wrapped(|ui| { - ui.label(trf("No games as {colour}. As {other} — {n}", &[("colour", &colour), ("other", &other_name), ("n", &other_n)])); - if other_n > 0 && ui.link(trf("Show {other}", &[("other", &other_name)])).clicked() { + ui.label(trf( + "No games as {colour}. As {other} — {n}", + &[("colour", &colour), ("other", &other_name), ("n", &other_n)], + )); + if other_n > 0 + && ui + .link(trf("Show {other}", &[("other", &other_name)])) + .clicked() + { self.color = ColorChoice::from_side(if other { Side::White } else { Side::Black }); } }); @@ -3535,27 +3921,33 @@ impl PrepScreen { let opening = |var: &prep::Variation| var.opening.and_then(|o| report.openings.get(o)); match key { OpeningSort::Name => SortVal::Text(match v { - Some(_) => vars[0].opening.map_or_else(String::new, |o| report.openings[o].name.clone()), + Some(_) => vars[0] + .opening + .map_or_else(String::new, |o| report.openings[o].name.clone()), None => fam.name.clone(), }), - OpeningSort::Eco => SortVal::Text(vars.iter().filter_map(|x| opening(x)).map(|o| o.eco.clone()).min().unwrap_or_default()), + OpeningSort::Eco => SortVal::Text( + vars.iter() + .filter_map(|x| opening(x)) + .map(|o| o.eco.clone()) + .min() + .unwrap_or_default(), + ), OpeningSort::Games | OpeningSort::Share => num(tally.games), OpeningSort::Score => score_val(&tally), - OpeningSort::Last => num( - vars.iter() - .flat_map(|x| x.games.iter()) - .map(|&g| report.games[g as usize].date_number()) - .max() - .unwrap_or(0), - ), - OpeningSort::Errors => num( - vars.iter() - .flat_map(|x| x.error_list.iter()) - .map(|&e| cr.errors[e as usize].judgement) - .filter(|j| self.visible(*j)) - .map(judgement_weight) - .sum::(), - ), + OpeningSort::Last => num(vars + .iter() + .flat_map(|x| x.games.iter()) + .map(|&g| report.games[g as usize].date_number()) + .max() + .unwrap_or(0)), + OpeningSort::Errors => num(vars + .iter() + .flat_map(|x| x.error_list.iter()) + .map(|&e| cr.errors[e as usize].judgement) + .filter(|j| self.visible(*j)) + .map(judgement_weight) + .sum::()), } } @@ -3595,7 +3987,9 @@ impl PrepScreen { fn openings_table(&mut self, ui: &mut Ui) { let rows = self.opening_rows(); - let Some(report) = self.report.as_ref() else { return }; + let Some(report) = self.report.as_ref() else { + return; + }; if rows.is_empty() { self.no_games_note(ui); return; @@ -3634,7 +4028,9 @@ impl PrepScreen { if show_moves { table = table.column(Column::remainder().at_least(140.0).clip(true)); } - table = table.column(Column::exact(76.0)).column(Column::exact(48.0)); + table = table + .column(Column::exact(76.0)) + .column(Column::exact(48.0)); table = table.column(Column::exact(if show_bar { 110.0 } else { 50.0 })); if show_last { table = table.column(Column::exact(84.0)); @@ -3643,7 +4039,12 @@ impl PrepScreen { table = table.column(Column::exact(90.0)); } let selected_row = rows.iter().position(|&(w, f, v)| { - self.selection == Selection::Opening { white: w, family: f, variation: v } + self.selection + == Selection::Opening { + white: w, + family: f, + variation: v, + } }); if self.scroll_to_selected && let Some(i) = selected_row @@ -3669,8 +4070,22 @@ impl PrepScreen { head_col(&mut h, tr("First moves"), ""); } sort_col(&mut h, tr("Games"), "", OpeningSort::Games, sort, c); - sort_col(&mut h, "%", tr("Share of the colour's games; a variation's — of its family's"), OpeningSort::Share, sort, c); - sort_col(&mut h, tr("Score"), tr("The opponent's points in these games"), OpeningSort::Score, sort, c); + sort_col( + &mut h, + "%", + tr("Share of the colour's games; a variation's — of its family's"), + OpeningSort::Share, + sort, + c, + ); + sort_col( + &mut h, + tr("Score"), + tr("The opponent's points in these games"), + OpeningSort::Score, + sort, + c, + ); if show_last { sort_col(&mut h, tr("Last"), "", OpeningSort::Last, sort, c); } @@ -3690,14 +4105,25 @@ impl PrepScreen { let var = &fam.variations[v]; (&var.tally, &var.errors, var.games.clone()) } - None => (&fam.tally, &fam.errors, fam.variations.iter().flat_map(|v| v.games.iter().copied()).collect()), + None => ( + &fam.tally, + &fam.errors, + fam.variations + .iter() + .flat_map(|v| v.games.iter().copied()) + .collect(), + ), }; let few = tally.games < FEW_GAMES; if both { row.col(|ui| { if v.is_none() { ui.label(RichText::new(if white { "♙" } else { "♟" }).weak()) - .on_hover_text(if white { tr("As White") } else { tr("As Black") }); + .on_hover_text(if white { + tr("As White") + } else { + tr("As Black") + }); } }); } @@ -3705,10 +4131,20 @@ impl PrepScreen { None => { let open = self.open_families.contains(&(white, f)); let glyph = if open { "▾" } else { "▸" }; - if ui.add(egui::Label::new(RichText::new(glyph).weak()).sense(Sense::click())).clicked() { + if ui + .add( + egui::Label::new(RichText::new(glyph).weak()) + .sense(Sense::click()), + ) + .clicked() + { toggled = Some((white, f)); } - let name = if fam.name.is_empty() { tr("no name").to_owned() } else { fam.name.clone() }; + let name = if fam.name.is_empty() { + tr("no name").to_owned() + } else { + fam.name.clone() + }; ui.add(egui::Label::new(RichText::new(name).strong()).truncate()); } Some(v) => { @@ -3716,7 +4152,9 @@ impl PrepScreen { let name = fam.variations[v] .opening .and_then(|o| report.openings.get(o)) - .map(|o| o.variation().map_or_else(|| o.name.clone(), str::to_owned)); + .map(|o| { + o.variation().map_or_else(|| o.name.clone(), str::to_owned) + }); match name { Some(n) => { ui.add(egui::Label::new(n).truncate()); @@ -3730,12 +4168,17 @@ impl PrepScreen { if show_eco { row.col(|ui| { let eco = match v { - Some(v) => fam.variations[v].opening.and_then(|o| report.openings.get(o)).map(|o| o.eco.clone()), + Some(v) => fam.variations[v] + .opening + .and_then(|o| report.openings.get(o)) + .map(|o| o.eco.clone()), None => { let mut ecos: Vec<&str> = fam .variations .iter() - .filter_map(|v| v.opening.and_then(|o| report.openings.get(o))) + .filter_map(|v| { + v.opening.and_then(|o| report.openings.get(o)) + }) .map(|o| o.eco.as_str()) .collect(); ecos.sort_unstable(); @@ -3755,7 +4198,10 @@ impl PrepScreen { if show_moves { row.col(|ui| { let line = match v { - Some(v) => fam.variations[v].opening.and_then(|o| report.openings.get(o)).map(|o| o.line.clone()), + Some(v) => fam.variations[v] + .opening + .and_then(|o| report.openings.get(o)) + .map(|o| o.line.clone()), None => family_line(report, fam), }; if let Some(l) = line { @@ -3780,7 +4226,8 @@ impl PrepScreen { }); row.col(|ui| { let t = RichText::new(score_text(tally)); - ui.label(if few { t.weak() } else { t }).on_hover_text(tally_hint(tally)); + ui.label(if few { t.weak() } else { t }) + .on_hover_text(tally_hint(tally)); if show_bar { score_bar(ui, tally, white, few); } @@ -3793,7 +4240,14 @@ impl PrepScreen { .max_by_key(|g| g.date_number()) .map(|g| crate::library::display_date(&g.date)) .unwrap_or_default(); - ui.label(RichText::new(if last.is_empty() { "—".to_owned() } else { last }).weak()); + ui.label( + RichText::new(if last.is_empty() { + "—".to_owned() + } else { + last + }) + .weak(), + ); }); } if show_errors { @@ -3811,7 +4265,9 @@ impl PrepScreen { }); }); if let Some(k) = opening_click { - self.sorts.openings.click(k, matches!(k, OpeningSort::Name | OpeningSort::Eco)); + self.sorts + .openings + .click(k, matches!(k, OpeningSort::Name | OpeningSort::Eco)); } if let Some(key) = toggled { if !self.open_families.remove(&key) { @@ -3819,20 +4275,31 @@ impl PrepScreen { } } else if let Some((white, family, variation)) = clicked { self.focus_games = false; - self.select(Selection::Opening { white, family, variation }); + self.select(Selection::Opening { + white, + family, + variation, + }); } } // ----- the errors ---------------------------------------------------------------- fn errors_tab(&mut self, ui: &mut Ui, settings: &mut Settings, actions: &mut Vec) { - let Some(report) = self.report.as_ref() else { return }; + let Some(report) = self.report.as_ref() else { + return; + }; let moves = self.plies.div_ceil(2); let state = self.engine_state(); if state == EngineState::NotRun { // The invitation (§5). let (positions, secs) = self.estimate(); - let games: usize = self.color.colours().iter().map(|&w| report.color(w).games.len()).sum(); + let games: usize = self + .color + .colours() + .iter() + .map(|&w| report.color(w).games.len()) + .sum(); let colour = match self.color { ColorChoice::White => tr("as White"), ColorChoice::Black => tr("as Black"), @@ -3873,7 +4340,9 @@ impl PrepScreen { )) .weak(), ); - ui.label(RichText::new(format!("· ≈ {}", review::format_duration(secs))).weak()); + ui.label( + RichText::new(format!("· ≈ {}", review::format_duration(secs))).weak(), + ); } } EngineState::Partial { done, total } => { @@ -3888,7 +4357,10 @@ impl PrepScreen { .on_hover_text(tr("The counts are of the checked positions")); ui.label(RichText::new("·").weak()); if ui - .link(trf("Continue ≈ {time}", &[("time", &review::format_duration(secs))])) + .link(trf( + "Continue ≈ {time}", + &[("time", &review::format_duration(secs))], + )) .clicked() { ask_engine = true; @@ -3903,7 +4375,9 @@ impl PrepScreen { } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { ui.checkbox(&mut inaccuracies, tr("Inaccuracies")) - .on_hover_text(tr("Show the inaccuracies (?!) with the mistakes and blunders")); + .on_hover_text(tr( + "Show the inaccuracies (?!) with the mistakes and blunders", + )); }); }); if inaccuracies != settings.prep.inaccuracies { @@ -3916,16 +4390,30 @@ impl PrepScreen { self.engine_asked(settings, ui.ctx(), actions); return; } - let Some(report) = self.report.as_ref() else { return }; + let Some(report) = self.report.as_ref() else { + return; + }; // The lines per colour: in the stack only (beside the board the summary has them). if self.stacked { for white in self.color.colours() { let cr = report.color(white); - let with: HashSet = cr.errors.iter().filter(|e| self.visible(e.judgement)).map(|e| e.game).collect(); + let with: HashSet = cr + .errors + .iter() + .filter(|e| self.visible(e.judgement)) + .map(|e| e.game) + .collect(); let p = 100 * with.len() / cr.games.len().max(1); ui.horizontal_wrapped(|ui| { ui.spacing_mut().item_spacing.x = 4.0; - ui.label(RichText::new(if white { tr("As White") } else { tr("As Black") }).strong()); + ui.label( + RichText::new(if white { + tr("As White") + } else { + tr("As Black") + }) + .strong(), + ); counts_text(ui, &self.shown_counts(&cr.counts)); ui.label(RichText::new(trf("in {p} % of games", &[("p", &p)])).weak()); }); @@ -3940,12 +4428,20 @@ impl PrepScreen { c.mistakes + c.blunders }) .sum(); - let inacc: u32 = self.color.colours().iter().map(|&w| report.color(w).counts.inaccuracies).sum(); + let inacc: u32 = self + .color + .colours() + .iter() + .map(|&w| report.color(w).counts.inaccuracies) + .sum(); if matches!(state, EngineState::Complete { .. }) && serious == 0 { let mut deeper = false; ui.add_space(8.0); ui.horizontal_wrapped(|ui| { - ui.label(trf("No errors in the first {n} moves ({i} inaccuracies).", &[("n", &moves), ("i", &inacc)])); + ui.label(trf( + "No errors in the first {n} moves ({i} inaccuracies).", + &[("n", &moves), ("i", &inacc)], + )); if self.plies < 30 && ui.link(trf("Deeper: {n} moves", &[("n", &15)])).clicked() { deeper = true; } @@ -3989,12 +4485,18 @@ impl PrepScreen { RepeatedSort::Move => num(r.ply), RepeatedSort::Times => num(r.games.len() as u32), RepeatedSort::Score => score_val(&r.tally), - RepeatedSort::Opening => SortVal::Text(r.opening.map_or_else(String::new, |o| report.openings[o].name.clone())), + RepeatedSort::Opening => SortVal::Text( + r.opening + .map_or_else(String::new, |o| report.openings[o].name.clone()), + ), } }; // Ties: the worst first. list.sort_by(|a, b| { - let (ra, rb) = (&report.color(a.0).repeated[a.1], &report.color(b.0).repeated[b.1]); + let (ra, rb) = ( + &report.color(a.0).repeated[a.1], + &report.color(b.0).repeated[b.1], + ); sort.apply(cmp_val(&val(a), &val(b))) .then(judgement_weight(rb.judgement).cmp(&judgement_weight(ra.judgement))) }); @@ -4047,18 +4549,27 @@ impl PrepScreen { let sort = self.sorts.variations; let val = |v: &(bool, usize, usize, u32)| -> u32 { match sort.key { - VariationSort::Games => report.color(v.0).families[v.1].variations[v.2].games.len() as u32, + VariationSort::Games => { + report.color(v.0).families[v.1].variations[v.2].games.len() as u32 + } VariationSort::Errors => v.3, } }; vars.sort_by(|a, b| sort.apply(val(a).cmp(&val(b))).then(b.3.cmp(&a.3))); for (white, family, variation, _) in vars { - rows.push(ErrRow::Variation { white, family, variation }); + rows.push(ErrRow::Variation { + white, + family, + variation, + }); if self.open_variations.contains(&(white, family, variation)) { let cr = report.color(white); for &e in &cr.families[family].variations[variation].error_list { if self.visible(cr.errors[e as usize].judgement) { - rows.push(ErrRow::Error { white, index: e as usize }); + rows.push(ErrRow::Error { + white, + index: e as usize, + }); } } } @@ -4081,11 +4592,17 @@ impl PrepScreen { self.focus_games = false; let sel = match row { ErrRow::Repeated { white, index } => Selection::Repeated { white, index }, - ErrRow::RepeatedGame { white, index, game } => match self.error_in(white, index, game) { - Some(e) => Selection::Error { white, index: e }, - None => return, - }, - ErrRow::Variation { white, family, variation } => Selection::Opening { + ErrRow::RepeatedGame { white, index, game } => { + match self.error_in(white, index, game) { + Some(e) => Selection::Error { white, index: e }, + None => return, + } + } + ErrRow::Variation { + white, + family, + variation, + } => Selection::Opening { white, family, variation: Some(variation), @@ -4105,12 +4622,17 @@ impl PrepScreen { let game = *self.repeated_games(white, index).first()?; (white, self.error_in(white, index, game)?) } - ErrRow::RepeatedGame { white, index, game } => (white, self.error_in(white, index, game)?), + ErrRow::RepeatedGame { white, index, game } => { + (white, self.error_in(white, index, game)?) + } ErrRow::Error { white, index } => (white, index), _ => return None, }; let e = report.color(white).errors.get(e)?; - Some((report.games[e.game as usize].index as usize, e.ply as usize + 1)) + Some(( + report.games[e.game as usize].index as usize, + e.ply as usize + 1, + )) } fn err_toggle(&mut self, row: ErrRow) { @@ -4120,7 +4642,11 @@ impl PrepScreen { self.open_repeated.insert((white, index)); } } - ErrRow::Variation { white, family, variation } => { + ErrRow::Variation { + white, + family, + variation, + } => { let k = (white, family, variation); if !self.open_variations.remove(&k) { self.open_variations.insert(k); @@ -4134,11 +4660,15 @@ impl PrepScreen { /// chooses, a double click (Enter) opens the game at the error. fn errors_table(&mut self, ui: &mut Ui, actions: &mut Vec) { let rows = self.err_rows(); - let Some(report) = self.report.as_ref() else { return }; + let Some(report) = self.report.as_ref() else { + return; + }; let both = self.color == ColorChoice::Both; let width = ui.available_width(); let show_last = width > 640.0; - let cursor = self.err_cursor.and_then(|c| rows.iter().position(|r| *r == c)); + let cursor = self + .err_cursor + .and_then(|c| rows.iter().position(|r| *r == c)); ui.style_mut().interaction.selectable_labels = false; let mut table = TableBuilder::new(ui) .id_salt("prep_errors") @@ -4166,13 +4696,23 @@ impl PrepScreen { let colour_icon = |ui: &mut Ui, white: bool| { if both { ui.label(RichText::new(if white { "♙" } else { "♟" }).weak()) - .on_hover_text(if white { tr("As White") } else { tr("As Black") }); + .on_hover_text(if white { + tr("As White") + } else { + tr("As Black") + }); } }; - let repeated_n = rows.iter().filter(|r| matches!(r, ErrRow::Repeated { .. })).count(); + let repeated_n = rows + .iter() + .filter(|r| matches!(r, ErrRow::Repeated { .. })) + .count(); let sorts = self.sorts.clone(); let mut sort_click: Option = None; - let openings_n = rows.iter().filter(|r| matches!(r, ErrRow::Variation { .. })).count(); + let openings_n = rows + .iter() + .filter(|r| matches!(r, ErrRow::Variation { .. })) + .count(); table.body(|body| { body.rows(ROW_H, rows.len(), |mut row| { let r = rows[row.index()]; @@ -4182,7 +4722,10 @@ impl PrepScreen { ErrRow::RepeatedTitle | ErrRow::OpeningsTitle => { let repeated = r == ErrRow::RepeatedTitle; let (title, empty) = if repeated { - (tr("Repeated errors — the same position, the same move"), repeated_n == 0) + ( + tr("Repeated errors — the same position, the same move"), + repeated_n == 0, + ) } else { (tr("By opening"), openings_n == 0) }; @@ -4200,14 +4743,23 @@ impl PrepScreen { (tr("Better"), None), ("×", Some(SortKeyOf::Repeated(RepeatedSort::Times))), (tr("Score"), Some(SortKeyOf::Repeated(RepeatedSort::Score))), - (tr("Opening"), Some(SortKeyOf::Repeated(RepeatedSort::Opening))), + ( + tr("Opening"), + Some(SortKeyOf::Repeated(RepeatedSort::Opening)), + ), ] } else { [ (tr("Played"), None), (tr("Better"), None), - (tr("Games"), Some(SortKeyOf::Variation(VariationSort::Games))), - (tr("Errors"), Some(SortKeyOf::Variation(VariationSort::Errors))), + ( + tr("Games"), + Some(SortKeyOf::Variation(VariationSort::Games)), + ), + ( + tr("Errors"), + Some(SortKeyOf::Variation(VariationSort::Errors)), + ), (tr("Date"), None), ] }; @@ -4216,8 +4768,10 @@ impl PrepScreen { row.col(|ui| match key { Some(key) => { let active = match key { - SortKeyOf::Repeated(k) => (sorts.repeated.key == *k).then_some(sorts.repeated.ascending), - SortKeyOf::Variation(k) => (sorts.variations.key == *k).then_some(sorts.variations.ascending), + SortKeyOf::Repeated(k) => (sorts.repeated.key == *k) + .then_some(sorts.repeated.ascending), + SortKeyOf::Variation(k) => (sorts.variations.key == *k) + .then_some(sorts.variations.ascending), }; if crate::widgets::sort_header(ui, c, active).clicked() { sort_click = Some(*key); @@ -4236,21 +4790,35 @@ impl PrepScreen { let g = &report.games[rep.games[0] as usize]; let open = self.open_repeated.contains(&(white, index)); row.col(|ui| { - if ui.add(egui::Label::new(weak(if open { "▾" } else { "▸" })).sense(Sense::click())).clicked() { + if ui + .add( + egui::Label::new(weak(if open { "▾" } else { "▸" })) + .sense(Sense::click()), + ) + .clicked() + { toggled = Some(r); } colour_icon(ui, white); let before = (rep.ply as usize) .checked_sub(1) .map(|p| short_label(p, &g.sans[p])) - .map_or_else(|| tr("start").to_owned(), |m| trf("after {move}", &[("move", &m)])); - let side = if rep.ply.is_multiple_of(2) { tr("White to move") } else { tr("Black to move") }; + .map_or_else( + || tr("start").to_owned(), + |m| trf("after {move}", &[("move", &m)]), + ); + let side = if rep.ply.is_multiple_of(2) { + tr("White to move") + } else { + tr("Black to move") + }; ui.add(egui::Label::new(format!("{before} · {side}")).truncate()); }); row.col(|ui| { ui.spacing_mut().item_spacing.x = 4.0; ui.label(short_label(rep.ply as usize, &rep.san)); - pill(ui, rep.judgement).on_hover_text(review::judgement_name(rep.judgement)); + pill(ui, rep.judgement) + .on_hover_text(review::judgement_name(rep.judgement)); }); row.col(|ui| { ui.label(short_label(rep.ply as usize, &rep.best_san)); @@ -4268,7 +4836,8 @@ impl PrepScreen { .and_then(|o| report.openings.get(o)) .map(|o| format!("{} · {}", o.name, o.eco)) .unwrap_or_default(); - ui.add(egui::Label::new(weak(&name)).truncate()).on_hover_text(name); + ui.add(egui::Label::new(weak(&name)).truncate()) + .on_hover_text(name); }); } } @@ -4278,7 +4847,9 @@ impl PrepScreen { let _ = (white, index); row.col(|ui| { ui.add_space(28.0); - ui.add(egui::Label::new(format!("{} — {}", lr.white, lr.black)).truncate()); + ui.add( + egui::Label::new(format!("{} — {}", lr.white, lr.black)).truncate(), + ); }); row.col(|_| {}); row.col(|_| {}); @@ -4292,7 +4863,11 @@ impl PrepScreen { }); } } - ErrRow::Variation { white, family, variation } => { + ErrRow::Variation { + white, + family, + variation, + } => { let cr = report.color(white); let var = &cr.families[family].variations[variation]; let open = self.open_variations.contains(&(white, family, variation)); @@ -4301,15 +4876,25 @@ impl PrepScreen { counts.add(cr.errors[e as usize].judgement); } row.col(|ui| { - if ui.add(egui::Label::new(weak(if open { "▾" } else { "▸" })).sense(Sense::click())).clicked() { + if ui + .add( + egui::Label::new(weak(if open { "▾" } else { "▸" })) + .sense(Sense::click()), + ) + .clicked() + { toggled = Some(r); } colour_icon(ui, white); let name = var .opening .and_then(|o| report.openings.get(o)) - .map_or_else(|| tr("no name").to_owned(), |o| format!("{} · {}", o.name, o.eco)); - ui.add(egui::Label::new(name.as_str()).truncate()).on_hover_text(name); + .map_or_else( + || tr("no name").to_owned(), + |o| format!("{} · {}", o.name, o.eco), + ); + ui.add(egui::Label::new(name.as_str()).truncate()) + .on_hover_text(name); }); row.col(|_| {}); row.col(|_| {}); @@ -4330,7 +4915,9 @@ impl PrepScreen { let lr = &self.rows[e.game as usize]; row.col(|ui| { ui.add_space(28.0); - ui.add(egui::Label::new(format!("{} — {}", lr.white, lr.black)).truncate()); + ui.add( + egui::Label::new(format!("{} — {}", lr.white, lr.black)).truncate(), + ); }); row.col(|ui| { ui.spacing_mut().item_spacing.x = 4.0; @@ -4373,7 +4960,9 @@ impl PrepScreen { match sort_click { Some(SortKeyOf::Repeated(k)) => { // Indices into the lists do not change: the rows only reorder. - self.sorts.repeated.click(k, matches!(k, RepeatedSort::Move | RepeatedSort::Opening)) + self.sorts + .repeated + .click(k, matches!(k, RepeatedSort::Move | RepeatedSort::Opening)) } Some(SortKeyOf::Variation(k)) => self.sorts.variations.click(k, false), None => {} @@ -4395,12 +4984,29 @@ impl PrepScreen { /// The keyboard in the errors tab: ↑/↓ the rows, →/← open and close, Enter the game. #[allow(clippy::too_many_arguments)] - fn errors_keys(&mut self, up: bool, down: bool, left: bool, right: bool, enter: bool, space: bool, home: bool, end: bool, actions: &mut Vec) { - let rows: Vec = self.err_rows().into_iter().filter(|r| !r.is_title()).collect(); + fn errors_keys( + &mut self, + up: bool, + down: bool, + left: bool, + right: bool, + enter: bool, + space: bool, + home: bool, + end: bool, + actions: &mut Vec, + ) { + let rows: Vec = self + .err_rows() + .into_iter() + .filter(|r| !r.is_title()) + .collect(); if rows.is_empty() { return; } - let at = self.err_cursor.and_then(|c| rows.iter().position(|r| *r == c)); + let at = self + .err_cursor + .and_then(|c| rows.iter().position(|r| *r == c)); let Some(at) = at else { if up || down || home || end { self.err_select(rows[0]); @@ -4427,12 +5033,17 @@ impl PrepScreen { } let open = match r { ErrRow::Repeated { white, index } => Some(self.open_repeated.contains(&(white, index))), - ErrRow::Variation { white, family, variation } => { - Some(self.open_variations.contains(&(white, family, variation))) - } + ErrRow::Variation { + white, + family, + variation, + } => Some(self.open_variations.contains(&(white, family, variation))), _ => None, }; - if (right && open == Some(false)) || (left && open == Some(true)) || (space && open.is_some()) { + if (right && open == Some(false)) + || (left && open == Some(true)) + || (space && open.is_some()) + { self.err_toggle(r); } else if left { // A game or an error row: to the row it is under. @@ -4462,7 +5073,9 @@ impl PrepScreen { // ----- the games list ------------------------------------------------------------ fn games_list(&mut self, ui: &mut Ui, actions: &mut Vec) { - let Some(report) = self.report.as_ref() else { return }; + let Some(report) = self.report.as_ref() else { + return; + }; let list = self.games_of(); let title = match &self.selection { Selection::None => trf("Games · {n}", &[("n", &list.len())]), @@ -4470,31 +5083,76 @@ impl PrepScreen { let n = &report.color(*white).tree.nodes[*node as usize]; match n.ply { 0 => trf("Games · {n}", &[("n", &list.len())]), - p => trf("Games · after {move} · {n}", &[("move", &short_label(usize::from(p) - 1, &n.san)), ("n", &list.len())]), + p => trf( + "Games · after {move} · {n}", + &[ + ("move", &short_label(usize::from(p) - 1, &n.san)), + ("n", &list.len()), + ], + ), } } - Selection::Opening { white, family, variation } => { + Selection::Opening { + white, + family, + variation, + } => { let fam = &report.color(*white).families[*family]; let name = match variation { - Some(v) => fam.variations[*v].opening.and_then(|o| report.openings.get(o)).map(|o| o.name.clone()).unwrap_or_else(|| fam.name.clone()), + Some(v) => fam.variations[*v] + .opening + .and_then(|o| report.openings.get(o)) + .map(|o| o.name.clone()) + .unwrap_or_else(|| fam.name.clone()), None => fam.name.clone(), }; - trf("Games · {opening} · {n}", &[("opening", &name), ("n", &list.len())]) + trf( + "Games · {opening} · {n}", + &[("opening", &name), ("n", &list.len())], + ) } Selection::Repeated { white, index } => { let r = &report.color(*white).repeated[*index]; - trf("Games · {move} · {n}", &[("move", &format!("{} {}", short_label(r.ply as usize, &r.san), review::judgement_symbol(r.judgement))), ("n", &list.len())]) + trf( + "Games · {move} · {n}", + &[ + ( + "move", + &format!( + "{} {}", + short_label(r.ply as usize, &r.san), + review::judgement_symbol(r.judgement) + ), + ), + ("n", &list.len()), + ], + ) } Selection::Error { white, index } => { let e = &report.color(*white).errors[*index]; - trf("Games · {move} · {n}", &[("move", &format!("{} {}", short_label(e.ply as usize, &e.san), review::judgement_symbol(e.judgement))), ("n", &list.len())]) + trf( + "Games · {move} · {n}", + &[ + ( + "move", + &format!( + "{} {}", + short_label(e.ply as usize, &e.san), + review::judgement_symbol(e.judgement) + ), + ), + ("n", &list.len()), + ], + ) } }; let mut clear = false; ui.horizontal(|ui| { ui.label(RichText::new(title).strong()); if self.selection != Selection::None - && crate::widgets::small_close_button(ui).on_hover_text(tr("All games")).clicked() + && crate::widgets::small_close_button(ui) + .on_hover_text(tr("All games")) + .clicked() { clear = true; } @@ -4516,7 +5174,12 @@ impl PrepScreen { let mut show_date = true; let gap = ui.spacing().item_spacing.x; let player_w_of = |event: bool, then: bool, elo: bool, errors: bool, date: bool| -> f32 { - let columns = 3 + 2 * usize::from(elo) + usize::from(date) + usize::from(then) + usize::from(event) + usize::from(errors); + let columns = 3 + + 2 * usize::from(elo) + + usize::from(date) + + usize::from(then) + + usize::from(event) + + usize::from(errors); let fixed = 44.0 + if elo { 88.0 } else { 0.0 } + if date { 84.0 } else { 0.0 } @@ -4542,7 +5205,8 @@ impl PrepScreen { _ => show_date = false, } } - let player_w = player_w_of(show_event, show_then, show_elo, show_errors, show_date).clamp(60.0, 170.0); + let player_w = + player_w_of(show_event, show_then, show_elo, show_errors, show_date).clamp(60.0, 170.0); let plies: HashMap = list.iter().map(|&g| (g, self.game_ply(g))).collect(); ui.style_mut().interaction.selectable_labels = false; let mut table = TableBuilder::new(ui) @@ -4602,13 +5266,27 @@ impl PrepScreen { sort_col(&mut h, tr("Date"), "", GameSort::Date, sort, c); } if show_then { - sort_col(&mut h, tr("Then"), tr("How the game went on from this position"), GameSort::Then, sort, c); + sort_col( + &mut h, + tr("Then"), + tr("How the game went on from this position"), + GameSort::Then, + sort, + c, + ); } if show_event { sort_col(&mut h, tr("Event"), "", GameSort::Event, sort, c); } if show_errors { - sort_col(&mut h, tr("Errors"), tr("His marked moves in the opening of this game"), GameSort::Errors, sort, c); + sort_col( + &mut h, + tr("Errors"), + tr("His marked moves in the opening of this game"), + GameSort::Errors, + sort, + c, + ); } }) .body(|body| { @@ -4619,7 +5297,14 @@ impl PrepScreen { row.set_selected(self.games_cursor == Some(row.index())); let name = |ui: &mut Ui, n: &str| { let t = RichText::new(n); - ui.add(egui::Label::new(if player_names.contains(n) { t.strong() } else { t }).truncate()); + ui.add( + egui::Label::new(if player_names.contains(n) { + t.strong() + } else { + t + }) + .truncate(), + ); }; let elo = |e: u16| if e > 0 { e.to_string() } else { String::new() }; let ply = plies.get(&gi).copied().unwrap_or(0); @@ -4652,7 +5337,8 @@ impl PrepScreen { } if show_then { row.col(|ui| { - let then: Vec = g.sans.iter().skip(ply).take(3).cloned().collect(); + let then: Vec = + g.sans.iter().skip(ply).take(3).cloned().collect(); let mut text = String::new(); for (k, san) in then.iter().enumerate() { let p = ply + k; @@ -4663,31 +5349,45 @@ impl PrepScreen { } text.push(' '); } - ui.add(egui::Label::new(crate::san::show_line(text.trim_end())).truncate()); + ui.add( + egui::Label::new(crate::san::show_line(text.trim_end())).truncate(), + ); }); } if show_event { row.col(|ui| { - ui.add(egui::Label::new(RichText::new(&r.event).italics().weak()).truncate()); + ui.add( + egui::Label::new(RichText::new(&r.event).italics().weak()) + .truncate(), + ); }); } if show_errors { row.col(|ui| { ui.spacing_mut().item_spacing.x = 3.0; let cr = report.color(g.white); - for e in cr.errors.iter().filter(|e| e.game == gi && self.visible(e.judgement)) { + for e in cr + .errors + .iter() + .filter(|e| e.game == gi && self.visible(e.judgement)) + { let number = e.ply as usize / 2 + 1; ui.label(RichText::new(format!("{number}.")).small()); pill(ui, e.judgement).on_hover_text(format!( "{} {} — {}", short_label(e.ply as usize, &e.san), review::judgement_name(e.judgement), - trf("better {best}", &[("best", &crate::san::show(&e.best_san))]) + trf( + "better {best}", + &[("best", &crate::san::show(&e.best_san))] + ) )); } }); } - let resp = row.response().on_hover_text(tr("Double click: open this game at this position")); + let resp = row + .response() + .on_hover_text(tr("Double click: open this game at this position")); if resp.hovered() { hovered = Some(gi); } @@ -4699,7 +5399,14 @@ impl PrepScreen { }); }); if let Some(k) = game_click { - let names = matches!(k, GameSort::White | GameSort::Black | GameSort::Result | GameSort::Then | GameSort::Event); + let names = matches!( + k, + GameSort::White + | GameSort::Black + | GameSort::Result + | GameSort::Then + | GameSort::Event + ); self.sorts.games.click(k, names); // The keyboard's row is a place in the list: it goes back to the top. self.games_cursor = None; @@ -4711,7 +5418,12 @@ impl PrepScreen { { let g = &report.games[gi as usize]; let ply = plies.get(&gi).copied().unwrap_or(0); - if let Some(m) = g.ucis.get(ply).and_then(|u| u.parse::().ok()).and_then(|u| u.to_move(&s.positions[s.ply]).ok()) { + if let Some(m) = g + .ucis + .get(ply) + .and_then(|u| u.parse::().ok()) + .and_then(|u| u.to_move(&s.positions[s.ply]).ok()) + { self.hover_arrow = m.from().map(|f| (f, crate::board::ui_target(&m))); } } @@ -4730,7 +5442,12 @@ impl PrepScreen { // ----- the keyboard -------------------------------------------------------------- - fn keyboard(&mut self, ctx: &egui::Context, settings: &Settings, actions: &mut Vec) { + fn keyboard( + &mut self, + ctx: &egui::Context, + settings: &Settings, + actions: &mut Vec, + ) { let ctrl = |k| KeyboardShortcut::new(Modifiers::COMMAND, k); let alt = |k| KeyboardShortcut::new(Modifiers::ALT, k); if ctx.input_mut(|i| i.consume_shortcut(&ctrl(Key::Num1))) { @@ -4755,7 +5472,10 @@ impl PrepScreen { actions.push(PrepAction::Back); } if ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::F)) { - let base = self.shown_pos.as_ref().map_or(self.color != ColorChoice::Black, |s| s.white); + let base = self + .shown_pos + .as_ref() + .map_or(self.color != ColorChoice::Black, |s| s.white); self.flipped = Some(!self.board_white() == base); } if ctx.input_mut(|i| i.consume_key(Modifiers::SHIFT, Key::A)) { @@ -4765,8 +5485,12 @@ impl PrepScreen { self.engine_asked(settings, ctx, actions); } } - if ctx.input_mut(|i| i.consume_shortcut(&KeyboardShortcut::new(Modifiers::COMMAND | Modifiers::SHIFT, Key::F))) - && let Some(s) = &self.shown_pos + if ctx.input_mut(|i| { + i.consume_shortcut(&KeyboardShortcut::new( + Modifiers::COMMAND | Modifiers::SHIFT, + Key::F, + )) + }) && let Some(s) = &self.shown_pos { let mut p = Chess::default(); let moves: Vec = s.ucis[..s.ply] @@ -4777,7 +5501,12 @@ impl PrepScreen { Some(m) }) .collect(); - actions.push(PrepAction::FindPosition(self.path.clone(), Chess::default(), moves, !self.board_white())); + actions.push(PrepAction::FindPosition( + self.path.clone(), + Chess::default(), + moves, + !self.board_white(), + )); } if ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::Escape)) { if self.board_popup { @@ -4830,9 +5559,7 @@ impl PrepScreen { self.games_cursor = Some(next); self.scroll_to_selected = true; } - if enter - && let Some(r) = &self.report - { + if enter && let Some(r) = &self.report { actions.push(PrepAction::OpenGame { path: self.path.clone(), index: r.games[list[next] as usize].index as usize, @@ -4844,18 +5571,36 @@ impl PrepScreen { match self.tab { Tab::Repertoire => self.tree_keys(up, down, left, right, enter, space, home, end), Tab::Openings => self.openings_keys(up, down, left, right, enter, space, home, end), - Tab::Errors => self.errors_keys(up, down, left, right, enter, space, home, end, actions), + Tab::Errors => { + self.errors_keys(up, down, left, right, enter, space, home, end, actions) + } } } #[allow(clippy::too_many_arguments)] - fn tree_keys(&mut self, up: bool, down: bool, left: bool, right: bool, enter: bool, space: bool, home: bool, end: bool) { + fn tree_keys( + &mut self, + up: bool, + down: bool, + left: bool, + right: bool, + enter: bool, + space: bool, + home: bool, + end: bool, + ) { let rows = self.tree_rows(); if rows.is_empty() { return; } let at = rows.iter().position(|r| match (r, &self.selection) { - (TreeRow::Node { white, node, .. }, Selection::Node { white: sw, node: sn }) => white == sw && node == sn, + ( + TreeRow::Node { white, node, .. }, + Selection::Node { + white: sw, + node: sn, + }, + ) => white == sw && node == sn, _ => false, }); let go = |screen: &mut Self, i: usize| { @@ -4898,7 +5643,10 @@ impl PrepScreen { } else if home { go(self, 0); } else if end { - let last = rows.iter().rposition(|r| matches!(r, TreeRow::Node { .. })).unwrap_or(0); + let last = rows + .iter() + .rposition(|r| matches!(r, TreeRow::Node { .. })) + .unwrap_or(0); go(self, last); } else if right { if has_children && !open { @@ -4909,7 +5657,11 @@ impl PrepScreen { } else if left { if open { self.expanded.remove(&(white, node)); - } else if let Some(p) = self.report.as_ref().and_then(|r| r.color(white).tree.nodes[node as usize].parent) { + } else if let Some(p) = self + .report + .as_ref() + .and_then(|r| r.color(white).tree.nodes[node as usize].parent) + { self.select(Selection::Node { white, node: p }); self.scroll_to_selected = true; } @@ -4924,15 +5676,36 @@ impl PrepScreen { } #[allow(clippy::too_many_arguments)] - fn openings_keys(&mut self, up: bool, down: bool, left: bool, right: bool, enter: bool, space: bool, home: bool, end: bool) { + fn openings_keys( + &mut self, + up: bool, + down: bool, + left: bool, + right: bool, + enter: bool, + space: bool, + home: bool, + end: bool, + ) { let rows = self.opening_rows(); if rows.is_empty() { return; } - let at = rows.iter().position(|&(w, f, v)| self.selection == Selection::Opening { white: w, family: f, variation: v }); + let at = rows.iter().position(|&(w, f, v)| { + self.selection + == Selection::Opening { + white: w, + family: f, + variation: v, + } + }); let go = |screen: &mut Self, i: usize| { if let Some(&(white, family, variation)) = rows.get(i) { - screen.select(Selection::Opening { white, family, variation }); + screen.select(Selection::Opening { + white, + family, + variation, + }); screen.scroll_to_selected = true; } }; @@ -4957,7 +5730,12 @@ impl PrepScreen { } } else if left { if v.is_some() { - go(self, rows.iter().position(|&(w, ff, vv)| w == white && ff == f && vv.is_none()).unwrap_or(at)); + go( + self, + rows.iter() + .position(|&(w, ff, vv)| w == white && ff == f && vv.is_none()) + .unwrap_or(at), + ); } else { self.open_families.remove(&(white, f)); } @@ -4984,7 +5762,12 @@ fn error_arrows(pos: &Chess, played: &str, best: Option<&str>, j: Judgement) -> if let Some(a) = to_arrow(played, review::judgement_color(j).gamma_multiply(0.85)) { out.push(a); } - if let Some(a) = best.and_then(|b| to_arrow(b, crate::board::shape_preview_color(chess_core::ShapeColor::Green))) { + if let Some(a) = best.and_then(|b| { + to_arrow( + b, + crate::board::shape_preview_color(chess_core::ShapeColor::Green), + ) + }) { out.push(a); } out @@ -4992,7 +5775,11 @@ fn error_arrows(pos: &Chess, played: &str, best: Option<&str>, j: Judgement) -> /// «6…Nb6 ? — better 6…e6 · 0.0 → −1.2». fn error_note(e: &prep::OpeningError) -> String { - let played = format!("{} {}", short_label(e.ply as usize, &e.san), review::judgement_symbol(e.judgement)); + let played = format!( + "{} {}", + short_label(e.ply as usize, &e.san), + review::judgement_symbol(e.judgement) + ); trf( "{played} — better {best} · {before} → {after}", &[ @@ -5099,19 +5886,36 @@ mod tests { #[test] fn a_header_click_sorts_then_turns_the_order_round() { let mut s = PrepSorts::default().games; - assert_eq!((s.key, s.ascending), (GameSort::Date, false), "newest first"); + assert_eq!( + (s.key, s.ascending), + (GameSort::Date, false), + "newest first" + ); s.click(GameSort::Date, false); assert!(s.ascending, "the same column again: the other way"); s.click(GameSort::White, true); - assert_eq!((s.key, s.ascending), (GameSort::White, true), "a name column starts A–Z"); + assert_eq!( + (s.key, s.ascending), + (GameSort::White, true), + "a name column starts A–Z" + ); assert_eq!(s.apply(std::cmp::Ordering::Less), std::cmp::Ordering::Less); s.click(GameSort::White, true); - assert_eq!(s.apply(std::cmp::Ordering::Less), std::cmp::Ordering::Greater); + assert_eq!( + s.apply(std::cmp::Ordering::Less), + std::cmp::Ordering::Greater + ); assert_eq!(cmp_val(&num(2), &num(10)), std::cmp::Ordering::Less); - assert_eq!(cmp_val(&SortVal::Text("b".into()), &SortVal::Text("a".into())), std::cmp::Ordering::Greater); + assert_eq!( + cmp_val(&SortVal::Text("b".into()), &SortVal::Text("a".into())), + std::cmp::Ordering::Greater + ); // Kept in the settings as they are. let json = serde_json::to_string(&PrepSorts::default()).unwrap(); - assert_eq!(serde_json::from_str::(&json).unwrap(), PrepSorts::default()); + assert_eq!( + serde_json::from_str::(&json).unwrap(), + PrepSorts::default() + ); } #[test] @@ -5119,11 +5923,20 @@ mod tests { assert_eq!(short_label(0, "e4"), "1.e4"); assert_eq!(short_label(1, "c5"), "1…c5"); assert_eq!(short_label(4, "Bb5"), "3.Bb5"); - let sans: Vec = ["e4", "c5", "Nf3"].iter().map(|s| (*s).to_owned()).collect(); + let sans: Vec = ["e4", "c5", "Nf3"] + .iter() + .map(|s| (*s).to_owned()) + .collect(); assert_eq!(line_text(&sans), "1.e4 c5 2.Nf3"); - assert_eq!(table_line("1. e4 c5 2. Nf3 Nc6 3. Bb5"), vec!["1.e4", "c5", "2.Nf3", "Nc6", "3.Bb5"]); + assert_eq!( + table_line("1. e4 c5 2. Nf3 Nc6 3. Bb5"), + vec!["1.e4", "c5", "2.Nf3", "Nc6", "3.Bb5"] + ); assert_eq!(table_line("1... e5"), vec!["1…e5"]); - let ucis: Vec = ["e2e4", "c7c5", "g1f3"].iter().map(|s| (*s).to_owned()).collect(); + let ucis: Vec = ["e2e4", "c7c5", "g1f3"] + .iter() + .map(|s| (*s).to_owned()) + .collect(); assert_eq!(replay(&ucis).len(), 4); assert_eq!(replay(&["zz".to_owned()]).len(), 1); } @@ -5145,7 +5958,10 @@ mod tests { named: None, book: None, }; - assert_eq!(period(&[game("2026.10.18"), game("2026.01.03"), game("")]), "01.2026 – 10.2026"); + assert_eq!( + period(&[game("2026.10.18"), game("2026.01.03"), game("")]), + "01.2026 – 10.2026" + ); assert_eq!(period(&[game("2026.10.18")]), "10.2026"); assert_eq!(period(&[game("")]), ""); } @@ -5176,15 +5992,27 @@ mod tests { bytes: 10, }, ]; - assert_eq!(BookChoice::from_setting(None, own, &dbs), BookChoice::Database(PathBuf::from("/a/mega.cbh"))); - assert_eq!(BookChoice::from_setting(Some(Path::new("")), own, &dbs), BookChoice::None); - assert_eq!(BookChoice::from_setting(Some(own), own, &dbs), BookChoice::Same); + assert_eq!( + BookChoice::from_setting(None, own, &dbs), + BookChoice::Database(PathBuf::from("/a/mega.cbh")) + ); + assert_eq!( + BookChoice::from_setting(Some(Path::new("")), own, &dbs), + BookChoice::None + ); + assert_eq!( + BookChoice::from_setting(Some(own), own, &dbs), + BookChoice::Same + ); assert_eq!( BookChoice::from_setting(Some(Path::new("/a/small.pgn")), own, &dbs), BookChoice::Database(PathBuf::from("/a/small.pgn")) ); // A database no longer on the shelf: the default again. - assert_eq!(BookChoice::from_setting(Some(Path::new("/gone.pgn")), own, &dbs), BookChoice::Database(PathBuf::from("/a/mega.cbh"))); + assert_eq!( + BookChoice::from_setting(Some(Path::new("/gone.pgn")), own, &dbs), + BookChoice::Database(PathBuf::from("/a/mega.cbh")) + ); assert_eq!(BookChoice::Same.setting(own), own); assert_eq!(BookChoice::None.setting(own), PathBuf::new()); } diff --git a/apps/desktop/src/reference.rs b/apps/desktop/src/reference.rs index a2fa374..84326ca 100644 --- a/apps/desktop/src/reference.rs +++ b/apps/desktop/src/reference.rs @@ -15,9 +15,7 @@ use std::sync::atomic::AtomicBool; use chess_core::{Game, NodeId}; use chess_import::Database; -use chess_import::position::{ - Match, MoveStat, PositionOutcome, PositionQuery, Tally, theory_end, -}; +use chess_import::position::{Match, MoveStat, PositionOutcome, PositionQuery, Tally, theory_end}; use egui::{RichText, Sense, Ui, vec2}; use egui_extras::{Column, TableBuilder}; use shakmaty::uci::UciMove; diff --git a/apps/desktop/src/review.rs b/apps/desktop/src/review.rs index 910f489..6402e42 100644 --- a/apps/desktop/src/review.rs +++ b/apps/desktop/src/review.rs @@ -124,16 +124,10 @@ impl Review { let spawned = std::thread::Builder::new() .name("game-review".into()) .spawn(move || { - let result = game_review::run( - config, - &settings, - targets, - &cancel_w, - &mut |e| { - let _ = tx.send(JobMsg::Event(e)); - ctx_w.request_repaint(); - }, - ); + let result = game_review::run(config, &settings, targets, &cancel_w, &mut |e| { + let _ = tx.send(JobMsg::Event(e)); + ctx_w.request_repaint(); + }); let msg = match result { Ok(()) => JobMsg::Done, Err(JobFailure::Start(e) | JobFailure::Engine(e)) => JobMsg::Failed(e), @@ -541,8 +535,11 @@ impl Review { let can_update = self.analysis.meta.as_ref().is_some_and(|m| m.nodes > 0); if can_update { // Stale: everything again («Обновить»); otherwise the gaps («Дополнить»). - let mut button = - ui.button(if stale { tr("Analyse again") } else { tr("Update") }); + let mut button = ui.button(if stale { + tr("Analyse again") + } else { + tr("Update") + }); if stale { button = button.on_hover_text(tr( "Every position is analysed again, the same way on every computer", diff --git a/apps/desktop/src/settings.rs b/apps/desktop/src/settings.rs index 1f0e456..c2d96f5 100644 --- a/apps/desktop/src/settings.rs +++ b/apps/desktop/src/settings.rs @@ -242,15 +242,13 @@ impl Settings { }; migrate_legacy_config(&path); match std::fs::read(&path) { - Ok(bytes) => { - serde_json::from_slice(&bytes).unwrap_or_else(|e| { - eprintln!( - "settings: cannot parse {}: {e}; using defaults", - path.display() - ); - Self::default() - }) - } + Ok(bytes) => serde_json::from_slice(&bytes).unwrap_or_else(|e| { + eprintln!( + "settings: cannot parse {}: {e}; using defaults", + path.display() + ); + Self::default() + }), Err(e) if e.kind() == std::io::ErrorKind::NotFound => Self::first_start(), Err(_) => Self::default(), } diff --git a/crates/chess-import/src/chessbase/base.rs b/crates/chess-import/src/chessbase/base.rs index 3c68a8e..5326f2d 100644 --- a/crates/chess-import/src/chessbase/base.rs +++ b/crates/chess-import/src/chessbase/base.rs @@ -968,7 +968,8 @@ impl Base { let mut first = true; moves::main_line(&bytes, 0, fast, |pos, step| { if std::mem::take(&mut first) { - line.standard_start = crate::position::same_position(pos, &shakmaty::Chess::default()); + line.standard_start = + crate::position::same_position(pos, &shakmaty::Chess::default()); if !line.standard_start { return false; } diff --git a/crates/chess-import/src/position.rs b/crates/chess-import/src/position.rs index 1f0352a..6678f45 100644 --- a/crates/chess-import/src/position.rs +++ b/crates/chess-import/src/position.rs @@ -408,9 +408,21 @@ mod tests { assert_eq!(theory_end(10, 0, |_| None), None); // Continuing from a known prefix. let end = theory_end(10, 4, |i| Some(i < 7)).expect("end"); - assert_eq!(end, TheoryEnd { last_known: Some(6), first_unknown: Some(7) }); + assert_eq!( + end, + TheoryEnd { + last_known: Some(6), + first_unknown: Some(7) + } + ); let end = theory_end(10, 4, |_| Some(true)).expect("end"); - assert_eq!(end, TheoryEnd { last_known: Some(9), first_unknown: None }); + assert_eq!( + end, + TheoryEnd { + last_known: Some(9), + first_unknown: None + } + ); } #[test] diff --git a/crates/game-review/examples/chesscom_check.rs b/crates/game-review/examples/chesscom_check.rs index 3d848f3..f40bf40 100644 --- a/crates/game-review/examples/chesscom_check.rs +++ b/crates/game-review/examples/chesscom_check.rs @@ -23,8 +23,9 @@ fn main() { eprintln!("usage: chesscom_check "); std::process::exit(2); }; - let nodes: u64 = std::env::var("CP_REVIEW_NODES") - .map_or(SEARCH_NODES, |n| n.parse().expect("CP_REVIEW_NODES: a number")); + let nodes: u64 = std::env::var("CP_REVIEW_NODES").map_or(SEARCH_NODES, |n| { + n.parse().expect("CP_REVIEW_NODES: a number") + }); let root = Path::new(env!("CARGO_MANIFEST_DIR")); // Evaluations of one version of the fixed search are the same on every machine; // those of other nodes go apart. @@ -82,7 +83,11 @@ fn main() { ); for (i, j) in a.report.judgements.iter().enumerate() { if let Some(j @ (Judgement::Brilliant | Judgement::Great)) = j { - let mark = if *j == Judgement::Brilliant { "!!" } else { "!" }; + let mark = if *j == Judgement::Brilliant { + "!!" + } else { + "!" + }; let label = game.move_label(line[i + 1]).unwrap_or_default(); println!(" ours {label:<14} {mark}"); } diff --git a/crates/game-review/src/features.rs b/crates/game-review/src/features.rs index cf41ffc..afcbf85 100644 --- a/crates/game-review/src/features.rs +++ b/crates/game-review/src/features.rs @@ -254,14 +254,12 @@ fn taking_loses(before: &Board, pos: &Chess, sq: Square, threat: i32) -> bool { let mut after = pos.clone(); after.play_unchecked(take); let mover = after.turn(); - threats(&after) - .iter() - .any(|t| { - t.2 != sq - && t.0 >= threat - && pseudo_threat(pos.board(), t.2, mover) >= threat - && pseudo_threat(before, t.2, mover) < threat - }) + threats(&after).iter().any(|t| { + t.2 != sq + && t.0 >= threat + && pseudo_threat(pos.board(), t.2, mover) >= threat + && pseudo_threat(before, t.2, mover) < threat + }) } /// What `by` would win taking on `sq`, whoever is to move (a piece already hanging). @@ -403,8 +401,14 @@ mod tests { let f = last(Chess::default(), PILLSBURY); assert!(f.sacrifice && f.brilliant_shape(Rules::ChessCom), "{f:?}"); // 18.fxe6! just before: takes back the knight taken on c3, no gain. - let f = last(Chess::default(), &PILLSBURY[..PILLSBURY.rfind(" Ra3").unwrap()]); - assert!(f.winning_capture && f.takes_back && f.great_shape(Rules::ChessCom), "{f:?}"); + let f = last( + Chess::default(), + &PILLSBURY[..PILLSBURY.rfind(" Ra3").unwrap()], + ); + assert!( + f.winning_capture && f.takes_back && f.great_shape(Rules::ChessCom), + "{f:?}" + ); assert!(!f.great_shape(Rules::Strict), "the first rules stay: {f:?}"); } @@ -418,7 +422,10 @@ mod tests { 15. O-O Ne5 16. Nxe5 Bxe5 17. f4 Bc7 18. e4 Rac8 19. e5 Bb6+ 20. Kh1 Ng4 \ 21. Be4 Qh4 22. g3 Rxc3 23. gxh4 Rd2 24. Qxd2 Bxe4+", ); - assert!(f.winning_capture && !f.takes_back && !f.great_shape(Rules::ChessCom), "{f:?}"); + assert!( + f.winning_capture && !f.takes_back && !f.great_shape(Rules::ChessCom), + "{f:?}" + ); } #[test] diff --git a/crates/game-review/src/job.rs b/crates/game-review/src/job.rs index fcfbfea..55108f6 100644 --- a/crates/game-review/src/job.rs +++ b/crates/game-review/src/job.rs @@ -54,7 +54,9 @@ const SEARCH_GUARD: Duration = Duration::from_secs(300); pub fn processes(limit: usize) -> usize { let cpus = std::thread::available_parallelism().map_or(1, |n| n.get()); let memory = available_mb().map_or(usize::MAX, |mb| { - (mb.saturating_sub(SHARED_MB) / PROCESS_MB).try_into().unwrap_or(usize::MAX) + (mb.saturating_sub(SHARED_MB) / PROCESS_MB) + .try_into() + .unwrap_or(usize::MAX) }); cpus.min(limit).min(memory).clamp(1, MAX_PROCESSES) } @@ -158,7 +160,10 @@ pub fn run( if targets.is_empty() { return Ok(()); } - let workers = settings.processes.clamp(1, MAX_PROCESSES).min(targets.len()); + let workers = settings + .processes + .clamp(1, MAX_PROCESSES) + .min(targets.len()); let next = AtomicUsize::new(0); let failed = AtomicBool::new(false); let halted = || cancel.load(Ordering::Relaxed) || failed.load(Ordering::Relaxed); @@ -228,7 +233,14 @@ fn worker( let mut search = |pos: &EnginePosition, among: Vec| { next_id += 1; let _ = handle.new_game(); - search_once(&handle, pos, SearchId(next_id), among, settings.nodes, halted) + search_once( + &handle, + pos, + SearchId(next_id), + among, + settings.nodes, + halted, + ) }; while let Some(t) = targets.get(next.fetch_add(1, Ordering::Relaxed)) { if halted() { diff --git a/crates/game-review/src/lib.rs b/crates/game-review/src/lib.rs index db0090e..b891810 100644 --- a/crates/game-review/src/lib.rs +++ b/crates/game-review/src/lib.rs @@ -23,8 +23,8 @@ pub mod report; pub use features::{MoveFeatures, Rules}; pub use job::{ - JobEvent, JobFailure, JobSettings, MAX_PROCESSES, PHONE_PROCESSES, SEARCH_HASH_MB, SEARCH_NODES, - SEARCH_VERSION, Target, estimate_secs, processes, run, + JobEvent, JobFailure, JobSettings, MAX_PROCESSES, PHONE_PROCESSES, SEARCH_HASH_MB, + SEARCH_NODES, SEARCH_VERSION, Target, estimate_secs, processes, run, }; pub use report::{Eval, Judgement, Phase, Phases, Ply, Report, SideStats, judge}; @@ -313,7 +313,11 @@ impl GameAnalysis { /// !! and ! ("Update" fills them in without evaluating anything again). None for /// evaluations from the PGN, which have no engine lines. pub fn seconds_missing(&self) -> usize { - if self.meta.as_ref().is_none_or(|m| m.nodes == 0 || m.is_stale()) { + if self + .meta + .as_ref() + .is_none_or(|m| m.nodes == 0 || m.is_stale()) + { return 0; } (0..self.played.len()) diff --git a/crates/game-review/src/report.rs b/crates/game-review/src/report.rs index b7c32f0..938a7fb 100644 --- a/crates/game-review/src/report.rs +++ b/crates/game-review/src/report.rs @@ -805,7 +805,10 @@ mod tests { Rules::Strict, ); assert_eq!(r.judgements[0], None); - let mate = Some(Eval::Mate { white: true, moves: 5 }); + let mate = Some(Eval::Mate { + white: true, + moves: 5, + }); let r = Report::build(&evals, &[noted(w, true, mate)], Phases::default()); assert_eq!(r.judgements[0], None); // No best other move known (an older analysis): nothing said. diff --git a/crates/mobile-api/src/lib.rs b/crates/mobile-api/src/lib.rs index f409152..3153958 100644 --- a/crates/mobile-api/src/lib.rs +++ b/crates/mobile-api/src/lib.rs @@ -661,7 +661,10 @@ mod tests { fn comments_and_variations_come_along() { // The Opera game of the samples has comments and a variation. let db = classics(); - let g = db.game(0).expect("a game"); + let g = (0..db.len()) + .map(|i| db.game(i).expect("a game")) + .find(|g| g.nodes.iter().any(|n| n.san == "Qb8+")) + .expect("the Opera game"); assert!( g.nodes .iter() diff --git a/crates/mobile-api/src/review.rs b/crates/mobile-api/src/review.rs index 8648a4e..523a779 100644 --- a/crates/mobile-api/src/review.rs +++ b/crates/mobile-api/src/review.rs @@ -474,8 +474,8 @@ mod tests { // Evaluations from the PGN have no lines: nothing to show on the board. assert!(ke7.best.is_none() && ke7.reply_from.is_none()); assert!(s.white.accuracy.is_some()); - // Nothing to analyse: every position has an evaluation. - assert!(!review.start("/nonexistent".into(), String::new(), false)); + // The engine never fills in evaluations from the PGN: it would analyse the whole + // game (GameAnalysis::begin), so nothing is started here. } /// With the fake engine of the `uci` crate (`cargo build -p uci --bin fake_uci`). diff --git a/crates/openings/src/lib.rs b/crates/openings/src/lib.rs index 14f5d5b..5c719eb 100644 --- a/crates/openings/src/lib.rs +++ b/crates/openings/src/lib.rs @@ -203,10 +203,18 @@ mod tests { let (at, id) = deepest(&k).expect("named"); let o = get(id); assert_eq!(o.eco, "B31"); - assert!(o.name.starts_with("Sicilian Defense: Nyezhmetdinov-Rossolimo Attack"), "{}", o.name); + assert!( + o.name + .starts_with("Sicilian Defense: Nyezhmetdinov-Rossolimo Attack"), + "{}", + o.name + ); assert_eq!(at, 6, "the position after 3...g6"); assert_eq!(o.family(), "Sicilian Defense"); - assert!(o.variation().is_some_and(|v| v.starts_with("Nyezhmetdinov"))); + assert!( + o.variation() + .is_some_and(|v| v.starts_with("Nyezhmetdinov")) + ); assert_eq!(o.plies, 6); assert_eq!(o.line, "1. e4 c5 2. Nf3 Nc6 3. Bb5 g6"); // A transposition: 1.Nf3 d5 2.d4 reaches the table's 1.d4 d5 2.Nf3. @@ -226,8 +234,14 @@ mod tests { 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_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")); @@ -236,11 +250,22 @@ mod tests { #[test] fn book_positions_and_keys() { // The Greco Gambit lines pass 6...Bb4+; 7...d5 is on none of them. - let k = keys(&["e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5", "c3", "Nf6", "d4", "exd4", "cxd4", "Bb4+"]); - assert!(in_book(k[12]) && by_position(k[12]).is_none(), "on the way, not named"); - let more = keys(&["e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5", "c3", "Nf6", "d4", "exd4", "cxd4", "Bb4+", "Nc3", "d5"]); + let k = keys(&[ + "e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5", "c3", "Nf6", "d4", "exd4", "cxd4", "Bb4+", + ]); + assert!( + in_book(k[12]) && by_position(k[12]).is_none(), + "on the way, not named" + ); + let more = keys(&[ + "e4", "e5", "Nf3", "Nc6", "Bc4", "Bc5", "c3", "Nf6", "d4", "exd4", "cxd4", "Bb4+", + "Nc3", "d5", + ]); assert!(in_book(more[13]) && !in_book(more[14])); - assert!(!in_book(k[0]), "the start position is no move into the book"); + assert!( + !in_book(k[0]), + "the start position is no move into the book" + ); // The key is the one the rest of the program uses. let pos = Chess::default(); assert_eq!(key(&pos), chess_import::position::key(&pos)); diff --git a/crates/prep/examples/prep_report.rs b/crates/prep/examples/prep_report.rs index d863dcb..8e7af56 100644 --- a/crates/prep/examples/prep_report.rs +++ b/crates/prep/examples/prep_report.rs @@ -16,9 +16,7 @@ use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicBool, AtomicUsize}; use std::time::Instant; -use prep::{ - BookOptions, ColorReport, Options, Player, PrepReport, PositionCache, Side, Tree, -}; +use prep::{BookOptions, ColorReport, Options, Player, PositionCache, PrepReport, Side, Tree}; struct Args { db: PathBuf, @@ -50,10 +48,16 @@ fn args() -> Args { "--book" => a.book = it.next().map(PathBuf::from), "--plies" => a.plies = it.next().and_then(|v| v.parse().ok()).unwrap_or(a.plies), "--processes" => { - a.processes = it.next().and_then(|v| v.parse().ok()).unwrap_or(a.processes) + a.processes = it + .next() + .and_then(|v| v.parse().ok()) + .unwrap_or(a.processes) } "--min-games" => { - a.min_games = it.next().and_then(|v| v.parse().ok()).unwrap_or(a.min_games) + a.min_games = it + .next() + .and_then(|v| v.parse().ok()) + .unwrap_or(a.min_games) } "--no-cache" => a.cache = false, _ => positional.push(arg), @@ -70,8 +74,8 @@ fn args() -> Args { fn open(path: &Path) -> chess_import::Database { let t = Instant::now(); - let opened = chess_import::open(path, &mut |_| {}, &AtomicBool::new(false)) - .unwrap_or_else(|e| { + let opened = + chess_import::open(path, &mut |_| {}, &AtomicBool::new(false)).unwrap_or_else(|e| { eprintln!("cannot open {}: {e}", path.display()); std::process::exit(1); }); @@ -105,7 +109,8 @@ fn print_tree(tree: &Tree, node: usize, depth: usize, min_games: u32, report: &P prep::move_label(usize::from(n.ply) - 1, &n.san), tally(&n.tally), n.last_date, - n.average_elo().map_or(String::new(), |e| format!(" Elo {e}")), + n.average_elo() + .map_or(String::new(), |e| format!(" Elo {e}")), if n.transposition { " ↔" } else { "" }, name, indent = depth * 2 @@ -118,7 +123,11 @@ fn print_tree(tree: &Tree, node: usize, depth: usize, min_games: u32, report: &P fn print_color(report: &PrepReport, cr: &ColorReport, min_games: u32) { let colour = if cr.white { "White" } else { "Black" }; - println!("\n==== {colour}: {} games, {} tree nodes ====", cr.games.len(), cr.tree.nodes.len()); + println!( + "\n==== {colour}: {} games, {} tree nodes ====", + cr.games.len(), + cr.tree.nodes.len() + ); println!("-- repertoire (nodes with at least {min_games} games; ↔ = transposition)"); print_tree(&cr.tree, 0, 0, min_games, report); println!("-- openings"); @@ -126,7 +135,11 @@ fn print_color(report: &PrepReport, cr: &ColorReport, min_games: u32) { println!( "{} {}{}", tally(&f.tally), - if f.name.is_empty() { "(unnamed)" } else { &f.name }, + if f.name.is_empty() { + "(unnamed)" + } else { + &f.name + }, errors_text(&f.errors) ); for v in &f.variations { @@ -239,7 +252,11 @@ fn main() { let t = Instant::now(); let (list, total) = prep::candidates(&db, &a.player, 10); - println!("[candidates] {total} for «{}», {:.1} ms:", a.player, t.elapsed().as_secs_f64() * 1000.0); + println!( + "[candidates] {total} for «{}», {:.1} ms:", + a.player, + t.elapsed().as_secs_f64() * 1000.0 + ); for c in &list { println!(" {} · {} games (id {})", c.name, c.games, c.id); } @@ -264,7 +281,10 @@ fn main() { .and_then(|d| PrepReport::load(d, &db, &player, &options)); let mut report = match cached { Some(r) => { - println!("[report] from the cache, {:.1} ms", t.elapsed().as_secs_f64() * 1000.0); + println!( + "[report] from the cache, {:.1} ms", + t.elapsed().as_secs_f64() * 1000.0 + ); r } None => { @@ -290,7 +310,11 @@ fn main() { }; let book = a.book.as_deref().map(open); let book_db = book.as_ref().unwrap_or(&db); - if report.book.as_ref().is_some_and(|b| b.fingerprint == prep::fingerprint(book_db)) { + if report + .book + .as_ref() + .is_some_and(|b| b.fingerprint == prep::fingerprint(book_db)) + { println!("[book] from the cached report"); } else { let progress = AtomicUsize::new(0); @@ -341,7 +365,13 @@ fn main() { first = false; } if last_shown.elapsed().as_secs_f64() >= 5.0 { - println!(" {} / {} ({:.0} s, nps {})", p.done, p.total, t.elapsed().as_secs_f64(), p.nps); + println!( + " {} / {} ({:.0} s, nps {})", + p.done, + p.total, + t.elapsed().as_secs_f64(), + p.nps + ); last_shown = Instant::now(); } }, diff --git a/crates/prep/src/errors.rs b/crates/prep/src/errors.rs index e02aa41..37cbc2f 100644 --- a/crates/prep/src/errors.rs +++ b/crates/prep/src/errors.rs @@ -127,10 +127,18 @@ pub fn judge_games( let mut out = Vec::new(); for &g in which { let game = &games[g as usize]; - let mover = if game.white { Color::White } else { Color::Black }; + let mover = if game.white { + Color::White + } else { + Color::Black + }; let mut pos = Chess::default(); for (i, uci) in game.ucis.iter().enumerate() { - let Some(m) = uci.parse::().ok().and_then(|u| u.to_move(&pos).ok()) else { + let Some(m) = uci + .parse::() + .ok() + .and_then(|u| u.to_move(&pos).ok()) + else { break; }; if game.player_moves_at(i) @@ -268,7 +276,11 @@ impl PositionCache { /// 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 { - if self.entries.get(&key).is_some_and(|e| e.nodes >= eval.nodes) { + if self + .entries + .get(&key) + .is_some_and(|e| e.nodes >= eval.nodes) + { return false; } self.entries.insert(key, eval); diff --git a/crates/prep/src/games.rs b/crates/prep/src/games.rs index d0cc1da..a525cc1 100644 --- a/crates/prep/src/games.rs +++ b/crates/prep/src/games.rs @@ -57,7 +57,8 @@ impl Tally { /// Points per game, 0..1, over the games with a result. pub fn score(&self) -> Option { let decided = self.wins + self.draws + self.losses; - (decided > 0).then(|| (f64::from(self.wins) + 0.5 * f64::from(self.draws)) / f64::from(decided)) + (decided > 0) + .then(|| (f64::from(self.wins) + 0.5 * f64::from(self.draws)) / f64::from(decided)) } } @@ -214,7 +215,13 @@ mod tests { assert_eq!(Outcome::of("1/2-1/2", true), Outcome::Draw); assert_eq!(Outcome::of("*", true), Outcome::Unknown); let mut t = Tally::default(); - for o in [Outcome::Win, Outcome::Win, Outcome::Draw, Outcome::Loss, Outcome::Unknown] { + for o in [ + Outcome::Win, + Outcome::Win, + Outcome::Draw, + Outcome::Loss, + Outcome::Unknown, + ] { t.add(o); } assert_eq!((t.games, t.wins, t.draws, t.losses), (5, 2, 1, 1)); diff --git a/crates/prep/src/lib.rs b/crates/prep/src/lib.rs index 48fb8d8..ec4b5b8 100644 --- a/crates/prep/src/lib.rs +++ b/crates/prep/src/lib.rs @@ -34,9 +34,7 @@ mod tree; pub use book::BookOptions; pub use chess_import::chessbase::base::Side; -pub use errors::{ - EXACT, ErrorCounts, OpeningError, PositionCache, PositionEval, RepeatedError, -}; +pub use errors::{EXACT, ErrorCounts, OpeningError, PositionCache, PositionEval, RepeatedError}; pub use game_review::{Eval, Judgement}; pub use games::{BookExit, GameInfo, Outcome, Tally, move_label}; pub use openings::Opening; @@ -179,7 +177,11 @@ pub fn fingerprint(db: &Database) -> u64 { match db { Database::Pgn(p) => { let f = p.fingerprint(); - fnv(f.content_hash.to_le_bytes().iter().chain(f.len.to_le_bytes().iter())) + fnv(f + .content_hash + .to_le_bytes() + .iter() + .chain(f.len.to_le_bytes().iter())) } Database::ChessBase(b) => { let meta = std::fs::metadata(b.path()).ok(); @@ -188,7 +190,8 @@ pub fn fingerprint(db: &Database) -> u64 { .and_then(|m| m.modified().ok()) .and_then(|t| t.duration_since(SystemTime::UNIX_EPOCH).ok()) .map_or(0, |d| d.as_secs()); - fnv(b.path() + fnv(b + .path() .to_string_lossy() .bytes() .chain(len.to_le_bytes()) @@ -562,7 +565,12 @@ impl PrepReport { } /// The report cached in `dir` for this database, player and options, if any. - pub fn load(dir: &Path, db: &Database, player: &Player, options: &Options) -> Option { + pub fn load( + dir: &Path, + db: &Database, + player: &Player, + options: &Options, + ) -> Option { let fp = fingerprint(db); let bytes = std::fs::read(Self::cache_path(dir, fp, player, options)).ok()?; let mut report: PrepReport = serde_json::from_slice(&bytes).ok()?; @@ -733,24 +741,44 @@ mod tests { let player = Player::new([list[0].id, list[1].id]); let never = AtomicBool::new(false); let found = games_of(&db, &player, Side::Any, &never).expect("games"); - assert_eq!(found, vec![(0, true), (1, false), (2, true), (3, true), (4, true)]); + assert_eq!( + found, + vec![(0, true), (1, false), (2, true), (3, true), (4, true)] + ); assert_eq!( games_of(&db, &player, Side::Black, &never).expect("games"), vec![(1, false)] ); - let report = build(&db, &player, &Options::default(), &AtomicUsize::new(0), &never) - .expect("report"); + let report = build( + &db, + &player, + &Options::default(), + &AtomicUsize::new(0), + &never, + ) + .expect("report"); assert_eq!(report.games.len(), 4, "the set-up game is left out"); assert_eq!(report.skipped, 1); assert_eq!(report.names, vec!["Вафин Радель", "Вафин Р."]); let g = &report.games[0]; - assert_eq!((g.index, g.white, g.opponent.as_str(), g.opponent_elo), (0, true, "Иванов Иван", 1500)); + assert_eq!( + (g.index, g.white, g.opponent.as_str(), g.opponent_elo), + (0, true, "Иванов Иван", 1500) + ); assert_eq!(g.date, "2026.01.10"); assert_eq!(g.outcome, Outcome::Win); - assert_eq!(g.sans, vec!["e4", "c5", "Nf3", "Nc6", "Bb5", "g6", "O-O", "Bg7"]); + assert_eq!( + g.sans, + vec!["e4", "c5", "Nf3", "Nc6", "Bb5", "g6", "O-O", "Bg7"] + ); assert_eq!(g.keys.len(), 9); let o = &report.openings[g.opening.expect("named")]; - assert!(o.name.starts_with("Sicilian Defense: Nyezhmetdinov-Rossolimo Attack"), "{}", o.name); + assert!( + o.name + .starts_with("Sicilian Defense: Nyezhmetdinov-Rossolimo Attack"), + "{}", + o.name + ); assert_eq!(g.named, Some(6)); assert_eq!(report.games[1].outcome, Outcome::Win); assert_eq!(report.games[1].opponent_elo, 1700); @@ -760,7 +788,11 @@ mod tests { assert_eq!(w.families.len(), 2); assert_eq!(w.families[0].name, "Sicilian Defense"); assert_eq!(w.families[0].tally.games, 3 - 1); - assert_eq!(w.families[0].variations.len(), 2, "3...g6 and 3...e6 are named apart"); + assert_eq!( + w.families[0].variations.len(), + 2, + "3...g6 and 3...e6 are named apart" + ); assert_eq!(w.families[1].name, "Queen's Gambit"); assert_eq!(w.tree.nodes[0].tally.games, 3); assert_eq!(w.tree.nodes[0].last_date, "2026.04.01"); @@ -790,7 +822,16 @@ mod tests { assert_eq!(white_only.side(), Side::White); // Cancelled. let cancelled = AtomicBool::new(true); - assert!(build(&db, &player, &Options::default(), &AtomicUsize::new(0), &cancelled).is_none()); + assert!( + build( + &db, + &player, + &Options::default(), + &AtomicUsize::new(0), + &cancelled + ) + .is_none() + ); } #[test] @@ -801,15 +842,24 @@ mod tests { [White \"A\"]\n[Black \"C\"]\n[Result \"0-1\"]\n\n1. e4 c5 2. Nc3 0-1\n\n", ); let player = Player::new([candidates(&db, "A", 1).0[0].id]); - let report = build(&db, &player, &Options::default(), &AtomicUsize::new(0), &AtomicBool::new(false)) - .expect("report"); + let report = build( + &db, + &player, + &Options::default(), + &AtomicUsize::new(0), + &AtomicBool::new(false), + ) + .expect("report"); let fam = &report.white.families[0]; assert_eq!(fam.name, "Sicilian Defense"); assert_eq!(fam.variations.len(), 1); let v = &fam.variations[0]; assert_eq!(v.games, vec![0, 1]); let o = &report.openings[v.opening.unwrap()]; - assert_eq!((o.name.as_str(), o.line.as_str()), ("Sicilian Defense: Closed", "1. e4 c5 2. Nc3")); + assert_eq!( + (o.name.as_str(), o.line.as_str()), + ("Sicilian Defense: Closed", "1. e4 c5 2. Nc3") + ); } #[test] @@ -818,8 +868,14 @@ mod tests { let (list, _) = candidates(&db, "Вафин Р.", 2); let player = Player::new([list[0].id, list[1].id]); let never = AtomicBool::new(false); - let mut report = build(&db, &player, &Options::default(), &AtomicUsize::new(0), &never) - .expect("report"); + let mut report = build( + &db, + &player, + &Options::default(), + &AtomicUsize::new(0), + &never, + ) + .expect("report"); // The database itself as the book, threshold 2: 1.e4 c5 2.Nf3 is in three // games; game 0 (3...g6) and game 2 (3...e6) part after 3.Bb5, which is in // both. `ply` counts the moves to the first rare position. @@ -839,10 +895,21 @@ mod tests { count: 1 }) ); - assert_eq!(exits[1].map(|b| (b.ply, b.by_player)), Some((4, true)), "2...d6 is his"); + assert_eq!( + exits[1].map(|b| (b.ply, b.by_player)), + Some((4, true)), + "2...d6 is his" + ); assert_eq!(exits[2].map(|b| (b.ply, b.by_player)), Some((6, false))); - assert_eq!(exits[3].map(|b| (b.ply, b.by_player)), Some((1, true)), "1.d4 is his own"); - assert_eq!(report.book.as_ref().map(|b| (b.threshold, b.left)), Some((2, 4))); + assert_eq!( + exits[3].map(|b| (b.ply, b.by_player)), + Some((1, true)), + "1.d4 is his own" + ); + assert_eq!( + report.book.as_ref().map(|b| (b.threshold, b.left)), + Some((2, 4)) + ); assert_eq!(report.white.book_exits(&report.games), (1, 2)); // The counts of the positions looked at: the start (4 games), 1.e4 c5 2.Nf3 // (3), the rare 3...g6 (1). @@ -868,8 +935,14 @@ mod tests { let (list, _) = candidates(&db, "Вафин Радель", 1); let player = Player::new([list[0].id]); let never = AtomicBool::new(false); - let mut report = build(&db, &player, &Options::default(), &AtomicUsize::new(0), &never) - .expect("report"); + let mut report = build( + &db, + &player, + &Options::default(), + &AtomicUsize::new(0), + &never, + ) + .expect("report"); let total = report.distinct_positions(); // 9 + 11 + 7 positions; the start and 1.e4 c5 2.Nf3 shared by three games, // 2...Nc6 3.Bb5 by two. @@ -886,15 +959,27 @@ mod tests { assert!(targets[0].pos.moves.is_empty()); assert_eq!(targets[3].pos.moves, vec!["e2e4", "c7c5", "g1f3"]); assert_eq!(targets[3].turn, uci::Side::Black); - assert!(targets.iter().all(|t| t.played.is_none() && t.known.is_none())); + assert!( + targets + .iter() + .all(|t| t.played.is_none() && t.known.is_none()) + ); // The engine says: every move fine but 3.Bb5, a blunder (+0.3 → −1.5). let mut cache = PositionCache::default(); for t in &targets { let key = u64::from_str_radix(&t.key, 16).unwrap(); let after_bb5 = report.games[0].keys[5]; - let eval = if key == after_bb5 { Eval::Cp(-150) } else { Eval::Cp(30) }; + let eval = if key == after_bb5 { + Eval::Cp(-150) + } else { + Eval::Cp(30) + }; let before_bb5 = report.games[0].keys[4]; - let pv = if key == before_bb5 { vec!["d2d4".to_owned()] } else { Vec::new() }; + let pv = if key == before_bb5 { + vec!["d2d4".to_owned()] + } else { + Vec::new() + }; let event = JobEvent::Eval { key: t.key.clone(), eval: game_review::PosEval { @@ -918,7 +1003,10 @@ mod tests { assert_eq!(w.errors[0].san, "Bb5"); assert_eq!(w.errors[0].best_san, "d4"); assert_eq!(w.errors[0].ply, 4); - assert_eq!(report.games[w.errors[0].game as usize].move_label(4), "3. Bb5"); + assert_eq!( + report.games[w.errors[0].game as usize].move_label(4), + "3. Bb5" + ); assert_eq!(w.families[0].errors.blunders, 2); assert_eq!(w.families[0].variations[0].errors.blunders, 1); assert_eq!(w.families[0].variations[0].error_list.len(), 1); @@ -936,14 +1024,34 @@ mod tests { let again = PrepReport::load(&dir, &db, &player, &Options::default()).expect("cached"); assert_eq!(again.white.errors, report.white.errors); assert_eq!(again.evals.len(), report.evals.len()); - assert!(PrepReport::load(&dir, &db, &player, &Options { plies: 10, side: Side::Any }).is_none()); + assert!( + PrepReport::load( + &dir, + &db, + &player, + &Options { + plies: 10, + side: Side::Any + } + ) + .is_none() + ); let other = Player::new([list[0].id + 1]); assert!(PrepReport::load(&dir, &db, &other, &Options::default()).is_none()); - let mut fresh = build(&db, &player, &Options::default(), &AtomicUsize::new(0), &never) - .expect("report"); + let mut fresh = build( + &db, + &player, + &Options::default(), + &AtomicUsize::new(0), + &never, + ) + .expect("report"); assert!(!fresh.evaluated()); assert_eq!(fresh.take_cached(&cache), total); - assert!(fresh.evaluated(), "evaluations from the cache judge the errors too"); + 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), 0); // A report of another search (from before the fixed one) keeps its games but @@ -972,8 +1080,14 @@ mod tests { let (list, _) = candidates(&db, "Вафин Радель", 1); let player = Player::new([list[0].id]); let never = AtomicBool::new(false); - let mut report = build(&db, &player, &Options::default(), &AtomicUsize::new(0), &never) - .expect("report"); + let mut report = build( + &db, + &player, + &Options::default(), + &AtomicUsize::new(0), + &never, + ) + .expect("report"); let total = report.distinct_positions(); let settings = JobSettings::new(2, None); let mut cache = PositionCache::default(); @@ -991,10 +1105,19 @@ mod tests { assert_eq!((last.done, last.total), (total, total)); assert_eq!(report.missing(), 0); assert_eq!(cache.len(), total); - assert_eq!(report.engine.as_ref().map(|e| e.name.as_str()), Some("Fake UCI")); + assert_eq!( + report.engine.as_ref().map(|e| e.name.as_str()), + Some("Fake UCI") + ); // A second run has nothing to do; a cancelled one ends at once. - let mut again = build(&db, &player, &Options::default(), &AtomicUsize::new(0), &never) - .expect("report"); + let mut again = build( + &db, + &player, + &Options::default(), + &AtomicUsize::new(0), + &never, + ) + .expect("report"); let cancelled = AtomicBool::new(true); let mut calls = 0; analyse( diff --git a/crates/prep/src/tree.rs b/crates/prep/src/tree.rs index 764f3f4..50dc250 100644 --- a/crates/prep/src/tree.rs +++ b/crates/prep/src/tree.rs @@ -98,11 +98,13 @@ impl Tree { let key = game.keys[i + 1]; // 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 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)) + parent.as_deref().is_none_or(|p| { + !openings::is_prefix_name(&openings::get(id).name, p) + }) }); let opening = named .map(|id| openings.intern(id)) @@ -161,9 +163,12 @@ impl Tree { 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 parent = tree.nodes[i] + .parent + .and_then(|p| tree.nodes[p as usize].opening); let name = |o: Option| 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.nodes[i].named = + tree.nodes[i].opening.is_some() && name(tree.nodes[i].opening) != name(parent); } tree } @@ -238,11 +243,18 @@ impl Tree { pub(crate) mod tests { use super::*; use crate::games::Outcome; - use chess_core::shakmaty::san::SanPlus; use chess_core::shakmaty::Chess; + use chess_core::shakmaty::san::SanPlus; use chess_import::position::{key, uci}; - pub(crate) fn game(index: u32, white: bool, moves: &[&str], result: &str, date: &str, elo: u16) -> GameInfo { + pub(crate) fn game( + index: u32, + white: bool, + moves: &[&str], + result: &str, + date: &str, + elo: u16, + ) -> GameInfo { let mut pos = Chess::default(); let (mut ucis, mut sans, mut keys) = (Vec::new(), Vec::new(), vec![key(&pos)]); for s in moves { @@ -270,11 +282,25 @@ pub(crate) mod tests { #[test] fn the_tree_counts_games_and_marks_transpositions() { let games = vec![ - game(0, true, &["d4", "d5", "Nf3", "Nf6"], "1-0", "2026.01.05", 1500), + game( + 0, + true, + &["d4", "d5", "Nf3", "Nf6"], + "1-0", + "2026.01.05", + 1500, + ), game(1, true, &["Nf3", "d5", "d4", "Nf6"], "0-1", "2026.03.01", 0), game(2, true, &["d4", "d5", "c4"], "1/2-1/2", "2025.12.31", 1700), game(3, false, &["e4", "c5"], "0-1", "2026.02.02", 1600), - game(4, true, &["d4", "d5", "c4", "e6", "Nc3", "Nf6", "h3"], "1-0", "", 0), + game( + 4, + true, + &["d4", "d5", "c4", "e6", "Nc3", "Nf6", "h3"], + "1-0", + "", + 0, + ), ]; let mut set = OpeningSet::default(); let tree = Tree::build(&games, &[0, 1, 2], 20, &mut set); @@ -284,20 +310,42 @@ pub(crate) mod tests { assert_eq!(root.average_elo(), Some(1600)); assert_eq!(root.games, vec![0, 1, 2]); // 1.d4 (2 games) before 1.Nf3 (1 game). - let kids: Vec<&str> = root.children.iter().map(|&c| tree.nodes[c as usize].san.as_str()).collect(); + let kids: Vec<&str> = root + .children + .iter() + .map(|&c| tree.nodes[c as usize].san.as_str()) + .collect(); assert_eq!(kids, vec!["d4", "Nf3"]); // The position after 1.d4 d5 2.Nf3 / 1.Nf3 d5 2.d4 is in two nodes. let shared: Vec<&Node> = tree.nodes.iter().filter(|n| n.transposition).collect(); let keys: Vec = shared.iter().map(|n| n.key).collect(); assert_eq!(shared.len(), 4, "{keys:?}"); - let after_nf3 = tree.nodes.iter().find(|n| n.ply == 3 && n.san == "Nf3").unwrap(); - let after_d4 = tree.nodes.iter().find(|n| n.ply == 3 && n.san == "d4").unwrap(); + let after_nf3 = tree + .nodes + .iter() + .find(|n| n.ply == 3 && n.san == "Nf3") + .unwrap(); + 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"]); + 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); // both move orders get the same name. assert!(after_nf3.named && after_d4.named); @@ -310,7 +358,11 @@ pub(crate) mod tests { let h3 = tree.nodes.iter().find(|n| n.san == "h3").unwrap(); assert!(!h3.named); assert_eq!(h3.opening, tree.nodes[h3.parent.unwrap() as usize].opening); - assert!(set.list[h3.opening.unwrap()].name.starts_with("Queen's Gambit Declined")); + assert!( + set.list[h3.opening.unwrap()] + .name + .starts_with("Queen's Gambit Declined") + ); // Depth limit. let short = Tree::build(&games, &[0, 1, 2], 1, &mut set); assert_eq!(short.nodes.len(), 3); diff --git a/packaging/io.github.vrubelroman.chessPenguin.metainfo.xml b/packaging/io.github.vrubelroman.chessPenguin.metainfo.xml index 02af45b..fdf31d7 100644 --- a/packaging/io.github.vrubelroman.chessPenguin.metainfo.xml +++ b/packaging/io.github.vrubelroman.chessPenguin.metainfo.xml @@ -43,6 +43,11 @@ BoardGame + + +

Preparing against an opponent: their opening repertoire by colour with opening names, and their opening mistakes found by the engine. The game review uses one fixed engine search everywhere, so the same game gets the same marks on every computer and phone. Brilliant and great moves recalibrated on chess.com; 100 classic sample games instead of 38.

+
+

The game review marks brilliant (!!) and great (!) moves, calibrated on chess.com, in the notation, the report and on the board, now also on Android; move marks in a clearer palette, bold moves in the notation. Downloaded Lichess and Chess.com databases get new games on their own. The notation no longer jumps with the engine on; Android starts in the dark theme.