Vampirc UCI is a Universal Chess Interface (UCI) protocol parser and serializer.
The UCI protocol is a way for a chess engine to communicate with a chessboard GUI, such as Cute Chess.
The Vampirc Project is a chess engine and chess library suite, written in Rust. It is named for the Slovenian grandmaster Vasja Pirc, and, I guess, vampires? I dunno.
Vampirc UCI uses the PEST parser to parse the UCI messages. If you want to build your own abstractions of the protocol, the corresponding PEG grammar is available here.
To use the crate, declare a dependency on it in your Cargo.toml file:
```toml [dependencies] vampire_uci = "0.6"
```
parse(..)
method or the parse_strict(..)
method. The difference between them that is that parse_strict(..)
will return an pest::error::Error
if any of the input is unrecognized or violates the rules of the PEG grammar, whereas parse
simply ignores it. The latter is the approach recommended by the protocol specification.rust
use vampirc_uci::parse;
rust
use vampirc_uci::{UciMessage, MessageList, UciTimeControl, Serializable};
rust
let messages: MessageList = parse("uci\nposition startpos moves e2e4 e7e5\ngo ponder\n");
rust
for m in messages {
match m {
UciMessage::Uci => {
// Initialize the UCI mode of the chess engine.
}
UciMessage::Position { startpos, fen, moves } => {
// Set up the starting position in the engine and play the moves e2-e4 and e7-e5
}
UciMessage::Go { time_control, search_control } {
if let Some(tc) = time_control {
match tc {
UciTimeControl::Ponder => {
// Put the engine into ponder mode ("think" on opponent's time)
}
_ => {...}
}
}
}
_ => {...}
}
}
```rust let message = UciMessage::Option(UciOptionConfig::Spin { name: "Selectivity".to_string(), default: Some(2), min: Some(0), max: Some(4), });
println!(message); // Outputs "option name Selectivity type spin default 2 min 0 max 4"
```
The full API documentation is available at docs.rs.
The current version 0.6.x only supports the parsing of engine–bound messages. These include:
* uci
* debug
* isready
* register
* position
* setoption
* ucinewgame
* stop
* ponderhit
* quit
* go
Support for the rest is coming up.
Since 0.6.0, it does, however, support representation and serialization of all the GUI-bound messages:
* id
* uciok
* readyok
* bestmove
* copyprotection
* registration
* option