manage (none) best move for mate

This commit is contained in:
Baptiste Fouques 2023-02-22 11:41:58 +01:00
parent da6060cf37
commit 71a166c927
2 changed files with 8 additions and 7 deletions

View File

@ -71,7 +71,7 @@ pub enum EngineCommand {
UciOk, UciOk,
ReadyOk, ReadyOk,
BestMove { BestMove {
best_move: ChessMove, best_move: Option<ChessMove>,
ponder: Option<ChessMove>, ponder: Option<ChessMove>,
}, },
CopyProtection, // unimplemented CopyProtection, // unimplemented
@ -141,16 +141,17 @@ pub fn parse(message: &mut str) -> Result<EngineCommand, &'static str> {
Some("readyok") => unimplemented!(), Some("readyok") => unimplemented!(),
Some("bestmove") => match message_iter.collect::<Vec<&str>>().as_slice() { Some("bestmove") => match message_iter.collect::<Vec<&str>>().as_slice() {
[] => Err("Empty bestmove command"), [] => Err("Empty bestmove command"),
["(none)"] => Ok(EngineCommand::BestMove { best_move: None, ponder: None }),
[chessmove] => Ok(EngineCommand::BestMove { [chessmove] => Ok(EngineCommand::BestMove {
best_move: ChessMove::from_str(chessmove).expect(&format!("chessmove {:?} is invalid", chessmove)), best_move: Some(
ChessMove::from_str(chessmove).expect(&format!("chessmove {:?} is invalid", chessmove))),
ponder: None, ponder: None,
}), }),
[_, "ponder"] => Err("Empty ponder in bestmove command"), [_, "ponder"] => Err("Empty ponder in bestmove command"),
[chessmove, "ponder", chess_ponder] => Ok(EngineCommand::BestMove { [chessmove, "ponder", chess_ponder] => Ok(EngineCommand::BestMove {
best_move: ChessMove::from_str(chessmove).expect("chessmove is invalid"), best_move: Some(ChessMove::from_str(chessmove).expect(&format!("chessmove {:?} is invalid", chessmove))),
ponder: Some( ponder: Some(
ChessMove::from_str(chess_ponder).expect("chessmove ponder is invalid"), ChessMove::from_str(chess_ponder).expect(&format!("ponder {:?} is invalid", chessmove))),
),
}), }),
_ => Err("Invalid chessmove subcommand"), _ => Err("Invalid chessmove subcommand"),
}, },

View File

@ -63,11 +63,11 @@ pub fn main() {
uci.push_raw("d\n"); uci.push_raw("d\n");
uci.go().expect("can not make engine move"); uci.go();
loop { loop {
match uci.pull() { match uci.pull() {
Some(EngineCommand::BestMove { best_move, .. }) => { Some(EngineCommand::BestMove { best_move: Some(best_move), .. }) => {
uci.make_move(&best_move); uci.make_move(&best_move);
break; break;
} }