Android: Rodent IV as a second opponent, with its characters and famous players
Some checks are pending
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run
CI / macos-build (push) Waiting to run

The play sheet chooses Maia or Rodent IV, and Rodent's character in a full-screen
list (docs/design/android-rodent.md, docs/decisions.md «Rodent IV на телефоне»).
The engine is built from its authors' sources by androidApp/scripts/rodent4.sh
(patches: no wordexp.h on bionic; the search thread took its parameter by reference,
which clang builds read after it was gone) and ships in both APKs; the opening books
are one checked download. Rodent's tables, its book manifest and its opponent loop
move from the desktop into crates/play, shared by both apps; uci's EngineConfig takes
an environment (RODENT4HOME).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-27 03:03:02 +03:00
parent 3dac4a185b
commit b3774d1651
42 changed files with 4098 additions and 951 deletions

View file

@ -2601,7 +2601,7 @@ impl GameView {
"Maia did not start: {e}"
}
crate::play::Engine::Rodent(g) => {
g.remove();
crate::play::RodentFiles::remove(g);
"Rodent did not start: {e}"
}
};

View file

@ -28,7 +28,6 @@ mod player_games;
mod reference;
mod review;
mod rodent4_download;
mod rodent4_files;
mod rodent_download;
mod san;
mod settings;

View file

@ -11,7 +11,10 @@ use serde::{Deserialize, Serialize};
use crate::i18n::tr;
use crate::maia_download::Published;
pub use ::play::{Ending, HOPELESS_TURNS, Judge, ending, hopeless, pause, random_unit};
pub use ::play::rodent::{Gen, STYLES, Style, style};
pub use ::play::{
Ending, HOPELESS_TURNS, Judge, MAIA_MAX, MAIA_MIN, ending, hopeless, pause, random_unit,
};
use maia::strength::Model;
// ----- time controls --------------------------------------------------------------------
@ -153,75 +156,46 @@ pub enum Rival {
Rodent,
}
/// Rodent's styles: its personality files, the personality's name (for PGN), what the
/// style is called and does (in the app's language). The players' imitations come last
/// (`player`).
pub struct Style {
pub id: &'static str,
pub name: &'static str,
title: &'static str,
pub about: &'static str,
pub player: bool,
/// Which Rodent plays it: V (a personality file of its own) or IV (a personality of
/// its list, `personality`; docs/decisions.md «Rodent IV»).
pub rodent: Gen,
pub personality: &'static str,
/// Downloading each Rodent (the engines' tables are the shared crate's, `play::rodent`).
pub trait RodentFiles {
fn available(self) -> bool;
fn installed(self) -> Option<std::path::PathBuf>;
fn size_mb(self) -> u64;
fn start(self, ctx: &egui::Context) -> crate::engine_download::Download;
/// A file that does not start goes: the dialog offers the download again.
fn remove(self);
}
/// Rodent V or Rodent IV: each downloaded on its own, each on its own scale of strength.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Gen {
V,
IV,
}
impl Gen {
/// «Rodent V», «Rodent IV»: in the game's record and on the bar.
pub fn name(self) -> &'static str {
match self {
Gen::V => "Rodent V",
Gen::IV => "Rodent IV",
}
}
/// Its UCI_Elo.
pub fn range(self) -> (u32, u32) {
match self {
Gen::V => (RODENT_MIN, RODENT_MAX),
Gen::IV => (RODENT_MIN, RODENT_IV_MAX),
}
}
pub fn available(self) -> bool {
impl RodentFiles for Gen {
fn available(self) -> bool {
match self {
Gen::V => crate::rodent_download::available(),
Gen::IV => crate::rodent4_download::available(),
}
}
pub fn installed(self) -> Option<std::path::PathBuf> {
fn installed(self) -> Option<std::path::PathBuf> {
match self {
Gen::V => crate::rodent_download::installed(),
Gen::IV => crate::rodent4_download::installed(),
}
}
pub fn size_mb(self) -> u64 {
fn size_mb(self) -> u64 {
match self {
Gen::V => crate::rodent_download::size_mb(),
Gen::IV => crate::rodent4_download::size_mb(),
}
}
pub fn start(self, ctx: &egui::Context) -> crate::engine_download::Download {
fn start(self, ctx: &egui::Context) -> crate::engine_download::Download {
match self {
Gen::V => crate::rodent_download::start(ctx),
Gen::IV => crate::rodent4_download::start(ctx),
}
}
/// A file that does not start goes: the dialog offers the download again.
pub fn remove(self) {
fn remove(self) {
let _ = match self {
Gen::V => crate::rodent_download::remove(),
Gen::IV => crate::rodent4_download::remove(),
@ -229,412 +203,18 @@ impl Gen {
}
}
impl Style {
/// The style's name to translate («Attacking»).
pub fn title(&self) -> &'static str {
self.title
}
}
pub const STYLES: &[Style] = &[
Style {
id: "rodent",
name: "Rodent",
title: "Balanced",
about: "Even, all-round play with no bias.",
player: false,
rodent: Gen::V,
personality: "",
},
Style {
id: "ampere",
name: "Ampere",
title: "Attacking",
about: "Active pieces and attack, sound pawn structure.",
player: false,
rodent: Gen::V,
personality: "",
},
Style {
id: "chaotic",
name: "Chaotic",
title: "Chaotic",
about: "Aggressive, tricky openings, careless with pawns.",
player: false,
rodent: Gen::V,
personality: "",
},
Style {
id: "nimzoid",
name: "Nimzoid",
title: "Restricting",
about: "Closed positions, cramping the opponent, old openings.",
player: false,
rodent: Gen::V,
personality: "",
},
Style {
id: "hector",
name: "Hector",
title: "Classical",
about: "Hand-written evaluation, no neural network.",
player: false,
rodent: Gen::V,
personality: "",
},
Style {
id: "tal_hybrid",
name: "Tal",
title: "Tal",
about: "Attacking style tuned on Tal's games.",
player: true,
rodent: Gen::V,
personality: "",
},
Style {
id: "tal_nnue",
name: "Tal NNUE",
title: "Tal (network)",
about: "A neural network trained on Tal's games.",
player: true,
rodent: Gen::V,
personality: "",
},
// Rodent IV's characters, then the players it imitates (its personality list).
Style {
id: "iv_amanda",
name: "Amanda",
title: "Amanda",
about: "Attacks first, then plays for active pieces.",
player: false,
rodent: Gen::IV,
personality: "Amanda",
},
Style {
id: "iv_cloe",
name: "Cloe",
title: "Cloe",
about: "Likes closed positions.",
player: false,
rodent: Gen::IV,
personality: "Cloe",
},
Style {
id: "iv_deborah",
name: "Deborah",
title: "Deborah",
about: "Defends well and likes her bishops.",
player: false,
rodent: Gen::IV,
personality: "Deborah",
},
Style {
id: "iv_defender",
name: "Defender",
title: "Defender",
about: "Solid and careful; content with a draw.",
player: false,
rodent: Gen::IV,
personality: "Defender",
},
Style {
id: "iv_dynamic",
name: "Dynamic",
title: "Dynamic",
about: "Attacks, likes bishops, sacrifices now and then.",
player: false,
rodent: Gen::IV,
personality: "Dynamic",
},
Style {
id: "iv_grumpy",
name: "Grumpy",
title: "Grumpy",
about: "Attack and restraint; likes blocked positions, avoids draws.",
player: false,
rodent: Gen::IV,
personality: "Grumpy",
},
Style {
id: "iv_partisan",
name: "Partisan",
title: "Partisan",
about: "Attacks after quiet, stealthy openings.",
player: false,
rodent: Gen::IV,
personality: "Partisan",
},
Style {
id: "iv_pawnsacker",
name: "Pawnsacker",
title: "Pawnsacker",
about: "Balanced, but gives up pawns more readily.",
player: false,
rodent: Gen::IV,
personality: "Pawnsacker",
},
Style {
id: "iv_pedrita",
name: "Pedrita",
title: "Pedrita",
about: "Pawns, defence and restraint.",
player: false,
rodent: Gen::IV,
personality: "Pedrita",
},
Style {
id: "iv_preston",
name: "Preston",
title: "Preston",
about: "A materialistic, moderate attacker.",
player: false,
rodent: Gen::IV,
personality: "Preston",
},
Style {
id: "iv_simple",
name: "Simple",
title: "Simple",
about: "The most computer-like: plain, sound chess.",
player: false,
rodent: Gen::IV,
personality: "Simple",
},
Style {
id: "iv_spitfire",
name: "Spitfire",
title: "Spitfire",
about: "Sharp and aggressive.",
player: false,
rodent: Gen::IV,
personality: "Spitfire",
},
Style {
id: "iv_strangler",
name: "Strangler",
title: "Strangler",
about: "A boa constrictor: squeezes slowly, very human-like.",
player: false,
rodent: Gen::IV,
personality: "Strangler",
},
Style {
id: "iv_alekhine",
name: "Alekhine",
title: "Alekhine",
about: "Dynamic attacks and deep combinations.",
player: true,
rodent: Gen::IV,
personality: "Alekhine",
},
Style {
id: "iv_anand",
name: "Anand",
title: "Anand",
about: "Quick, universal play with sharp openings.",
player: true,
rodent: Gen::IV,
personality: "Anand",
},
Style {
id: "iv_anderssen",
name: "Anderssen",
title: "Anderssen",
about: "A romantic attacker of the 19th century: sacrifices.",
player: true,
rodent: Gen::IV,
personality: "Anderssen",
},
Style {
id: "iv_bosboom",
name: "Bosboom",
title: "Bosboom",
about: "Offbeat openings and creative blitz play.",
player: true,
rodent: Gen::IV,
personality: "Bosboom.txt",
},
Style {
id: "iv_botvinnik",
name: "Botvinnik",
title: "Botvinnik",
about: "Scientific, strategic play from deep preparation.",
player: true,
rodent: Gen::IV,
personality: "Botvinnik",
},
Style {
id: "iv_fischer",
name: "Fischer",
title: "Fischer",
about: "Clear, classical and precise.",
player: true,
rodent: Gen::IV,
personality: "Fischer",
},
Style {
id: "iv_karpov",
name: "Karpov",
title: "Karpov",
about: "Positional squeeze, prophylaxis and technique.",
player: true,
rodent: Gen::IV,
personality: "Karpov",
},
Style {
id: "iv_kasparov",
name: "Kasparov",
title: "Kasparov",
about: "Initiative and powerful attack.",
player: true,
rodent: Gen::IV,
personality: "Kasparov",
},
Style {
id: "iv_kortchnoi",
name: "Kortchnoi",
title: "Kortchnoi",
about: "A tenacious defender and counter-attacker.",
player: true,
rodent: Gen::IV,
personality: "Kortchnoi",
},
Style {
id: "iv_larsen",
name: "Larsen",
title: "Larsen",
about: "Original and risky, with offbeat openings.",
player: true,
rodent: Gen::IV,
personality: "Larsen",
},
Style {
id: "iv_lasker",
name: "Lasker",
title: "Lasker",
about: "A practical, psychological fighter.",
player: true,
rodent: Gen::IV,
personality: "Lasker",
},
Style {
id: "iv_marshall",
name: "Marshall",
title: "Marshall",
about: "A swashbuckling attacker with gambits.",
player: true,
rodent: Gen::IV,
personality: "Marshall",
},
Style {
id: "iv_morphy",
name: "Morphy",
title: "Morphy",
about: "Quick development and open lines.",
player: true,
rodent: Gen::IV,
personality: "Morphy",
},
Style {
id: "iv_nimzowitsch",
name: "Nimzowitsch",
title: "Nimzowitsch",
about: "Restraint, blockade and overprotection.",
player: true,
rodent: Gen::IV,
personality: "Nimzowitsch",
},
Style {
id: "iv_petrosian",
name: "Petrosian",
title: "Petrosian",
about: "Prophylaxis and safety first.",
player: true,
rodent: Gen::IV,
personality: "Petrosian",
},
Style {
id: "iv_reti",
name: "Reti",
title: "Reti",
about: "Hypermodern: controls the centre from afar.",
player: true,
rodent: Gen::IV,
personality: "Reti",
},
Style {
id: "iv_rubinstein",
name: "Rubinstein",
title: "Rubinstein",
about: "Classical positional play, great in endgames.",
player: true,
rodent: Gen::IV,
personality: "Rubinstein",
},
Style {
id: "iv_spassky",
name: "Spassky",
title: "Spassky",
about: "A universal player, at home in any position.",
player: true,
rodent: Gen::IV,
personality: "Spassky",
},
Style {
id: "iv_steinitz",
name: "Steinitz",
title: "Steinitz",
about: "The founder of positional play, a stubborn defender.",
player: true,
rodent: Gen::IV,
personality: "Steinitz",
},
Style {
id: "iv_tal",
name: "Tal",
title: "Tal (classic)",
about: "The magician from Riga: sacrifices and attack.",
player: true,
rodent: Gen::IV,
personality: "Tal",
},
Style {
id: "iv_tarrasch",
name: "Tarrasch",
title: "Tarrasch",
about: "Classical rules: space, development, active pieces.",
player: true,
rodent: Gen::IV,
personality: "Tarrasch",
},
Style {
id: "iv_topalov",
name: "Topalov",
title: "Topalov",
about: "Aggressive and dynamic, sacrifices the exchange.",
player: true,
rodent: Gen::IV,
personality: "Topalov",
},
];
/// «Attacking — Ampere»; «Balanced», «Tal»: no name twice.
fn style_label(st: &Style) -> String {
let title = tr(st.title());
// The default one is Rodent himself, the players' are named by their title, and so
// are Rodent IV's characters (their titles are their names, translated).
if st.player || st.id == "rodent" || st.title == st.name {
if st.player || st.id == "rodent" || st.title() == st.name {
title.to_owned()
} else {
format!("{title} — {}", st.name)
}
}
/// The style of this id (the default one for an unknown id).
pub fn style(id: &str) -> &'static Style {
STYLES.iter().find(|s| s.id == id).unwrap_or(&STYLES[0])
}
impl Default for PlayPrefs {
fn default() -> Self {
PlayPrefs {
@ -654,16 +234,7 @@ impl Default for PlayPrefs {
// Each engine on its own scale, as its authors give it (the owner's decision, after the
// measurements of docs/research/maia-strength.md and rodent.md): these are not a
// person's Elo, and the dialog says so.
/// Maia's ratings: what her network was trained on.
pub const MAIA_MIN: u32 = 600;
pub const MAIA_MAX: u32 = 2600;
/// Rodent's UCI_Elo.
pub const RODENT_MIN: u32 = 800;
pub const RODENT_MAX: u32 = 3000;
/// Rodent IV's UCI_Elo goes to 2800 (and plays at full strength there).
pub const RODENT_IV_MAX: u32 = 2800;
// person's Elo, and the dialog says so. The scales are the shared crate's (`play`).
/// The strengths `rival` plays (Rodent's by the engine of the style chosen).
pub fn range(rival: Rival, style_id: &str) -> (u32, u32) {
@ -874,9 +445,9 @@ pub fn clk_of(comment: &str) -> Option<Duration> {
Some(Duration::from_secs(secs))
}
// ----- Maia's moves -------------------------------------------------------------------
// ----- the opponent's moves -------------------------------------------------------------
/// A request for a move: the positions up to now, the ratings, the pause.
/// A request for Maia's move: the positions up to now, the ratings, the pause.
struct Request {
generation: u64,
positions: Vec<Chess>,
@ -884,18 +455,26 @@ struct Request {
oppo_elo: u32,
temperature: f32,
pause: Duration,
/// The game for a UCI engine (Rodent): its start and moves.
engine_pos: Option<uci::EnginePosition>,
}
/// The engine in a thread of its own: loads Maia once, answers requests after a pause.
/// An answer for an older generation (after a take-back, a resignation) is dropped.
/// What computes the opponent's moves.
enum Worker {
/// Maia in a thread of her own; her error, if loading failed.
Maia {
tx: Sender<Request>,
rx: Receiver<(u64, Option<Move>, Duration)>,
generation: u64,
error: Arc<Mutex<Option<String>>>,
},
/// Rodent, a UCI engine (the shared crate's player).
Rodent(::play::rodent::RodentPlayer),
}
/// The engine in a thread of its own: loads Maia once (or starts Rodent), answers
/// requests after a pause. An answer for an older request (after a take-back, a
/// resignation) is dropped.
pub struct Opponent {
tx: Sender<Request>,
rx: Receiver<(u64, Option<Move>, Duration)>,
generation: u64,
/// Loading failed: why (shown to the user).
pub error: Arc<Mutex<Option<String>>>,
worker: Worker,
pub thinking: bool,
}
@ -939,10 +518,12 @@ impl Opponent {
}
});
Opponent {
tx,
rx,
generation: 0,
error,
worker: Worker::Maia {
tx,
rx,
generation: 0,
error,
},
thinking: false,
}
}
@ -957,134 +538,59 @@ impl Opponent {
oppo_elo: u32,
pause: Duration,
) {
self.generation += 1;
self.thinking = true;
let _ = self.tx.send(Request {
generation: self.generation,
positions,
self_elo,
oppo_elo,
temperature,
pause,
engine_pos,
});
match &mut self.worker {
Worker::Maia { tx, generation, .. } => {
*generation += 1;
let _ = tx.send(Request {
generation: *generation,
positions,
self_elo,
oppo_elo,
temperature,
pause,
});
}
Worker::Rodent(player) => {
if let (Some(pos), Some(now)) = (engine_pos, positions.last().cloned()) {
player.ask(pos, now, pause);
}
}
}
}
/// Rodent V (`exe` in its folder) playing in `style` at `uci_elo` (none: full
/// strength), with its opening book. It thinks during the pause (a game's own clock
/// is not its business: Maia's pause rule paces it), and answers after it.
/// Rodent (`exe` in its folder) playing in `style` at `uci_elo` (none: full
/// strength), with its opening book.
pub fn start_rodent(
exe: std::path::PathBuf,
style: String,
uci_elo: Option<u32>,
ctx: &egui::Context,
) -> Opponent {
let (tx, req_rx) = channel::<Request>();
let (ans_tx, rx) = channel();
let error = Arc::new(Mutex::new(None));
let err = error.clone();
let config = uci::EngineConfig {
working_dir: exe.parent().map(|d| d.to_path_buf()),
..uci::EngineConfig::new(&exe)
};
let ctx = ctx.clone();
let _ = std::thread::Builder::new()
.name("rodent".into())
.spawn(move || {
let fail = |e: String| {
if let Ok(mut g) = err.lock() {
*g = Some(e);
}
ctx.request_repaint();
};
let config = uci::EngineConfig {
working_dir: exe.parent().map(|d| d.to_path_buf()),
..uci::EngineConfig::new(&exe)
};
let engine = match uci::Engine::spawn_with(config, Box::new(|| {})) {
Ok(e) => e,
Err(e) => return fail(start_failure(&e.to_string())),
};
// V reads a personality file; IV picks one of its list (with its books).
let st = self::style(&style);
let mut setup = match st.rodent {
Gen::V => vec![
("PersonalityFile", format!("personalities/{style}.txt")),
("OwnBook", "true".to_owned()),
],
Gen::IV => vec![
("Personality", st.personality.to_owned()),
("UseBook", "true".to_owned()),
],
};
if let Some(elo) = uci_elo {
setup.push(("UCI_LimitStrength", "true".to_owned()));
setup.push(("UCI_Elo", elo.to_string()));
}
let ready = engine.set_threads(1).and_then(|()| engine.set_hash_mb(64));
if let Err(e) = ready {
return fail(start_failure(&e.to_string()));
}
for (name, value) in &setup {
if let Err(e) = engine.set_option(name, Some(value)) {
return fail(start_failure(&e.to_string()));
}
}
let _ = engine.new_game();
while let Ok(mut r) = req_rx.recv() {
while let Ok(newer) = req_rx.try_recv() {
r = newer;
}
let (Some(pos), Some(now)) =
(r.engine_pos.clone(), r.positions.last().cloned())
else {
continue;
};
let started = Instant::now();
let id = uci::SearchId(r.generation);
// Its own limit (from UCI_Elo) ends the search early; at full strength
// it thinks for the pause.
let think = r.pause.max(Duration::from_millis(300));
if let Err(e) = engine.search(pos, id, uci::SearchLimits::MoveTime(think)) {
return fail(e.to_string());
}
let best = loop {
match engine.recv_timeout(Duration::from_millis(200)) {
Some(uci::EngineEvent::BestMove {
search_id, best: b, ..
}) if search_id == id => {
break b;
}
Some(uci::EngineEvent::Terminated(_)) => {
return fail(tr("it stopped while playing").to_owned());
}
_ if started.elapsed() > think + Duration::from_secs(20) => {
let _ = engine.stop();
}
_ => {}
}
};
let m = best
.and_then(|b| b.parse::<shakmaty::uci::UciMove>().ok())
.and_then(|u| u.to_move(&now).ok());
std::thread::sleep(r.pause.saturating_sub(started.elapsed()));
let spent = r.pause.max(started.elapsed());
if ans_tx.send((r.generation, m, spent)).is_err() {
engine.quit();
return;
}
ctx.request_repaint();
}
engine.quit();
});
let player = ::play::rodent::RodentPlayer::start(
config,
&style,
uci_elo,
true,
Box::new(move || ctx.request_repaint()),
);
Opponent {
tx,
rx,
generation: 0,
error,
worker: Worker::Rodent(player),
thinking: false,
}
}
/// Forgets what was asked (its answer will be dropped).
pub fn forget(&mut self) {
self.generation += 1;
match &mut self.worker {
Worker::Maia { generation, .. } => *generation += 1,
Worker::Rodent(player) => player.forget(),
}
self.thinking = false;
}
@ -1092,17 +598,35 @@ impl Opponent {
/// the computing when longer).
pub fn answer(&mut self) -> Option<(Move, Duration)> {
let mut out = None;
while let Ok((g, m, pause)) = self.rx.try_recv() {
if g == self.generation {
self.thinking = false;
out = m.map(|m| (m, pause));
match &mut self.worker {
Worker::Maia { rx, generation, .. } => {
while let Ok((g, m, pause)) = rx.try_recv() {
if g == *generation {
self.thinking = false;
out = m.map(|m| (m, pause));
}
}
}
Worker::Rodent(player) => {
if let Some((m, pause)) = player.answer() {
self.thinking = false;
out = m.map(|m| (m, pause));
}
}
}
out
}
pub fn failed(&self) -> Option<String> {
self.error.lock().ok().and_then(|g| g.clone())
use ::play::rodent::Failure;
match &self.worker {
Worker::Maia { error, .. } => error.lock().ok().and_then(|g| g.clone()),
Worker::Rodent(player) => player.failure().map(|f| match f {
Failure::Start(e) => start_failure(&e),
Failure::Stopped => tr("it stopped while playing").to_owned(),
Failure::Search(e) => e,
}),
}
}
}
@ -1468,11 +992,9 @@ pub fn debug_rival() -> (Rival, String) {
/// «Maia 1500», «Rodent V 2400», «Rodent V 2400 (Tal)», «Rodent IV 2000 (Petrosian)»
/// (the default style unnamed).
pub fn rival_name(rival: Rival, strength: u32, style_id: &str) -> String {
let st = style(style_id);
match rival {
Rival::Maia => format!("Maia {strength}"),
Rival::Rodent if style_id == STYLES[0].id => format!("{} {strength}", st.rodent.name()),
Rival::Rodent => format!("{} {strength} ({})", st.rodent.name(), st.name),
Rival::Rodent => ::play::rodent::name(strength, style_id),
}
}

View file

@ -9,7 +9,7 @@ use std::path::PathBuf;
use std::sync::atomic::AtomicBool;
use crate::engine_download::{Asset, Download, Failure, Stage, disk, fetch};
use crate::rodent4_files::{COMMIT, FILES};
use ::play::rodent::{BOOK_NAMES, FILES, file_url};
/// The release of our builds.
const TAG: &str = "rodent-iv-0.33";
@ -97,23 +97,6 @@ pub fn start(ctx: &egui::Context) -> Download {
Download::spawn(ctx, total(), run)
}
/// Books three personalities name by a path not in the authors' files (a case or a dash
/// off): a copy goes under that name, so that they open their book (the engine takes
/// books only from the personality's file). (file in the repository, name it is read by)
const BOOK_NAMES: &[(&str, &str)] = &[
("books/guide/Strangler.bin", "books/guide/strangler.bin"),
(
"books/players/ph-spassky2.bin",
"books/players/ph_spassky2.bin",
),
("books/guide.bin", "books/guide/guide.bin"),
];
/// A path of the repository as it goes into a URL («#readme.txt» has a «#»).
fn url_path(path: &str) -> String {
path.replace('#', "%23").replace(' ', "%20")
}
fn run(report: &dyn Fn(Stage), cancel: &AtomicBool) -> Result<PathBuf, Failure> {
let bin = binary().ok_or(Failure::Unsupported)?;
let dir = dir().ok_or_else(|| Failure::Disk("no data directory".into()))?;
@ -154,11 +137,7 @@ fn run(report: &dyn Fn(Stage), cancel: &AtomicBool) -> Result<PathBuf, Failure>
size,
zip: false,
};
let url = format!(
"https://raw.githubusercontent.com/nescitus/rodent-iv/{COMMIT}/{}",
url_path(path)
);
fetch(&url, &dest, &asset, &step(base), cancel)?;
fetch(&file_url(path), &dest, &asset, &step(base), cancel)?;
base += size;
}
report(Stage::Unpacking);
@ -178,22 +157,3 @@ fn run(report: &dyn Fn(Stage), cancel: &AtomicBool) -> Result<PathBuf, Failure>
}
result
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_file_is_where_the_engine_looks_for_it() {
assert_eq!(COMMIT.len(), 40);
assert!(FILES.iter().any(|f| f.0 == "personalities/basic.ini"));
assert!(FILES.iter().any(|f| f.0 == "personalities/tal.txt"));
assert!(FILES.iter().any(|f| f.0 == "books/rodent.bin"));
assert!(FILES.iter().all(|f| f.2.len() == 64 && !f.0.contains("..")));
assert_eq!(url_path("books/#readme.txt"), "books/%23readme.txt");
// The books copied under the names the personalities use are downloaded.
for (file, _) in BOOK_NAMES {
assert!(FILES.iter().any(|f| f.0 == *file), "{file}");
}
}
}

View file

@ -1,454 +0,0 @@
//! Generated by scripts/rodent4-manifest.py: the personalities and opening books of
//! Rodent IV as they are in the authors' repository at `COMMIT`, with their sizes and
//! SHA-256 (each is checked as it is downloaded).
pub const COMMIT: &str = "e8d84c8c8c189a1cf4eb27c578fc573af3b916d2";
/// (path in the repository, bytes, SHA-256).
pub const FILES: &[(&str, u64, &str)] = &[
(
"books/#readme.txt",
190,
"48d94c1e55cb6f98476bccaf9432166d3bb07aea664bf595c4b85a65ef43a714",
),
(
"books/guide.bin",
3056,
"168abc6dc0af6cf5c1719403e51e367cc56c5929531c8f35b8000dcda0de84ba",
),
(
"books/guide/#readme.txt",
1263,
"7a73f72ac924f4988b88da2ea6ad3168c99107202a690905e011b0f3e66f1875",
),
(
"books/guide/Strangler.bin",
10144,
"35303138aacbea4ce768414f4b7c709e5705e7d17f57a487136d6575634dfbf1",
),
(
"books/guide/active.bin",
298368,
"4ce06ffe8208ea462623d4aa2cd76e5fffb43fee568eec926dda58c49de39a74",
),
(
"books/guide/cat.bin",
3280,
"6b38a429a10d9214b2bef03ddff3f1d07ba29486e47d2b23a52ca256b7af4929",
),
(
"books/guide/closed.bin",
1312,
"eb663e1ed1e6cffbfcc33f2aed8b080df70dd6fe3e0f549a3ad20938f37f2da6",
),
(
"books/guide/cs.bin",
4336,
"ea213e6c49e32b0b0e6ab1ce48b91fff354a05893d3a7fcaef595c1b82c8ee32",
),
(
"books/guide/empty.bin",
16,
"60c69a3e87bf5c4f1e546bec45f262690bcf5494c4ecac2616bf2f731afa152a",
),
(
"books/guide/exchange.bin",
1824,
"98b191cbb8426bf4098c7330861d441315687325e5f27d7f9dc623c163c2ff39",
),
(
"books/guide/flank.bin",
186144,
"da019cc249e2f5e9559067faa7cbfeadde405cdd5f77dabd8059589329d88243",
),
(
"books/guide/grandpa.bin",
11584,
"2c2d177e4695e32e22915dc4d2d624e834d59a75aef889f9a3d2190b6d9de71e",
),
(
"books/guide/low.bin",
2432,
"549b341172c980aa7b47750b8caafa9e5e4df8161f9e9a3ae84df65a7db135a5",
),
(
"books/guide/ph-exoticbook.bin",
9361568,
"fa0f55de6bd345521633f1ad0f3171823f4ff36c8784b123c9963278bc0cac13",
),
(
"books/guide/ph-gambitbook.bin",
8407936,
"f2dddc37343b155624fddb08a7743965e806b717ac87985f887643e126119f14",
),
(
"books/guide/simple.bin",
1136,
"5c5655286dfb7828ecdc516ec5a04bc7ff82ee6d4d6d3b1e6737eea0a2a3f01c",
),
(
"books/guide/solid.bin",
702704,
"b6ed13b48ede300b9c33944e12d899daaab1fc120d129379bfe234f2f65dffc8",
),
(
"books/guide/tricky.bin",
236128,
"ea008c67e321c3460298777be6b4ad6d21384589c148bec16c8295b84870ab63",
),
(
"books/hist/#readme.txt",
285,
"7997dfcd3f1f1afd8da16ddddada703eca0a74c0e57b7ef7357e90f075c0b6e3",
),
(
"books/hist/_31to80.bin",
588640,
"c51764eab0ad6ab0659c6aba8bdfa7cec930e88dfc5887efce1e31a5ca80e81f",
),
(
"books/hist/_81to06.bin",
1393952,
"ddd3fe064d17ee52e6653dbafbd6280d2d85f09da50352366c3515585c0c8d19",
),
(
"books/hist/_post06.bin",
1474384,
"b3b1fb48054e4737b80acebe8851c152188243439bc7194b3faa01be85116ee9",
),
(
"books/hist/_pre30.bin",
169856,
"77aeca2bd8ee5996cd95683531f008b4e038c6f8a1d41550d5b02c73d4f17257",
),
(
"books/main/micro.bin",
76400,
"40b063b1a2dfff9964b3e43f76e321863a3bc40d79c9ec71d604116d5cb0fb0e",
),
(
"books/main/mini.bin",
154576,
"cde1a83f2f8d067920d9bd63bd6e66840ec8b74b4e85ed43b26e3dfcb5c0ba1d",
),
(
"books/main/small.bin",
311296,
"ef9c73df2d1df15cfd70bea5f6ed074298a583fb2248a2ea626f008bbad55148",
),
(
"books/players/#readme.txt",
908,
"fb5a69bee93feec68ee8ca24a86f7877b008a01b8438ffe5d0ae8f6874a387ad",
),
(
"books/players/bn-bosboom.bin",
538960,
"c75133dc14d07034d73e7faace7adbe6a2f8ea3a5b55ff6e2f3b6cd8b3c13b48",
),
(
"books/players/morphy.bin",
1440,
"57e6e7619ac7647acaf561e0ebc2f065c32835cadca2029386ea4bbb347f58b0",
),
(
"books/players/nimzowitsch.bin",
261040,
"64f43e651515f68c5a8e5eb1c970cfc6b49b47e30abf3a078659b5465bf79459",
),
(
"books/players/petrosian.bin",
850048,
"0393a98eaa0a86203066494447d9a90255518499ba702933118b72af281a364e",
),
(
"books/players/ph-anand2.bin",
1998384,
"ca5d7a52b33f78e857fb44f6157ac83b943dcd2e36c630c77e107a7c8d5f94ad",
),
(
"books/players/ph-anderssen2.bin",
8539632,
"7edf078361d6462584107b0b37d9c24ee6dec297936bacc6f4085069687256eb",
),
(
"books/players/ph-botvinnik2.bin",
1764656,
"dd041dad209ae2278f94ea3bd3d59aa280b07ee5b6f5e856aef87cb800bdd7e7",
),
(
"books/players/ph-fischer2.bin",
1728896,
"1b8bc31b15a135c0cef705e633524583cea304f4c44cf705bb7b0a58d0be1279",
),
(
"books/players/ph-karpov2.bin",
2287088,
"aed5d14526826482414ae9a8334cf84ee812de6da01e9f50ad14b48d3ebd7668",
),
(
"books/players/ph-larsen2.bin",
2086640,
"c88749872fa2d8f99b699d21c30e8e4b61b1a5cd84feef9eebd3354be70f37c3",
),
(
"books/players/ph-lasker2.bin",
1752464,
"7c11cc10212424fb8dd24da6e6e4fabdb6f9689d5e0eb9cd4c8d7b7494a44ef9",
),
(
"books/players/ph-reti2.bin",
1644768,
"50837dc5bed4f94a35449732c676dba3bafde132b219b63ea683b1159988f9f2",
),
(
"books/players/ph-rubinstein2.bin",
1705984,
"3dd2f06df72c2666d37ef3e397bec296add5d4e3de45bfeed6c07823de21cb36",
),
(
"books/players/ph-spassky2.bin",
2021984,
"d0c981ea25e3ab6e48984bcdd587e74d08aa6bced545b15b0d4cf3d29b8e2e3b",
),
(
"books/players/ph-tal2.bin",
2062464,
"2e7923a363a4d24fa10cda6991dc5c289cde57d536b358b45b29a157690c9c04",
),
(
"books/players/ph-tarrasch2.bin",
1677472,
"16954ddd54e2aa82dddd418fba651a6f19052205d7aa203fe9d6098a60c700b4",
),
(
"books/players/ph-topalov2.bin",
1828864,
"5a07a21d75424b59b7c1a51387868bbd0f55cf0e3eb83d223b9f0bdac410dfdf",
),
(
"books/players/rj-alekhine.bin",
865072,
"df46561ddcd723f3f01fc7c6fbab290b0c9eb2a3594a87c79eadbd87fdcc2737",
),
(
"books/players/rj-kasparov.bin",
1617072,
"06e06f3b061f31002a58a39ddf26a9fd5064b827522b06cedde25198d54d9d45",
),
(
"books/players/rj-kortchnoi.bin",
135424,
"4e2ff5a5be4aee43c56998015cc800f3537d16371dfab4be3726734b252727c9",
),
(
"books/players/rj-marshall.bin",
300688,
"c11f9dab58a0ef1efe655ca92ef010b4384e819affc7116c6ba110f33622312c",
),
(
"books/players/steinitz.bin",
81280,
"14d96f0b54b578bdead1cd214bc8fc6442f5a09a7a99f3a9ea129f47df17aa2b",
),
(
"books/rodent.bin",
10179008,
"4a65869ba4081398bfa0804b953502352815dcfae49ad5af9726a69d46047786",
),
(
"personalities/alekhine.txt",
3517,
"3d618e0a35cbcdc2467f5f114790646fe40050bea78c62c5520e888a02553bb8",
),
(
"personalities/amanda.txt",
2510,
"ff04a71cd2f1eb626d8805d37f2dd3a6904d93a1c93c5290553431453fea26b6",
),
(
"personalities/ampere.txt",
2498,
"a9ce7312c0fb8f3b0c46e3ff58e79cb10a6fd092f1cb69c480e102461861e912",
),
(
"personalities/anand.txt",
3366,
"f01b264bf221118af21f8576c8234fc7259ee32b008d7f604764f14abd38965a",
),
(
"personalities/anderssen.txt",
3274,
"5d4235febae596783c0d68c2567900440addfebf6697c48ad5d0ada2eb94cceb",
),
(
"personalities/basic.ini",
2719,
"abe0ebe031c00009d3d3bbce7daf218e54f0422a8e6ded3c29d6e9c3350551bd",
),
(
"personalities/bosboom.txt",
2904,
"172d473052ee04141235b90bceb2eace235c1c33f7c46aae292a22ceeebbaa85",
),
(
"personalities/botvinnik.txt",
3385,
"e4de674084b289e6a5eca65edce542c948e3e75ffa25c155c7af56069ff8816e",
),
(
"personalities/cloe.txt",
2483,
"dfe5a303071440c531b91437d81a47a0be1d51b4e63bdeb64794a7c2d4f504a9",
),
(
"personalities/deborah.txt",
2489,
"7d2203efdd3972a1b9bd836dc9237121873de26200f515378bc24850446f85f7",
),
(
"personalities/default.txt",
1091,
"1470a3e385b26efdd37d7ba30aae50e008a35eea78f03f683db82d02d1a2df2e",
),
(
"personalities/defender.txt",
2455,
"7b0d1e377d0862d18f8101e2068eed8486558416997fe596c42f589c525aae7c",
),
(
"personalities/dynamic.txt",
2543,
"1edd02be3baddba2f5056db8fdabfe549488c0f9832e553677227e98b3a0f404",
),
(
"personalities/fischer.txt",
3333,
"ee2ab4e175f0dbee88f2f12595393d14001915670e086198139d15ad86eae577",
),
(
"personalities/grumpy.txt",
2531,
"0ff254a3439d947756fdf748b94fcceb82cc202b46ded10e839a7204fbce3c03",
),
(
"personalities/karpov.txt",
2893,
"9ea8a26ddd30ebb7085193d2c94119bdeb9535cd7b43a283741ad27244c78aee",
),
(
"personalities/kasparov.txt",
2949,
"0167481c1a12c5ee50dcaae8d9a5de80ca5baccb44114e603ae8395cd4244f43",
),
(
"personalities/kortchnoi.txt",
3084,
"36fa917d841447df9aa2168f4f736c80d1506afe270c015ceba6a013c80802ad",
),
(
"personalities/larsen.txt",
3430,
"e0ae364f22630da9bfbe4a415ad05555a19c526a8efba2e0e716c23b603bc60b",
),
(
"personalities/lasker.txt",
2850,
"2f522070cc68bede8c77d6e7040939c0ba24aba7017988d417b37ec9a424c388",
),
(
"personalities/marshall.txt",
2960,
"38dfc223a8067f5a041e011c25c914e56bebbfd78e0dc10648c6a73a228f5711",
),
(
"personalities/morphy.txt",
2486,
"8e6d9aa1658deda43c280bef69ec6e0914c883e57f118a22c7a5edbe7cfef7de",
),
(
"personalities/nimzowitsch.txt",
2475,
"53b1825b4dd6ea709b5fcfc401ce9ab920ffcd03b9e54936e8fa3c36812ceae1",
),
(
"personalities/partisan.txt",
2504,
"483d94226b4d5b42105db4c28c0f078ae096a6f26777ee558e5c7afabc8730fe",
),
(
"personalities/pawnsacker.txt",
2563,
"bf92b869e67fce75d967f8c385787ef52ac62ffa612917184d7b6f75caff7941",
),
(
"personalities/pedrita.txt",
2482,
"3f9858b2e7912e666d4b48b6f6509d712b63428db06902b83e45aadef2988ad3",
),
(
"personalities/petrosian.txt",
3350,
"e4558a9035d0e21afa9bbd453f5ded76d22fb274ca39889cf2163d7472879ef4",
),
(
"personalities/preston.txt",
2487,
"a232ea602749587fbd15889a8948403c5ac2687234caca538d3aa6b641741944",
),
(
"personalities/reti.txt",
3327,
"8d15e479e118903309afe215cd070faaa2e4337b2b62809a26476113a9469d20",
),
(
"personalities/rubinstein.txt",
3384,
"efb9dda6d01b824ba39260881deb18a22c22774d7946eeb6adbd3d4d4c18ca39",
),
(
"personalities/simple.txt",
2510,
"19f83fb05f96039a34e0e9a36bf66fc841693f70d73ee2a243df42e90caf1613",
),
(
"personalities/spassky.txt",
3347,
"000da9c591c8e63fe5e4b11c812c42d3e700032e034f75934d67faba089b4bbd",
),
(
"personalities/spitfire.txt",
2448,
"5b42cac56aa4fbab4b6dff48e86fbfec8744e27bb310475b9bc9e91746e519f6",
),
(
"personalities/steinitz.txt",
2572,
"f7ab0efd23c94f96f025104dc82eab993163d7a7523cab8b612add1d85d1b338",
),
(
"personalities/strangler.txt",
2526,
"3ed1809e19ba622c165b9fbf8eb10f056a3acbb3a0ee2a4c32b9488919d85409",
),
(
"personalities/swapper.txt",
2513,
"d1b8ec5e016452f002609c32bc575fb9ee47ba4e0db671f82215009c731187fc",
),
(
"personalities/tal.txt",
2459,
"f6b58d7cc9e7d2fcdbbc24a20ea72035d05ca5ed5e3401bda240b1b298ce149d",
),
(
"personalities/tarrasch.txt",
2546,
"6fafaf4cb8ec37439c2471a26b9be471a35d5e14faf1a624bb2fe9edb6f3f496",
),
(
"personalities/topalov.txt",
3358,
"0e5a9fc33d3ade50d7eaa68a06d29131151d270d5d0f3afd5d408bfb9081e4d8",
),
];