Struct usi::UsiEngineHandler [−][src]
pub struct UsiEngineHandler { /* fields omitted */ }
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
Spanws a new process of the specific USI engine.
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.
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.
Sends a command to the engine.
Spanws a new thread to monitor outputs from the engine.
hook
will be called for each USI command received.
prepare
method can only be called before listen
method.