The Universal Chess Interface (UCI) is a protocol that enables communication between a chess engine and a graphical user interface (GUI). This document describes the main UCI commands and their usage.
- The engine receives commands through standard input (stdin)
- The engine sends responses through standard output (stdout)
- All commands and responses are text-based
- Each command is terminated by a newline character
- Purpose: Initial handshake between GUI and engine
- Engine Response:
id name <engine_name>
id author <author_name>
option name <option_name> type <option_type> ...
uciok
- Purpose: Check if engine is ready to receive commands
- Engine Response:
readyok
- Purpose: Signal the start of a new game
- Engine Response: None required
- Purpose: Set up a position on the internal board
- Parameters:
fen <fenstring>: Set up position from FEN stringstartpos: Set up initial positionmoves <move1> ... <movei>: List of moves to play from the position
- Example:
position startpos moves e2e4 e7e5
- Purpose: Start calculating on the current position
- Parameters (all optional):
searchmoves <move1> ... <movei>: Restrict search to these movesponder: Start searching in pondering modewtime <x>: White has x msec leftbtime <x>: Black has x msec leftwinc <x>: White increment per move in msecbinc <x>: Black increment per move in msecmovestogo <x>: There are x moves to the next time controldepth <x>: Search x plies onlynodes <x>: Search x nodes onlymate <x>: Search for mate in x movesmovetime <x>: Search exactly x msecinfinite: Search until the "stop" command
- Engine Response:
bestmove <move> [ponder <move>]
- Purpose: Stop calculating as soon as possible
- Engine Response:
bestmove <move> [ponder <move>]
- Purpose: Set the value of an option
- Example:
setoption name Hash value 128
- Purpose: Switch debug mode on or off
- Engine Response: None required
- Purpose: Quit the program as soon as possible
- Engine Response: None required
During a search, the engine can send the following information:
info depth <x> seldepth <y> time <t> nodes <n> score cp <x> pv <move1> ... <movei>
Where:
depth: Current search depthseldepth: Selective search depthtime: Time spent searching in msnodes: Number of nodes searchedscore: Evaluation scorecp <x>: Centipawns (positive for white advantage)mate <y>: Mate in y moves
pv: Principal variation (best line found)
GUI: uci
Engine: id name MyChessEngine
Engine: id author John Doe
Engine: option name Hash type spin default 128 min 1 max 1024
Engine: uciok
GUI: isready
Engine: readyok
GUI: position startpos moves e2e4 e7e5
GUI: go depth 10
Engine: info depth 1 score cp 20 nodes 20 time 1 pv e2e4
Engine: info depth 2 score cp 15 nodes 100 time 2 pv e2e4 e7e5
...
Engine: bestmove e2e4 ponder e7e5
GUI: quit
- The engine must be able to handle all commands at any time
- Commands should be processed in the order they are received
- The engine should respond to commands as quickly as possible
- During a search, the engine should regularly send info strings
- The engine must be able to stop searching immediately when receiving the "stop" command