EngineMessage

Enum EngineMessage 

Source
pub enum EngineMessage {
    Id(IdParams),
    UsiOk,
    ReadyOk,
    BestMove(BestMoveParams),
    CheckMate(CheckMateParams),
    CopyProtection(StatusCheck),
    Registration(StatusCheck),
    Option(OptionParam),
    Info(Vec<InfoParam>),
    Unknown(String),
}
Expand description

Messages sent from the Shogi Engine to the GUI.

Variants§

§

Id(IdParams)

id - the id message informs the GUI about the engine name and engine developer. This message is sent as initial response to the GUI usi message.

id name haitaka-shogi
id author tofutofu
§

UsiOk

usiok - sent to finalize the initial handshake between GUI and engine. This message is sent after the id and initial option messages.

§

ReadyOk

readyok - sent in response to the isready message to inform the GUI that the engine is ready to start a search.

§

BestMove(BestMoveParams)

bestmove - sent in response to a go command, to inform the GUI that the engine has stopped searching and found a good move. The engine can also use this command to resign or claim a win.

bestmove <move>
bestmove <move> ponder <move>
bestmove resign
bestmove win
§

CheckMate(CheckMateParams)

checkmate - sent as termination of a go mate command.

checkmate <moves> - a forced mate principal sequence of moves (sokuzumi)
checkmate nomate - the engine was able to prove there is no forced mate
checkmate timeout - the search timed out inconclusively
checkmate notimplemented - the engine does not implement tsume shogi search
§

CopyProtection(StatusCheck)

copyprotection - sent by engines that check copy protection:

copyprotection error
copyprotection checking
copyprotection ok
§

Registration(StatusCheck)

registration - sent by engines that may require the user (GUI) to register by name and registration code.

registration error
registration checking
registration ok
§

Option(OptionParam)

option - informs the GUI about available engine options. Options are distinguished by type and name. Examples:

option name UseBook type check default true
option name Selectivity type spin default 2 min 0 max 4
option name Style type combo default Normal var Solid var Normal var Risky
option name ResetLearning type button
option name BookFile type string default public.bin
option name LearningFile type filename default <empty>

Available engine options are sent by the engine in response to the usi command. The GUI can in that case respond by modifying an option with a setoption message. Option names can never have spaces. Certain names have fixed semantics:

- USI_Hash type spin - MB memory to use for hash tables
- USI_Ponder type check - when set, the engine is allowed to "ponder" (think during opponent's time)
- USI_OwnBook type check - the engine has its own opening book
- USI_Multipv type spin - the engine supports multi bestline mode (default is 1)
- USI_ShowCurrLine type check - the engine can show the current line while searching (false by default)
- USI_ShowRefutations type check - the engine can show a move and its refutation (false by default)
- USI_LimitStrength type check - the engine can adjust its strength (false by default)
- USI_Strength type spin - the engine plays at the indicated strenght level (negative values
represent kyu levels, positive values dan levels), requires USI_LimitStrength to be set
- USI_AnalyseMode type check - the engine may behave differently when analysing or playing a game

The USI_Hash and especially the USI_Ponder options should always be supported. Note that even when the ponder option is available and enabled, the engine should still only start pondering when it receives a go ponder command.

Engines may only support a subset of options. For details, please consult the engine documentation.

§

Info(Vec<InfoParam>)

info - informs the GUI, during the search, about the status of the search. The engine may send either selected info messages or multiple infos in one message. All infos about the principal variation should be sent in one message. Infos about multipv should be sent in successive lines. Examples:

info time 1141 depth 3 nodes 135125 score cp -1521 pv 3a3b L*4h 4c4d
info depth 2 score cp 214 time 1242 nodes 2124 nps 34928 pv 2g2f 8c8d 2f2e
info nodes 120000 nps 116391 hashfull 104
info string 7g7f (70%)
info score cp 156 multipv 1 pv P*5h 4g5g 5h5g 8b8f
info score cp -99 multipv 2 pv 2d4d 3c4e 8h5e N*7f
info score cp -157 multipv 3 pv 5g5f 4g4f 4e3c+ 4c3c
§

Unknown(String)

This variant is a catch-all for messages that do not conform to the USI protocol.

Implementations§

Source§

impl EngineMessage

Source

pub fn parse(input: &str) -> Result<Self, PestError<Rule>>

Parse one USI message, sent by the Engine and received by the GUI.

If the string contains multiple messages, only the first one is returned.

Note that all USI protocol messages must be terminated by a newline (‘\n’, ‘\r’ or ‘\r\n’). This function will return a ParseError if the input string does not end with either a newline or newline followed by ascii whitespace.

SAFETY: The parser should be able to process any newline-terminated input. An input string input that does not conform to the USI protocol is returned as Ok(GuiMessage::Unknown(input)).

§Examples
use haitaka_usi::*;
use haitaka_types::*;
let input = "bestmove 3c3d\n";
let msg = EngineMessage::parse(input).unwrap();
let mv = "3c3d".parse::<Move>().unwrap();
assert_eq!(msg,
    EngineMessage::BestMove(
        BestMoveParams::BestMove {
            bestmove: mv,
            ponder: None })
);
let input = "bestmove resign\n";
let msg = EngineMessage::parse(input).unwrap();
assert_eq!(msg,
    EngineMessage::BestMove(
        BestMoveParams::Resign
    )
);
Source

pub fn parse_first_valid(input: &str) -> Option<Self>

Parses the input and returns the first valid protocol Engine message, skipping Unknowns. Returns None if no valid Engine message is found.

§Panics

This function will panic if the input string is not newline terminated.

Trait Implementations§

Source§

impl Clone for EngineMessage

Source§

fn clone(&self) -> EngineMessage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EngineMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for EngineMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for EngineMessage

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for EngineMessage

Source§

fn eq(&self, other: &EngineMessage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for EngineMessage

Source§

impl StructuralPartialEq for EngineMessage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.