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.prepare().unwrap();
assert_eq!("engine name", info.name());

// Set options.
handler.send_command(&GuiCommand::SetOption("USI_Ponder".to_string(), Some("true".to_string()))).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.

Bootstrap the engine and returns a metadata such as an engine name and available options. Returns Error::IllegalOperation when called after listen method.

Sends a command to the engine.

Terminates 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.

Trait Implementations

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.