From 71a166c92773ff7ba1e6387f0362328e54cef976 Mon Sep 17 00:00:00 2001 From: Baptiste Fouques Date: Wed, 22 Feb 2023 11:41:58 +0100 Subject: [PATCH] manage (none) best move for mate --- chess_uci/src/uci_command.rs | 11 ++++++----- chess_uci_demo/src/main.rs | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/chess_uci/src/uci_command.rs b/chess_uci/src/uci_command.rs index 68db0eb..503159a 100644 --- a/chess_uci/src/uci_command.rs +++ b/chess_uci/src/uci_command.rs @@ -71,7 +71,7 @@ pub enum EngineCommand { UciOk, ReadyOk, BestMove { - best_move: ChessMove, + best_move: Option, ponder: Option, }, CopyProtection, // unimplemented @@ -141,16 +141,17 @@ pub fn parse(message: &mut str) -> Result { Some("readyok") => unimplemented!(), Some("bestmove") => match message_iter.collect::>().as_slice() { [] => Err("Empty bestmove command"), + ["(none)"] => Ok(EngineCommand::BestMove { best_move: None, ponder: None }), [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"] => Err("Empty ponder in bestmove command"), [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( - 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"), }, diff --git a/chess_uci_demo/src/main.rs b/chess_uci_demo/src/main.rs index 1c25436..053e56d 100644 --- a/chess_uci_demo/src/main.rs +++ b/chess_uci_demo/src/main.rs @@ -63,11 +63,11 @@ pub fn main() { uci.push_raw("d\n"); - uci.go().expect("can not make engine move"); + uci.go(); loop { match uci.pull() { - Some(EngineCommand::BestMove { best_move, .. }) => { + Some(EngineCommand::BestMove { best_move: Some(best_move), .. }) => { uci.make_move(&best_move); break; }