The communication protocol is loosely based on the Universal Chess Interface (UCI).
All communication between the engine and the UI happens through the
engine's stdin and stdout. Every message should be ended with a single
newline character \n
. Newlines inside a message is not allowed, but
other arbitrary whitespace between fields is:
Valid message:
position\tstartpos e3b\n
Invalid message:
position\nstartpos e3b\n
All moves are 3 characters (for example a5b
) where the first two characters
denote the square on the board
a b c d e f g h
1
2
3
4
5
6
7
8
and the third character represents the player of the move, either b
for
black or w
for white. The move notation is case-insensitive.
The starting board configuration looks like the following:
a b c d e f g h
1
2
3
4 W B
5 B W
6
7
8
The communication protocol is designed to allow stateless engines. In
other words, the engine should not have to save any data between
successive go
messages. All data that is needed to evaluate a position
is sent in the position
message. This helps with keeping the engine
synchronized. If the engine chooses to keep internal state these messages
can be used to detect mismatches between the engine and the UI.
While not mandatory, an engine is allowed to save state between successive
go
messages, however it is not allowed to modify any state related to
the search after the bestmove
message has been sent. The position
message should be still be parsed into the internal state representation
of the engine, but no search can take place.
reversi_v1
- Initialize the engine to communicate according the protocol described
in this document. This is required to be the first message sent from
the UI to the engine and the engine needs to respond with
id
messages followed byreversi_v1_ok
.
- Initialize the engine to communicate according the protocol described
in this document. This is required to be the first message sent from
the UI to the engine and the engine needs to respond with
newgame b|w
- Initialize a new game in the engine.
position
andgo
commands sent after this should be assumed to belong to the same game.b
orw
gives the color that this engine is playing this game.
- Initialize a new game in the engine.
isready
- Used to wait for the engine when multiple commands have been sent for
for synchronization purposes. Specifically this is sent after sending
newgame
orposition
to give the engine time to initialize fully before continuing.
- Used to wait for the engine when multiple commands have been sent for
for synchronization purposes. Specifically this is sent after sending
position startpos moves...
- Load the position for searching.
startpos
corresponds to the following squares being filled:d4b e4w d5w e5b
.moves...
is a list of moves describing the additional moves that have been played since the start of the game. Note that at the start of the game there are no additional moves, in which case the message is onlyposition startpos
.
- Load the position for searching.
go btime=<t> wtime=<t> binc=<t> winc<t>
- Initiate a search in the engine. The order of the
btime
,wtime
,binc
andwinc
key-values is not guaranteed.btime
andwtime
give the total time remaining for black and white respectively andbinc
andwinc
gives the time increase after each completed move. After sending this message the UI will await abestmove
message from the engine.
- Initiate a search in the engine. The order of the
id
name MyEngine 1.0
- Sent from the engine to the UI after receiving
reversi_v1
. The message should specify the name of the engine, for exampleid name MyEngine 1.0
- Sent from the engine to the UI after receiving
author AuthorNickname
- Sent from the engine to the UI after receiving
reversi_v1
. The message should specify the author of the engine, for exampleid author AuthorNickname
- Sent from the engine to the UI after receiving
reversi_v1_ok
- Sent after the
id
messages to signify that the engine configuration is complete.
- Sent after the
readyok
- Sent by the engine in response to an
isready
from the UI.
- Sent by the engine in response to an
bestmove <move>
- The best move found by the engine. Note that the player should still be included in the move.