play: the tags of a game against Maia shared (desktop and Android)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
68941d3341
commit
57cc4b2360
4 changed files with 73 additions and 34 deletions
|
|
@ -2109,16 +2109,6 @@ impl GameView {
|
|||
{
|
||||
self.board.set_premove(from, to);
|
||||
}
|
||||
let maia = format!("Maia {}", start.strength);
|
||||
let you = if start.user_name.is_empty() {
|
||||
"?".to_owned()
|
||||
} else {
|
||||
start.user_name.clone()
|
||||
};
|
||||
let (white, black) = match start.user {
|
||||
Color::White => (you, maia),
|
||||
Color::Black => (maia, you),
|
||||
};
|
||||
let event = match start.clock {
|
||||
Some(tc) => trf(
|
||||
"Game vs computer, {speed}",
|
||||
|
|
@ -2127,30 +2117,16 @@ impl GameView {
|
|||
None => tr("Game vs computer").to_owned(),
|
||||
};
|
||||
let g = &mut self.game;
|
||||
g.set_tag("Event", &event);
|
||||
g.set_tag("Site", "ChessPenguin");
|
||||
g.set_tag("White", &white);
|
||||
g.set_tag("Black", &black);
|
||||
let (we, be) = match start.user {
|
||||
Color::White => (start.user_elo, Some(start.strength)),
|
||||
Color::Black => (Some(start.strength), start.user_elo),
|
||||
};
|
||||
if let Some(e) = we {
|
||||
g.set_tag("WhiteElo", &e.to_string());
|
||||
}
|
||||
if let Some(e) = be {
|
||||
g.set_tag("BlackElo", &e.to_string());
|
||||
}
|
||||
let (wt, bt) = match start.user {
|
||||
Color::White => ("human", "program"),
|
||||
Color::Black => ("program", "human"),
|
||||
};
|
||||
g.set_tag("WhiteType", wt);
|
||||
g.set_tag("BlackType", bt);
|
||||
g.set_tag(
|
||||
"TimeControl",
|
||||
for (name, value) in ::play::game_tags(
|
||||
&event,
|
||||
start.user,
|
||||
&start.user_name,
|
||||
start.user_elo,
|
||||
start.strength,
|
||||
&start.clock.map_or_else(|| "-".to_owned(), |tc| tc.pgn()),
|
||||
);
|
||||
) {
|
||||
g.set_tag(&name, &value);
|
||||
}
|
||||
// From a position of another game: its moves are already here; after the last
|
||||
// of them, where the game comes from (a comment of the game, written in PGN).
|
||||
let floor = match &start.from {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ pub use online::{
|
|||
AccountLookup, DownloadState, OnlineAccount, OnlineDatabase, OnlineDownload, OnlineFailure,
|
||||
OnlineProblem, OnlineTarget, Site,
|
||||
};
|
||||
pub use play::{GameEnding, MaiaPlayer, ResignJudge, hopeless_turns, maia_pause_ms, maia_range};
|
||||
pub use play::{
|
||||
GameEnding, MaiaPlayer, ResignJudge, hopeless_turns, maia_game_tags, maia_pause_ms, maia_range,
|
||||
};
|
||||
pub use review::{GameReview, MoveJudgement, ReviewMove, ReviewPoint, ReviewState, SideReview};
|
||||
pub use session::{Edited, GameSession, own_create, own_remove, own_save};
|
||||
pub use train::{TrainState, TrainStats, TrainVerdict, Trainer, trainer_set_file};
|
||||
|
|
|
|||
|
|
@ -60,6 +60,26 @@ pub fn maia_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`.
|
||||
#[uniffi::export]
|
||||
pub fn maia_game_tags(
|
||||
event: String,
|
||||
user_white: bool,
|
||||
user_name: String,
|
||||
strength: u32,
|
||||
) -> Vec<crate::Tag> {
|
||||
let user = if user_white {
|
||||
shakmaty::Color::White
|
||||
} else {
|
||||
shakmaty::Color::Black
|
||||
};
|
||||
::play::game_tags(&event, user, &user_name, None, strength, "-")
|
||||
.into_iter()
|
||||
.map(|(name, value)| crate::Tag { name, value })
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Maia's turns in a row with her position hopeless before she offers to resign.
|
||||
#[uniffi::export]
|
||||
pub fn hopeless_turns() -> u32 {
|
||||
|
|
|
|||
|
|
@ -126,6 +126,47 @@ pub fn pause(clock: Option<(Duration, u32)>, ply: usize, only_move: bool) -> Dur
|
|||
Duration::from_secs_f32(secs)
|
||||
}
|
||||
|
||||
// ----- the game's tags -----------------------------------------------------------------
|
||||
|
||||
/// The tags of a game against Maia (as Lichess writes a game against a program):
|
||||
/// `event` in the app's language, the user's name ("?" unknown) and rating, Maia's
|
||||
/// strength, the time control in PGN ("-": none). The rest (date, result) is the game's.
|
||||
pub fn game_tags(
|
||||
event: &str,
|
||||
user: Color,
|
||||
user_name: &str,
|
||||
user_elo: Option<u32>,
|
||||
strength: u32,
|
||||
time_control: &str,
|
||||
) -> Vec<(String, String)> {
|
||||
let maia = format!("Maia {strength}");
|
||||
let you = if user_name.trim().is_empty() {
|
||||
"?".to_owned()
|
||||
} else {
|
||||
user_name.trim().to_owned()
|
||||
};
|
||||
let (white, black, we, be, wt, bt) = match user {
|
||||
Color::White => (you, maia, user_elo, Some(strength), "human", "program"),
|
||||
Color::Black => (maia, you, Some(strength), user_elo, "program", "human"),
|
||||
};
|
||||
let mut tags = vec![
|
||||
("Event".to_owned(), event.to_owned()),
|
||||
("Site".to_owned(), "ChessPenguin".to_owned()),
|
||||
("White".to_owned(), white),
|
||||
("Black".to_owned(), black),
|
||||
];
|
||||
if let Some(e) = we {
|
||||
tags.push(("WhiteElo".to_owned(), e.to_string()));
|
||||
}
|
||||
if let Some(e) = be {
|
||||
tags.push(("BlackElo".to_owned(), e.to_string()));
|
||||
}
|
||||
tags.push(("WhiteType".to_owned(), wt.to_owned()));
|
||||
tags.push(("BlackType".to_owned(), bt.to_owned()));
|
||||
tags.push(("TimeControl".to_owned(), time_control.to_owned()));
|
||||
tags
|
||||
}
|
||||
|
||||
// ----- Maia resigns --------------------------------------------------------------------
|
||||
|
||||
/// Nodes the judge searches a position: a tenth of a second or two, enough to see that
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue