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 tofutofuUsiOk
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 winCheckMate(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 searchCopyProtection(StatusCheck)
copyprotection - sent by engines that check copy protection:
copyprotection error
copyprotection checking
copyprotection okRegistration(StatusCheck)
registration - sent by engines that may require the user (GUI) to register
by name and registration code.
registration error
registration checking
registration okOption(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 gameThe 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+ 4c3cUnknown(String)
This variant is a catch-all for messages that do not conform to the USI protocol.
Implementations§
Source§impl EngineMessage
impl EngineMessage
Sourcepub fn parse(input: &str) -> Result<Self, PestError<Rule>>
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
)
);Sourcepub fn parse_first_valid(input: &str) -> Option<Self>
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
impl Clone for EngineMessage
Source§fn clone(&self) -> EngineMessage
fn clone(&self) -> EngineMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more