pub struct UsiEngineHandler { /* private fields */ }Expand description
UsiEngineHandler provides a type-safe interface to the USI engine process.
§Examples
use usi::{BestMoveParams, Error, EngineCommand, GuiCommand, UsiEngineHandler};
let mut handler = UsiEngineHandler::spawn("/path/to/usi_engine", "/path/to/working_dir").unwrap();
// Get the USI engine information.
let info = handler.get_info().unwrap();
assert_eq!("engine name", info.name());
// Set options and prepare the engine.
handler.send_command(&GuiCommand::SetOption("USI_Ponder".to_string(), Some("true".to_string()))).unwrap();
handler.prepare().unwrap();
handler.send_command(&GuiCommand::UsiNewGame).unwrap();
// Start listening to the engine output.
// You can pass the closure which will be called
// everytime new command is received from the engine.
handler.listen(move |output| -> Result<(), Error> {
match output.response() {
Some(EngineCommand::BestMove(BestMoveParams::MakeMove(
ref best_move_sfen,
ref ponder_move,
))) => {
assert_eq!("5g5f", best_move_sfen);
}
_ => {}
}
Ok(())
}).unwrap();
handler.send_command(&GuiCommand::Usi).unwrap();Implementations§
Source§impl UsiEngineHandler
impl UsiEngineHandler
Sourcepub fn spawn<P: AsRef<OsStr>, Q: AsRef<Path>>(
engine_path: P,
working_dir: Q,
) -> Result<Self, Error>
pub fn spawn<P: AsRef<OsStr>, Q: AsRef<Path>>( engine_path: P, working_dir: Q, ) -> Result<Self, Error>
Spanws a new process of the specific USI engine.
Sourcepub fn get_info(&mut self) -> Result<EngineInfo, Error>
pub fn get_info(&mut self) -> Result<EngineInfo, Error>
Request metadata such as a name and available options.
Internally get_info() sends usi command and
records id and option commands until usiok is received.
Returns Error::IllegalOperation when called after listen method.
Sourcepub fn prepare(&mut self) -> Result<(), Error>
pub fn prepare(&mut self) -> Result<(), Error>
Prepare the engine to be ready to start a new game.
Internally, prepare() sends isready command and waits until readyok is received.
Returns Error::IllegalOperation when called after listen method.
Sourcepub fn send_command(&mut self, command: &GuiCommand) -> Result<(), Error>
pub fn send_command(&mut self, command: &GuiCommand) -> Result<(), Error>
Sends a command to the engine.
Trait Implementations§
Source§impl Debug for UsiEngineHandler
impl Debug for UsiEngineHandler
Auto Trait Implementations§
impl Freeze for UsiEngineHandler
impl RefUnwindSafe for UsiEngineHandler
impl Send for UsiEngineHandler
impl Sync for UsiEngineHandler
impl Unpin for UsiEngineHandler
impl UnwindSafe for UsiEngineHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more