Large ChessBase bases: our own search booster when .cbb is missing or stale; skip the booster for early positions

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-19 18:54:22 +03:00
parent c66117e387
commit a7d9d599aa
10 changed files with 666 additions and 75 deletions

View file

@ -1549,6 +1549,22 @@ const ROWS: &[[&str; 6]] = &[
"+ Añadir motor…",
"+ Aggiungi motore…",
],
[
"Preparing fast position search… {p} %",
"Подготовка быстрого поиска по позиции… {p} %",
"Préparation de la recherche rapide par position… {p} %",
"Schnelle Stellungssuche wird vorbereitet… {p} %",
"Preparando la búsqueda rápida por posición… {p} %",
"Preparazione della ricerca rapida per posizione… {p} %",
],
[
"The base has no usable search index (.cbb); one is built once and kept in the cache.",
"У базы нет пригодного индекса поиска (.cbb); он строится один раз и хранится в кэше.",
"La base n'a pas d'index de recherche utilisable (.cbb) ; il est construit une fois et conservé dans le cache.",
"Die Datenbank hat keinen brauchbaren Suchindex (.cbb); er wird einmal erstellt und im Cache behalten.",
"La base no tiene un índice de búsqueda utilizable (.cbb); se construye una vez y se guarda en la caché.",
"La base non ha un indice di ricerca utilizzabile (.cbb); viene costruito una volta e tenuto nella cache.",
],
[
"Checking engine…",
"Проверка движка…",

View file

@ -236,6 +236,10 @@ pub struct LargeView {
in_order: Option<(usize, usize)>,
cache: OutcomeCache,
job: Option<Job>,
/// Building our own search booster (a base without a usable `.cbb`), once the
/// board is used; `booster_failed` keeps a failure from being retried.
booster: Option<Background<bool>>,
booster_failed: bool,
board: SearchBoard,
only_order: bool,
/// Next move of the game under the pointer in the table (an arrow on the board).
@ -304,6 +308,8 @@ impl LargeView {
in_order: None,
cache: HashMap::new(),
job: None,
booster: None,
booster_failed: false,
board,
only_order: false,
table_hover: None,
@ -445,11 +451,42 @@ impl LargeView {
highlighted: None,
});
}
if self.job.is_some() || self.suggest_job.is_some() {
self.update_booster(db, now, ctx);
if self.job.is_some() || self.suggest_job.is_some() || self.booster.is_some() {
ctx.request_repaint_after(std::time::Duration::from_millis(50));
}
}
/// Builds our own booster in the background when the board is in use and the
/// base has no usable `.cbb`; searches meanwhile run without it.
fn update_booster(&mut self, db: &Arc<Database>, now: f64, ctx: &egui::Context) {
if let Some(b) = &self.booster
&& let Some(result) = b.poll()
{
self.booster = None;
self.booster_failed = result != Some(true);
}
let wanted = self.pane == Pane::Board || self.board.is_set();
if !wanted
|| self.booster.is_some()
|| self.booster_failed
|| !db.as_chessbase().is_some_and(|b| b.booster_wanted())
{
return;
}
let db = db.clone();
self.booster = Background::spawn(ctx, now, move |progress, cancel| {
match db.as_chessbase()?.build_booster(progress, cancel) {
Ok(true) => Some(true),
Ok(false) => None,
Err(e) => {
eprintln!("search booster: {e}");
Some(false)
}
}
});
}
fn start(&mut self, db: &Arc<Database>, request: Request, now: f64, ctx: &egui::Context) {
// Dropping the old job cancels it.
self.job = None;
@ -552,6 +589,22 @@ impl LargeView {
.job
.as_ref()
.map(|j| (j.work.progress() as f32 / total.max(1) as f32).min(1.0));
if let Some(b) = &self.booster {
let p = (b.progress() as f32 / total.max(1) as f32).min(1.0);
ui.horizontal(|ui| {
ui.add(egui::Spinner::new().size(14.0));
ui.label(
RichText::new(trf(
"Preparing fast position search… {p} %",
&[("p", &format!("{:.0}", p * 100.0))],
))
.weak(),
)
.on_hover_text(tr(
"The base has no usable search index (.cbb); one is built once and kept in the cache.",
));
});
}
let outcome = self.board_outcome().cloned();
let mut events = Vec::new();
self.board.keys(ui.ctx(), outcome.as_ref(), &mut events);

View file

@ -324,6 +324,13 @@ impl Library {
notes: o.notes,
},
);
// Position searches without a usable `.cbb` get our own
// booster, kept in the cache directory.
if let Database::ChessBase(b) = &o.db
&& let Some(dir) = Settings::cache_dir()
{
b.set_booster_dir(&dir.join("boosters"));
}
Slot::Ready(Arc::new(o.db))
}
Err(e) => Slot::Failed(import_error(&e)),