8.0 KiB
8.0 KiB
Stockfish UCI Protocol Reference
UCI Protocol Overview
Universal Chess Interface (UCI) is a text-based protocol for communication between chess engines and GUIs. Commands are line-based with ASCII encoding.
Initialization Sequence
→ uci
← id name Stockfish 16
← id author Stockfish developers
← option name Debug Log File type string default
← option name Threads type spin default 1 min 1 max 1024
← option name Hash type spin default 16 min 1 max 33554432
← [... more options ...]
← uciok
→ isready
← readyok
Core UCI Commands
Engine Identification
uci- Initialize UCI mode, engine responds with options anduciokquit- Terminate engine process
Synchronization
isready- Synchronization command, engine respondsreadyokwhen readyucinewgame- Clear hash tables and reset for new game
Position Setup
position [fen <fenstring> | startpos] [moves <move1> ... <moveN>]
startpos- Standard starting positionfen <fenstring>- Custom position in FEN notationmoves- Apply moves from position in UCI format (e.g., e2e4, e7e8q)
Search Commands
Basic Search
go [searchmoves <move1> ... <moveN>] [ponder] [wtime <ms>] [btime <ms>]
[winc <ms>] [binc <ms>] [movestogo <n>] [depth <n>] [nodes <n>]
[mate <n>] [movetime <ms>] [infinite]
Parameters:
searchmoves- Restrict search to specific movesponder- Start pondering mode (thinking on opponent's time)wtime/btime- White/black time remaining (ms)winc/binc- White/black increment per move (ms)movestogo- Moves until next time controldepth- Search to fixed depthnodes- Search fixed number of positionsmate- Search for mate in N movesmovetime- Search for fixed time (ms)infinite- Search untilstopcommand
Search Control
stop- Stop calculating and return best moveponderhit- Opponent played expected ponder move
Engine Options
setoption name <option_name> [value <value>]
Stockfish-Specific Options
Search Parameters
MultiPV(1-500): Number of principal variations to calculateSkill Level(0-20): Playing strength limitationContempt(-100 to 100): Draw avoidance tendencyAnalysis Contempt(Off/White/Black/Both): Contempt perspectiveMove Overhead(0-5000ms): Time buffer for network/GUI delaySlow Mover(10-1000): Time management aggressivenessUCI_AnalyseMode(true/false): Optimization for analysisUCI_Chess960(true/false): Fischer Random Chess supportUCI_ShowWDL(true/false): Show win/draw/loss probabilitiesUCI_LimitStrength(true/false): Enable ELO limitationUCI_Elo(1320-3190): Target ELO when strength limited
Hash Tables
Hash(1-33554432 MB): Transposition table sizeClear Hash: Clear transposition tablePonder(true/false): Think during opponent's turn
Hardware Configuration
Threads(1-1024): Search threads (typically CPU cores)Use NNUE(true/false): Neural network evaluationEvalFile(path): Custom NNUE evaluation file
Syzygy Tablebases
SyzygyPath(path): Directory containing tablebase filesSyzygyProbeDepth(1-100): Minimum depth for tablebase probingSyzygy50MoveRule(true/false): Consider 50-move ruleSyzygyProbeLimit(0-7): Maximum pieces for probing
Debug Commands
Board Display
→ d
←
+---+---+---+---+---+---+---+---+
| r | n | b | q | k | b | n | r | 8
+---+---+---+---+---+---+---+---+
| p | p | p | p | p | p | p | p | 7
+---+---+---+---+---+---+---+---+
| | | | | | | | | 6
[...]
+---+---+---+---+---+---+---+---+
a b c d e f g h
Fen: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
Key: 8F8F01D4562F59FB
Checkers:
Evaluation
→ eval
← Total evaluation: +0.25 (white side)
← [detailed NNUE evaluation breakdown]
Performance Testing
→ bench [depth] [threads] [hash] [fenfile] [limittype] [evaltype]
Default: bench 13 1 16 default depth mixed
Search Output Format
Standard Info String
info depth <d> seldepth <sd> multipv <n> score <score> nodes <n>
nps <n> hashfull <n> tbhits <n> time <ms> pv <move1> ... <moveN>
Fields:
depth- Current search depthseldepth- Selective search depthmultipv- PV number (when MultiPV > 1)score cp <n>- Evaluation in centipawnsscore mate <n>- Mate in N moves (negative if being mated)score lowerbound/upperbound- Bound type in fail-high/lownodes- Nodes searchednps- Nodes per secondhashfull- Hash table saturation (per mill)tbhits- Tablebase positions foundtime- Search time (ms)pv- Principal variation (best line)currmove- Currently searching movecurrmovenumber- Move number in root move liststring- Free-form engine output
Win/Draw/Loss Output (UCI_ShowWDL=true)
info depth 20 score cp 15 wdl 395 604 1
WDL values in per mill: win/draw/loss from current side's perspective.
Multi-PV Example
setoption name MultiPV value 3
go depth 15
info multipv 1 depth 15 score cp 31 pv e2e4 e7e5 g1f3
info multipv 2 depth 15 score cp 20 pv d2d4 d7d5 g1f3
info multipv 3 depth 15 score cp 15 pv g1f3 g8f6 d2d4
Best Move Output
bestmove <move> [ponder <move>]
bestmove- Best move in UCI notationponder- Expected opponent response for pondering
Special cases:
bestmove (none)- No legal moves (checkmate/stalemate)bestmove 0000- Null move (analysis mode only)
Advanced Analysis Techniques
Infinite Analysis
position fen <position>
setoption name UCI_AnalyseMode value true
go infinite
[... engine thinks until stop ...]
stop
Multi-PV Analysis
setoption name MultiPV value 5
position startpos moves e2e4 e7e5
go depth 20
Mate Search
go mate 7 # Find mate in 7 moves or less
Fixed Node Search
go nodes 1000000 # Analyze exactly 1M positions
Search Move Restriction
position startpos
go searchmoves e2e4 d2d4 g1f3 # Only consider these moves
Time Management
Tournament Time Control
position startpos moves e2e4 e7e5
go wtime 300000 btime 300000 winc 2000 binc 2000 movestogo 40
5 minutes + 2 second increment, 40 moves to time control.
Sudden Death
go wtime 60000 btime 60000 # 1 minute each, no increment
Fixed Time Per Move
go movetime 5000 # Think for exactly 5 seconds
Performance Tuning
Analysis Optimization
setoption name Threads value 8
setoption name Hash value 4096
setoption name UCI_AnalyseMode value true
setoption name MultiPV value 1
Rapid/Blitz Optimization
setoption name Move Overhead value 100
setoption name Slow Mover value 50
setoption name Threads value 4
Endgame Optimization
setoption name SyzygyPath value /path/to/tablebases
setoption name SyzygyProbeDepth value 1
Error Handling
Common error responses:
Unknown command: <cmd>- Invalid UCI commandIllegal move: <move>- Move not legal in current positionInvalid position- FEN parsing failedNo such option: <name>- Unknown engine option
Protocol Extensions
Chess960 (Fischer Random)
setoption name UCI_Chess960 value true
position fen <chess960_fen> moves <move1> ...
Debug Logging
setoption name Debug Log File value debug.txt
setoption name Use Debug Log value true
NNUE Evaluation
setoption name Use NNUE value true
setoption name EvalFile value nn-[hash].nnue
Typical Usage Patterns
Game Analysis
- Set analysis mode and resources
- Load position with game moves
- Run infinite analysis
- Stop and retrieve evaluation
Opening Preparation
- Set MultiPV to compare variations
- Load opening position
- Search to fixed depth
- Compare evaluations of candidate moves
Endgame Study
- Configure tablebase paths
- Load endgame position
- Search for mate or optimal play
- Verify with tablebase hits
Engine Match
- Reset with ucinewgame
- Set time controls
- Apply moves incrementally
- Use ponder for thinking on opponent time