Android: Rodent IV as a second opponent, with its characters and famous players
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:
parent
3dac4a185b
commit
b3774d1651
42 changed files with 4098 additions and 951 deletions
|
|
@ -26,7 +26,9 @@ pub use online::{
|
|||
OnlineProblem, OnlineTarget, Site,
|
||||
};
|
||||
pub use play::{
|
||||
GameEnding, MaiaPlayer, ResignJudge, hopeless_turns, maia_game_tags, maia_pause_ms, maia_range,
|
||||
GameEnding, MaiaPlayer, ResignJudge, Rival, RodentBook, RodentFailure, RodentPlayer,
|
||||
RodentStyle, computer_game_tags, hopeless_turns, maia_range, move_pause_ms, rival_label,
|
||||
rival_name, rodent_book_pack, rodent_range, rodent_styles, rodent_version,
|
||||
};
|
||||
pub use review::{GameReview, MoveJudgement, ReviewMove, ReviewPoint, ReviewState, SideReview};
|
||||
pub use session::{Edited, GameSession, own_create, own_remove, own_save};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
//! A game against Maia on the phone (docs/design/android-play.md §31): the small model
|
||||
//! (5M) chooses her moves at a strength on the Lichess blitz scale, by the same tables
|
||||
//! and rule as on the desktop (`maia::strength`). No clocks on the phone.
|
||||
//! A game against the computer on the phone (docs/design/android-play.md §31,
|
||||
//! android-rodent.md): Maia's small model (5M) chooses her moves at a strength of her
|
||||
//! own scale, by the same tables and rule as on the desktop (`maia::strength`); Rodent IV
|
||||
//! plays in a style, as on the desktop (`play::rodent`). No clocks on the phone.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
@ -55,20 +56,54 @@ impl GameSession {
|
|||
}
|
||||
}
|
||||
|
||||
/// How long Maia "thinks" before her move `ply` of an untimed game (milliseconds):
|
||||
/// as a person would, quicker with one legal move.
|
||||
/// How long the computer "thinks" before its move `ply` of an untimed game
|
||||
/// (milliseconds): as a person would, quicker with one legal move.
|
||||
#[uniffi::export]
|
||||
pub fn maia_pause_ms(ply: u32, only_move: bool) -> u64 {
|
||||
pub fn move_pause_ms(ply: u32, only_move: bool) -> u64 {
|
||||
::play::pause(None, ply as usize, only_move).as_millis() as u64
|
||||
}
|
||||
|
||||
/// The tags of a game against Maia on the phone (no clocks): `event` in the app's
|
||||
/// language; the user plays White when `user_white`.
|
||||
/// Who plays against the user.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Enum)]
|
||||
pub enum Rival {
|
||||
Maia,
|
||||
/// Rodent IV in a style of its list (`iv_tal`…).
|
||||
Rodent {
|
||||
style_id: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// The opponent as the game's record names it: «Maia 1500», «Rodent IV 1800 (Tal)».
|
||||
#[uniffi::export]
|
||||
pub fn maia_game_tags(
|
||||
pub fn rival_name(rival: Rival, strength: u32) -> String {
|
||||
match rival {
|
||||
Rival::Maia => format!("Maia {strength}"),
|
||||
Rival::Rodent { style_id } => {
|
||||
::play::rodent::name(strength, ::play::rodent::iv_style(&style_id).id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The opponent as the app shows it, without the style: «Maia 1500», «Rodent IV 1800».
|
||||
#[uniffi::export]
|
||||
pub fn rival_label(rival: Rival, strength: u32) -> String {
|
||||
match rival {
|
||||
Rival::Maia => format!("Maia {strength}"),
|
||||
Rival::Rodent { style_id } => format!(
|
||||
"{} {strength}",
|
||||
::play::rodent::iv_style(&style_id).rodent.name()
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// The tags of a game against the computer on the phone (no clocks): `event` in the
|
||||
/// app's language; the user plays White when `user_white`.
|
||||
#[uniffi::export]
|
||||
pub fn computer_game_tags(
|
||||
event: String,
|
||||
user_white: bool,
|
||||
user_name: String,
|
||||
rival: Rival,
|
||||
strength: u32,
|
||||
) -> Vec<crate::Tag> {
|
||||
let user = if user_white {
|
||||
|
|
@ -81,7 +116,7 @@ pub fn maia_game_tags(
|
|||
user,
|
||||
&user_name,
|
||||
None,
|
||||
&format!("Maia {strength}"),
|
||||
&rival_name(rival, strength),
|
||||
"-",
|
||||
)
|
||||
.into_iter()
|
||||
|
|
@ -178,15 +213,10 @@ impl ResignJudge {
|
|||
}
|
||||
}
|
||||
|
||||
/// Maia's own scale, as on the desktop (decisions «Сила соперника — по шкале самого
|
||||
/// движка»): the ratings her network was trained on, not a person's Elo.
|
||||
pub const PHONE_MIN: u32 = 600;
|
||||
pub const PHONE_MAX: u32 = 2600;
|
||||
|
||||
/// The strengths the phone offers: (weakest, strongest).
|
||||
/// The strengths Maia plays on her own scale, as on the desktop: (weakest, strongest).
|
||||
#[uniffi::export]
|
||||
pub fn maia_range() -> Vec<u32> {
|
||||
vec![PHONE_MIN, PHONE_MAX]
|
||||
vec![::play::MAIA_MIN, ::play::MAIA_MAX]
|
||||
}
|
||||
|
||||
/// Maia, loaded once for a game.
|
||||
|
|
@ -227,7 +257,7 @@ impl MaiaPlayer {
|
|||
.collect(),
|
||||
)
|
||||
})?;
|
||||
let strength = strength.clamp(PHONE_MIN, PHONE_MAX);
|
||||
let strength = strength.clamp(::play::MAIA_MIN, ::play::MAIA_MAX);
|
||||
let p = self
|
||||
.maia
|
||||
.predict(&history, strength, opponent.unwrap_or(strength));
|
||||
|
|
@ -235,6 +265,157 @@ impl MaiaPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
// ----- Rodent IV ---------------------------------------------------------------------
|
||||
|
||||
/// A character of Rodent IV: its id, its English name (for PGN), its title and what it
|
||||
/// does (English: the app shows its own translations), a great player or not.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Record)]
|
||||
pub struct RodentStyle {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
pub about: String,
|
||||
pub player: bool,
|
||||
}
|
||||
|
||||
/// Rodent IV's characters (the desktop's list; Rodent V is not on the phone).
|
||||
#[uniffi::export]
|
||||
pub fn rodent_styles() -> Vec<RodentStyle> {
|
||||
use ::play::rodent::{Gen, STYLES};
|
||||
STYLES
|
||||
.iter()
|
||||
.filter(|s| s.rodent == Gen::IV)
|
||||
.map(|s| RodentStyle {
|
||||
id: s.id.to_owned(),
|
||||
name: s.name.to_owned(),
|
||||
title: s.title().to_owned(),
|
||||
about: s.about.to_owned(),
|
||||
player: s.player,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The strengths Rodent IV plays (its UCI_Elo): (weakest, strongest).
|
||||
#[uniffi::export]
|
||||
pub fn rodent_range() -> Vec<u32> {
|
||||
let (lo, hi) = ::play::rodent::Gen::IV.range();
|
||||
vec![lo, hi]
|
||||
}
|
||||
|
||||
/// The version of Rodent IV's files (the authors' commit): the personalities copied out
|
||||
/// of the APK are copied again when it changes.
|
||||
#[uniffi::export]
|
||||
pub fn rodent_version() -> String {
|
||||
::play::rodent::COMMIT.to_owned()
|
||||
}
|
||||
|
||||
/// A file of the book pack: where it comes from, where it goes (under the engine's
|
||||
/// home), its size and SHA-256.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Record)]
|
||||
pub struct RodentBook {
|
||||
pub url: String,
|
||||
pub local: String,
|
||||
pub size: u64,
|
||||
pub sha256: String,
|
||||
}
|
||||
|
||||
/// The opening books Rodent IV's characters open, downloaded as one pack
|
||||
/// (android-rodent.md §5).
|
||||
#[uniffi::export]
|
||||
pub fn rodent_book_pack() -> Vec<RodentBook> {
|
||||
::play::rodent::book_pack()
|
||||
.into_iter()
|
||||
.map(|b| RodentBook {
|
||||
url: ::play::rodent::file_url(b.file),
|
||||
local: b.local,
|
||||
size: b.size,
|
||||
sha256: b.sha256.to_owned(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Rodent IV playing one game (a UCI child process, the shared crate's player).
|
||||
#[derive(uniffi::Object)]
|
||||
pub struct RodentPlayer {
|
||||
player: ::play::rodent::RodentPlayer,
|
||||
}
|
||||
|
||||
#[uniffi::export]
|
||||
impl RodentPlayer {
|
||||
/// The engine at `exe` with its personalities and books in `home`, playing
|
||||
/// `style_id` at `strength` (its UCI_Elo), with its opening book when `use_book`.
|
||||
/// It starts in the background: a failure is told by [`RodentPlayer::failure`].
|
||||
#[uniffi::constructor]
|
||||
pub fn start(
|
||||
exe: String,
|
||||
home: String,
|
||||
style_id: String,
|
||||
strength: u32,
|
||||
use_book: bool,
|
||||
) -> Arc<RodentPlayer> {
|
||||
// Below the app (nice 10), as the analysis: the interface comes first. The
|
||||
// engine finds its files by RODENT4HOME (packaging/rodent-iv/android.patch).
|
||||
let config = uci::EngineConfig {
|
||||
working_dir: Some(home.clone().into()),
|
||||
nice: 10,
|
||||
env: vec![("RODENT4HOME".into(), home.into())],
|
||||
..uci::EngineConfig::new(exe)
|
||||
};
|
||||
Arc::new(RodentPlayer {
|
||||
player: ::play::rodent::RodentPlayer::start(
|
||||
config,
|
||||
::play::rodent::iv_style(&style_id).id,
|
||||
Some(strength),
|
||||
use_book,
|
||||
Box::new(|| {}),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
/// Rodent's move (UCI) in the position at place `at` of the game, given after
|
||||
/// `pause_ms` (it thinks meanwhile). Blocks: called off the main thread. None when
|
||||
/// the game is over there, a newer request or `forget` passed it over, or Rodent
|
||||
/// failed.
|
||||
pub fn choose(&self, game: Arc<GameSession>, at: u32, pause_ms: u64) -> Option<String> {
|
||||
let (history, now) = game.read(|g| {
|
||||
let id = crate::order(g).get(at as usize).copied()?;
|
||||
Some((g.engine_history(id)?, g.position(id)?.clone()))
|
||||
})?;
|
||||
let pos = match history.start_fen {
|
||||
None => uci::EnginePosition::startpos(history.moves),
|
||||
Some(fen) => uci::EnginePosition::fen(fen, history.moves),
|
||||
};
|
||||
let generation = self
|
||||
.player
|
||||
.ask(pos, now, std::time::Duration::from_millis(pause_ms));
|
||||
let (m, _) = self.player.wait(generation)?;
|
||||
m.map(|m| m.to_uci(CastlingMode::Standard).to_string())
|
||||
}
|
||||
|
||||
/// Drops the request in flight (its position is gone): its `choose` returns none.
|
||||
pub fn forget(&self) {
|
||||
self.player.forget();
|
||||
}
|
||||
|
||||
/// Why Rodent does not play, if it does not.
|
||||
pub fn failure(&self) -> Option<RodentFailure> {
|
||||
use ::play::rodent::Failure;
|
||||
self.player.failure().map(|f| match f {
|
||||
Failure::Start(detail) => RodentFailure::DidNotStart { detail },
|
||||
// A search not taken: the process is gone in the middle of the game.
|
||||
Failure::Stopped | Failure::Search(_) => RodentFailure::Stopped,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Why Rodent does not play: it did not start (the engine's words), or it stopped
|
||||
/// during the game (android-rodent.md §6.6).
|
||||
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Enum)]
|
||||
pub enum RodentFailure {
|
||||
DidNotStart { detail: String },
|
||||
Stopped,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -271,4 +452,53 @@ mod tests {
|
|||
.id;
|
||||
assert!(m.choose(mated, end, 1500, None, 0.3).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rodent_is_named_and_listed_as_on_the_desktop() {
|
||||
let tags = computer_game_tags(
|
||||
"Game".into(),
|
||||
true,
|
||||
"Roman".into(),
|
||||
Rival::Rodent {
|
||||
style_id: "iv_tal".into(),
|
||||
},
|
||||
1800,
|
||||
);
|
||||
let black = tags.iter().find(|t| t.name == "Black").unwrap();
|
||||
assert_eq!(black.value, "Rodent IV 1800 (Tal)");
|
||||
assert_eq!(rival_name(Rival::Maia, 1500), "Maia 1500");
|
||||
let tal = Rival::Rodent {
|
||||
style_id: "iv_tal".into(),
|
||||
};
|
||||
assert_eq!(rival_label(tal, 1800), "Rodent IV 1800");
|
||||
let styles = rodent_styles();
|
||||
assert_eq!(styles.len(), 35);
|
||||
assert_eq!(styles.iter().filter(|s| s.player).count(), 22);
|
||||
assert_eq!(rodent_range(), vec![800, 2800]);
|
||||
let pack = rodent_book_pack();
|
||||
assert!(
|
||||
pack.iter()
|
||||
.all(|b| b.url.starts_with("https://raw.githubusercontent.com/")
|
||||
&& b.local.starts_with("books/")
|
||||
&& b.sha256.len() == 64)
|
||||
);
|
||||
}
|
||||
|
||||
/// Needs Rodent IV beside its files: `RODENT4=/path/rodent_iv cargo test -p mobile-api -- --ignored`.
|
||||
#[test]
|
||||
#[ignore = "needs Rodent IV (RODENT4)"]
|
||||
fn rodent_answers_with_a_legal_move() {
|
||||
let exe = std::env::var("RODENT4").expect("RODENT4");
|
||||
let home = std::path::Path::new(&exe)
|
||||
.parent()
|
||||
.unwrap()
|
||||
.display()
|
||||
.to_string();
|
||||
let r = RodentPlayer::start(exe, home, "iv_karpov".into(), 1600, false);
|
||||
let s = GameSession::from_pgn("1. e4 *".into()).unwrap();
|
||||
let e4 = s.data().nodes.iter().find(|n| n.san == "e4").unwrap().id;
|
||||
let uci = r.choose(s.clone(), e4, 300).expect("a move");
|
||||
assert!(s.legal_moves(e4).contains(&uci), "{uci}");
|
||||
assert_eq!(r.failure(), None);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "play"
|
||||
description = "A game against Maia in ChessPenguin: how it ends, Maia's pause, her resignation judged by an engine (the desktop and Android apps share it)"
|
||||
description = "A game against the computer in ChessPenguin: how it ends, the pause, resignation judged by an engine, Rodent and its files (the desktop and Android apps share it)"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
//! A game against Maia (docs/design/play-mode.md, android-play.md §31): how it ends,
|
||||
//! how long Maia "thinks", and her resignation judged by an engine. Shared by the
|
||||
//! desktop and the Android apps; nothing here draws.
|
||||
//! A game against the computer (docs/design/play-mode.md, android-play.md §31): how it
|
||||
//! ends, how long the opponent "thinks", its resignation judged by an engine, and Rodent
|
||||
//! (`rodent`). Shared by the desktop and the Android apps; nothing here draws.
|
||||
|
||||
pub mod rodent;
|
||||
mod rodent4_files;
|
||||
|
||||
use std::sync::mpsc::{Receiver, Sender, channel};
|
||||
use std::time::{Duration, Instant};
|
||||
|
|
@ -8,6 +11,11 @@ use std::time::{Duration, Instant};
|
|||
use shakmaty::zobrist::Zobrist64;
|
||||
use shakmaty::{Chess, Color, EnPassantMode, Position};
|
||||
|
||||
/// Maia's ratings: what her network was trained on (her own scale, not a person's Elo;
|
||||
/// decisions «Сила соперника — по шкале самого движка»).
|
||||
pub const MAIA_MIN: u32 = 600;
|
||||
pub const MAIA_MAX: u32 = 2600;
|
||||
|
||||
// ----- the end of a game ---------------------------------------------------------------
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
|
|
|||
857
crates/play/src/rodent.rs
Normal file
857
crates/play/src/rodent.rs
Normal file
|
|
@ -0,0 +1,857 @@
|
|||
//! Rodent, the opponent with a style (docs/research/rodent.md, docs/design/rodent-opponent.md,
|
||||
//! android-rodent.md): its styles and characters, its scales of strength, the files of
|
||||
//! Rodent IV with the books its characters open, and the engine playing a game in a
|
||||
//! thread of its own. Shared by the desktop and the Android apps; nothing here draws.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::mpsc::{Sender, channel};
|
||||
use std::sync::{Arc, Condvar, Mutex, MutexGuard};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use shakmaty::{Chess, Move};
|
||||
|
||||
pub use crate::rodent4_files::{COMMIT, FILES, PERSONALITY_BOOKS};
|
||||
|
||||
// ----- styles and characters -------------------------------------------------------------
|
||||
|
||||
/// Rodent's styles: its personality files, the personality's name (for PGN), what the
|
||||
/// style is called and does (English: the apps translate it). The players' imitations
|
||||
/// are marked `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,
|
||||
}
|
||||
|
||||
impl Style {
|
||||
/// The style's name to translate («Attacking»).
|
||||
pub fn title(&self) -> &'static str {
|
||||
self.title
|
||||
}
|
||||
}
|
||||
|
||||
/// 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Each engine on its own scale, as its authors give it (decisions «Сила соперника — по
|
||||
// шкале самого движка»): not a person's Elo.
|
||||
|
||||
/// 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;
|
||||
|
||||
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",
|
||||
},
|
||||
];
|
||||
|
||||
/// 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])
|
||||
}
|
||||
|
||||
/// Rodent IV's character of this id (Tal for an unknown one, or one of Rodent V: a
|
||||
/// phone has Rodent IV only, android-rodent.md §7.1).
|
||||
pub fn iv_style(id: &str) -> &'static Style {
|
||||
STYLES
|
||||
.iter()
|
||||
.find(|s| s.id == id && s.rodent == Gen::IV)
|
||||
.unwrap_or_else(|| style("iv_tal"))
|
||||
}
|
||||
|
||||
/// Rodent as a game names it: «Rodent V 2400» (the default style unnamed), «Rodent V 2400
|
||||
/// (Tal)», «Rodent IV 1800 (Tal)» — the personality's English name: PGN is not translated.
|
||||
pub fn name(strength: u32, style_id: &str) -> String {
|
||||
let st = style(style_id);
|
||||
if st.id == STYLES[0].id {
|
||||
format!("{} {strength}", st.rodent.name())
|
||||
} else {
|
||||
format!("{} {strength} ({})", st.rodent.name(), st.name)
|
||||
}
|
||||
}
|
||||
|
||||
// ----- Rodent IV's files ---------------------------------------------------------------
|
||||
|
||||
/// Books three personalities name by a path not in the authors' files (a case or a dash
|
||||
/// off): they are read under that name (the engine takes books only from the
|
||||
/// personality's file). (file in the repository, name it is read by)
|
||||
pub 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 «#»).
|
||||
pub fn url_path(path: &str) -> String {
|
||||
path.replace('#', "%23").replace(' ', "%20")
|
||||
}
|
||||
|
||||
/// Where a file of the authors' repository is downloaded from (at `COMMIT`).
|
||||
pub fn file_url(path: &str) -> String {
|
||||
format!(
|
||||
"https://raw.githubusercontent.com/nescitus/rodent-iv/{COMMIT}/{}",
|
||||
url_path(path)
|
||||
)
|
||||
}
|
||||
|
||||
/// An opening book of Rodent IV to download: its file in the authors' repository, where
|
||||
/// the engine reads it (relative to its home folder), its size and SHA-256.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Book {
|
||||
pub file: &'static str,
|
||||
pub local: String,
|
||||
pub size: u64,
|
||||
pub sha256: &'static str,
|
||||
}
|
||||
|
||||
/// The books Rodent IV's characters open (the guide and the main book of each), each
|
||||
/// once, under the name it is read by: the phone's book pack (android-rodent.md §5), not
|
||||
/// the books nobody uses.
|
||||
pub fn book_pack() -> Vec<Book> {
|
||||
let mut books = BTreeMap::new();
|
||||
for st in STYLES.iter().filter(|s| s.rodent == Gen::IV) {
|
||||
let Some(&(_, guide, main)) = PERSONALITY_BOOKS.iter().find(|p| p.0 == st.personality)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
for book in [guide, main] {
|
||||
let local = format!("books/{book}");
|
||||
let file = BOOK_NAMES
|
||||
.iter()
|
||||
.find(|(_, name)| *name == local)
|
||||
.map_or(local.as_str(), |(file, _)| file);
|
||||
if let Some(&(file, size, sha256)) = FILES.iter().find(|f| f.0 == file) {
|
||||
books.entry(local.clone()).or_insert(Book {
|
||||
file,
|
||||
local,
|
||||
size,
|
||||
sha256,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
books.into_values().collect()
|
||||
}
|
||||
|
||||
// ----- Rodent playing a game -----------------------------------------------------------
|
||||
|
||||
/// Why Rodent does not play.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Failure {
|
||||
/// It did not start, or did not take its options (the engine's words).
|
||||
Start(String),
|
||||
/// Its process ended during the game.
|
||||
Stopped,
|
||||
/// A search could not be asked for (the engine's words).
|
||||
Search(String),
|
||||
}
|
||||
|
||||
/// A move asked for: the game for the engine, its position now, the pause.
|
||||
struct Request {
|
||||
generation: u64,
|
||||
pos: uci::EnginePosition,
|
||||
now: Chess,
|
||||
pause: Duration,
|
||||
}
|
||||
|
||||
/// Rodent's move, or none (no legal move it gave), and the time it took.
|
||||
pub type Answer = (Option<Move>, Duration);
|
||||
|
||||
#[derive(Default)]
|
||||
struct State {
|
||||
/// The request asked last (bumped by `forget`).
|
||||
generation: u64,
|
||||
/// The newest request answered or passed over, and the answer of the newest.
|
||||
answered: u64,
|
||||
answer: Option<(u64, Answer)>,
|
||||
failure: Option<Failure>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Shared {
|
||||
state: Mutex<State>,
|
||||
changed: Condvar,
|
||||
}
|
||||
|
||||
impl Shared {
|
||||
fn lock(&self) -> MutexGuard<'_, State> {
|
||||
self.state.lock().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
fn fail(&self, f: Failure) {
|
||||
self.lock().failure = Some(f);
|
||||
self.changed.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
/// Rodent playing one game, in its own thread (a UCI child process): it thinks during
|
||||
/// the pause a move should take (a game's own clock is not its business: Maia's pause
|
||||
/// rule paces it) and answers after it. Only the newest request counts; the answer to
|
||||
/// an older one (after a take-back) is dropped.
|
||||
pub struct RodentPlayer {
|
||||
tx: Sender<Request>,
|
||||
shared: Arc<Shared>,
|
||||
}
|
||||
|
||||
impl RodentPlayer {
|
||||
/// The engine of `config` (its folder, or its home in the environment: Android)
|
||||
/// playing `style_id` at `uci_elo` (none: full strength), with its opening book when
|
||||
/// `use_book`. `wake` is called when an answer or a failure comes (the app draws again).
|
||||
pub fn start(
|
||||
config: uci::EngineConfig,
|
||||
style_id: &str,
|
||||
uci_elo: Option<u32>,
|
||||
use_book: bool,
|
||||
wake: Box<dyn Fn() + Send>,
|
||||
) -> RodentPlayer {
|
||||
let (tx, rx) = channel::<Request>();
|
||||
let shared = Arc::new(Shared::default());
|
||||
let sh = shared.clone();
|
||||
let st = style(style_id);
|
||||
let _ = std::thread::Builder::new()
|
||||
.name("rodent".into())
|
||||
.spawn(move || {
|
||||
let fail = |f: Failure| {
|
||||
sh.fail(f);
|
||||
wake();
|
||||
};
|
||||
let engine = match uci::Engine::spawn_with(config, Box::new(|| {})) {
|
||||
Ok(e) => e,
|
||||
Err(e) => return fail(Failure::Start(e.to_string())),
|
||||
};
|
||||
// V reads a personality file; IV picks one of its list (with its books).
|
||||
let book = use_book.to_string();
|
||||
let mut setup = match st.rodent {
|
||||
Gen::V => vec![
|
||||
("PersonalityFile", format!("personalities/{}.txt", st.id)),
|
||||
("OwnBook", book),
|
||||
],
|
||||
Gen::IV => vec![
|
||||
("Personality", st.personality.to_owned()),
|
||||
("UseBook", book),
|
||||
],
|
||||
};
|
||||
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(Failure::Start(e.to_string()));
|
||||
}
|
||||
for (name, value) in &setup {
|
||||
if let Err(e) = engine.set_option(name, Some(value)) {
|
||||
return fail(Failure::Start(e.to_string()));
|
||||
}
|
||||
}
|
||||
let _ = engine.new_game();
|
||||
while let Ok(mut r) = rx.recv() {
|
||||
while let Ok(newer) = rx.try_recv() {
|
||||
r = newer;
|
||||
}
|
||||
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(r.pos, id, uci::SearchLimits::MoveTime(think)) {
|
||||
return fail(Failure::Search(e.to_string()));
|
||||
}
|
||||
let mut stopped: Option<Instant> = None;
|
||||
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(Failure::Stopped);
|
||||
}
|
||||
// A search that does not end: stopped, then given up on.
|
||||
_ => match stopped {
|
||||
None if started.elapsed() > think + Duration::from_secs(20) => {
|
||||
let _ = engine.stop();
|
||||
stopped = Some(Instant::now());
|
||||
}
|
||||
Some(t) if t.elapsed() > Duration::from_secs(5) => {
|
||||
return fail(Failure::Stopped);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
};
|
||||
let m = best
|
||||
.and_then(|b| b.parse::<shakmaty::uci::UciMove>().ok())
|
||||
.and_then(|u| u.to_move(&r.now).ok());
|
||||
std::thread::sleep(r.pause.saturating_sub(started.elapsed()));
|
||||
let spent = r.pause.max(started.elapsed());
|
||||
{
|
||||
let mut s = sh.lock();
|
||||
s.answered = s.answered.max(r.generation);
|
||||
s.answer = Some((r.generation, (m, spent)));
|
||||
}
|
||||
sh.changed.notify_all();
|
||||
wake();
|
||||
}
|
||||
engine.quit();
|
||||
});
|
||||
RodentPlayer { tx, shared }
|
||||
}
|
||||
|
||||
/// Asks for a move in `now` (`pos`: the game to it for the engine) after `pause`;
|
||||
/// the request's number, for [`RodentPlayer::wait`].
|
||||
pub fn ask(&self, pos: uci::EnginePosition, now: Chess, pause: Duration) -> u64 {
|
||||
let generation = {
|
||||
let mut s = self.shared.lock();
|
||||
s.generation += 1;
|
||||
s.generation
|
||||
};
|
||||
let _ = self.tx.send(Request {
|
||||
generation,
|
||||
pos,
|
||||
now,
|
||||
pause,
|
||||
});
|
||||
generation
|
||||
}
|
||||
|
||||
/// Forgets what was asked (its answer will be dropped; a wait for it ends).
|
||||
pub fn forget(&self) {
|
||||
self.shared.lock().generation += 1;
|
||||
self.shared.changed.notify_all();
|
||||
}
|
||||
|
||||
/// The answer to the request asked last, once it has come (given once).
|
||||
pub fn answer(&self) -> Option<Answer> {
|
||||
let mut s = self.shared.lock();
|
||||
let generation = s.generation;
|
||||
match s.answer {
|
||||
Some((g, _)) if g == generation => s.answer.take().map(|(_, a)| a),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Waits for the answer to request `generation`: none when it was forgotten or
|
||||
/// passed over by a newer one, or Rodent failed.
|
||||
pub fn wait(&self, generation: u64) -> Option<Answer> {
|
||||
let mut s = self.shared.lock();
|
||||
while s.generation == generation && s.answered < generation && s.failure.is_none() {
|
||||
s = self
|
||||
.shared
|
||||
.changed
|
||||
.wait(s)
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
}
|
||||
match s.answer {
|
||||
Some((g, _)) if g == generation && s.generation == generation => {
|
||||
s.answer.take().map(|(_, a)| a)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Why Rodent does not play, if it does not.
|
||||
pub fn failure(&self) -> Option<Failure> {
|
||||
self.shared.lock().failure.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[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 read under another name are in the authors' files.
|
||||
for (file, _) in BOOK_NAMES {
|
||||
assert!(FILES.iter().any(|f| f.0 == *file), "{file}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_pack_has_the_books_of_every_character_and_no_other() {
|
||||
let pack = book_pack();
|
||||
let has = |local: &str| pack.iter().any(|b| b.local == local);
|
||||
let iv: Vec<&Style> = STYLES.iter().filter(|s| s.rodent == Gen::IV).collect();
|
||||
assert_eq!(iv.len(), 35);
|
||||
for st in iv {
|
||||
let (_, guide, main) = PERSONALITY_BOOKS
|
||||
.iter()
|
||||
.find(|p| p.0 == st.personality)
|
||||
.unwrap_or_else(|| panic!("no books for {}", st.personality));
|
||||
assert!(has(&format!("books/{guide}")), "{guide}");
|
||||
assert!(has(&format!("books/{main}")), "{main}");
|
||||
}
|
||||
// The three named otherwise come from their files in the repository.
|
||||
let spassky = pack
|
||||
.iter()
|
||||
.find(|b| b.local == "books/players/ph_spassky2.bin")
|
||||
.unwrap();
|
||||
assert_eq!(spassky.file, "books/players/ph-spassky2.bin");
|
||||
assert!(has("books/guide/strangler.bin") && has("books/guide/guide.bin"));
|
||||
// Nobody's books stay out: 59 MB of the 69.
|
||||
assert!(!has("books/guide/ph-exoticbook.bin"));
|
||||
let total: u64 = pack.iter().map(|b| b.size).sum();
|
||||
assert_eq!((total + 500_000) / 1_000_000, 59);
|
||||
assert!(
|
||||
file_url(spassky.file).ends_with(&format!("/{COMMIT}/books/players/ph-spassky2.bin"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rodent_is_named_with_its_strength_and_personality() {
|
||||
assert_eq!(name(1800, "iv_tal"), "Rodent IV 1800 (Tal)");
|
||||
assert_eq!(name(2400, "rodent"), "Rodent V 2400");
|
||||
assert_eq!(name(2400, "tal_hybrid"), "Rodent V 2400 (Tal)");
|
||||
assert_eq!(style("iv_spassky").rodent.range(), (800, 2800));
|
||||
// An unknown style (of a later version) is the default one; of Rodent IV, Tal.
|
||||
assert_eq!(style("nobody").id, "rodent");
|
||||
assert_eq!(iv_style("nobody").id, "iv_tal");
|
||||
assert_eq!(iv_style("ampere").id, "iv_tal");
|
||||
assert_eq!(iv_style("iv_karpov").id, "iv_karpov");
|
||||
}
|
||||
|
||||
/// Needs Rodent IV and its files: `RODENT4=/path/rodent_iv cargo test -p play -- --ignored`
|
||||
/// (the folder of the executable has `personalities/` and `books/`).
|
||||
#[test]
|
||||
#[ignore = "needs Rodent IV (RODENT4)"]
|
||||
fn rodent_answers_the_newest_request_only() {
|
||||
let exe = std::env::var("RODENT4").expect("RODENT4");
|
||||
let player = RodentPlayer::start(
|
||||
uci::EngineConfig::new(exe),
|
||||
"iv_tal",
|
||||
Some(1800),
|
||||
true,
|
||||
Box::new(|| {}),
|
||||
);
|
||||
let start = || uci::EnginePosition::startpos(Vec::<String>::new());
|
||||
let pause = Duration::from_millis(400);
|
||||
// Asked twice: the first is passed over, the second answered with a legal move.
|
||||
let first = player.ask(start(), Chess::default(), pause);
|
||||
let second = player.ask(start(), Chess::default(), pause);
|
||||
assert_eq!(player.wait(first), None);
|
||||
let (m, spent) = player.wait(second).expect("an answer");
|
||||
assert!(m.is_some(), "{:?}", player.failure());
|
||||
assert!(spent >= pause);
|
||||
// A request forgotten ends its wait at once.
|
||||
let third = player.ask(start(), Chess::default(), pause);
|
||||
player.forget();
|
||||
assert_eq!(player.wait(third), None);
|
||||
assert_eq!(player.failure(), None);
|
||||
}
|
||||
}
|
||||
499
crates/play/src/rodent4_files.rs
Normal file
499
crates/play/src/rodent4_files.rs
Normal file
|
|
@ -0,0 +1,499 @@
|
|||
//! 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",
|
||||
),
|
||||
];
|
||||
|
||||
/// The personalities of the engine's list: (name, guide book, main book), the books
|
||||
/// as the personality's file names them (under `books/`).
|
||||
pub const PERSONALITY_BOOKS: &[(&str, &str, &str)] = &[
|
||||
("Alekhine", "players/rj-alekhine.bin", "hist/_pre30.bin"),
|
||||
("Amanda", "guide/ph-gambitbook.bin", "rodent.bin"),
|
||||
("Ampere", "guide/active.bin", "rodent.bin"),
|
||||
("Anand", "players/ph-anand2.bin", "hist/_post06.bin"),
|
||||
("Anderssen", "players/ph-anderssen2.bin", "hist/_pre30.bin"),
|
||||
("Bosboom.txt", "players/bn-bosboom.bin", "hist/_post06.bin"),
|
||||
("Botvinnik", "players/ph-botvinnik2.bin", "hist/_31to80.bin"),
|
||||
("Cloe", "guide/closed.bin", "rodent.bin"),
|
||||
("Deborah", "guide/guide.bin", "rodent.bin"),
|
||||
("Defender", "guide/solid.bin", "rodent.bin"),
|
||||
("Dynamic", "guide/active.bin", "rodent.bin"),
|
||||
("Fischer", "players/ph-fischer2.bin", "hist/_31to80.bin"),
|
||||
("Grumpy", "guide/grandpa.bin", "rodent.bin"),
|
||||
("Karpov", "players/ph-karpov2.bin", "hist/_81to06.bin"),
|
||||
("Kasparov", "players/rj-kasparov.bin", "hist/_81to06.bin"),
|
||||
("Kortchnoi", "players/rj-kortchnoi.bin", "hist/_31to80.bin"),
|
||||
("Larsen", "players/ph-larsen2.bin", "hist/_31to80.bin"),
|
||||
("Lasker", "players/ph-lasker2.bin", "hist/_pre30.bin"),
|
||||
("Marshall", "players/rj-marshall.bin", "hist/_pre30.bin"),
|
||||
("Morphy", "players/morphy.bin", "hist/_pre30.bin"),
|
||||
("Nimzowitsch", "players/nimzowitsch.bin", "hist/_pre30.bin"),
|
||||
("Partisan", "guide/low.bin", "rodent.bin"),
|
||||
("Pawnsacker", "rodent.bin", "rodent.bin"),
|
||||
("Pedrita", "guide/solid.bin", "rodent.bin"),
|
||||
("Petrosian", "players/petrosian.bin", "hist/_31to80.bin"),
|
||||
("Preston", "guide/cs.bin", "rodent.bin"),
|
||||
("Reti", "players/ph-reti2.bin", "hist/_pre30.bin"),
|
||||
(
|
||||
"Rubinstein",
|
||||
"players/ph-rubinstein2.bin",
|
||||
"hist/_pre30.bin",
|
||||
),
|
||||
("Simple", "guide/simple.bin", "rodent.bin"),
|
||||
("Spassky", "players/ph_spassky2.bin", "hist/_31to80.bin"),
|
||||
("Spitfire", "guide/active.bin", "rodent.bin"),
|
||||
("Steinitz", "players/steinitz.bin", "hist/_pre30.bin"),
|
||||
("Strangler", "guide/strangler.bin", "rodent.bin"),
|
||||
("Tal", "players/ph-tal2.bin", "hist/_31to80.bin"),
|
||||
("Tarrasch", "players/ph-tarrasch2.bin", "hist/_pre30.bin"),
|
||||
("Topalov", "players/ph-topalov2.bin", "hist/_post06.bin"),
|
||||
];
|
||||
|
|
@ -81,6 +81,9 @@ pub struct EngineConfig {
|
|||
/// Added to the engine's nice value on Unix (0 = as the app): a phone keeps its
|
||||
/// interface smooth while the engine thinks. Every thread of the engine has it.
|
||||
pub nice: i32,
|
||||
/// Variables added to the engine's environment (Rodent IV on Android finds its
|
||||
/// personalities and books by `RODENT4HOME`).
|
||||
pub env: Vec<(OsString, OsString)>,
|
||||
}
|
||||
|
||||
impl EngineConfig {
|
||||
|
|
@ -91,6 +94,7 @@ impl EngineConfig {
|
|||
working_dir: None,
|
||||
timeouts: Timeouts::default(),
|
||||
nice: 0,
|
||||
env: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -389,6 +393,7 @@ fn spawn_impl(cfg: EngineConfig, waker: Waker) -> Result<EngineHandle, EngineErr
|
|||
let mut command = Command::new(&path);
|
||||
command
|
||||
.args(&cfg.args)
|
||||
.envs(cfg.env.iter().map(|(k, v)| (k, v)))
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
|
|
|
|||
|
|
@ -676,3 +676,25 @@ fn an_engine_can_run_below_the_app() {
|
|||
calm.quit();
|
||||
plain.quit();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn an_engine_gets_the_variables_given() {
|
||||
let engine = Engine::spawn_with(
|
||||
EngineConfig {
|
||||
env: vec![("CP_TEST_HOME".into(), "/some/where".into())],
|
||||
..config(&[])
|
||||
},
|
||||
Box::new(|| {}),
|
||||
)
|
||||
.expect("spawn");
|
||||
let environ = std::fs::read(format!("/proc/{}/environ", engine.pid())).expect("environ");
|
||||
assert!(
|
||||
environ
|
||||
.split(|&b| b == 0)
|
||||
.any(|v| v == b"CP_TEST_HOME=/some/where")
|
||||
);
|
||||
// The app's own environment goes on as well.
|
||||
assert!(environ.split(|&b| b == 0).any(|v| v.starts_with(b"PATH=")));
|
||||
engine.quit();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue