In the world of chess analysis, the quest for improvement knows no bounds. Whether you're a casual player seeking to enhance your skills or a seasoned grandmaster aiming for that competitive edge, the allure of understanding the intricate dance of pieces on the board is universal. Enter Stockfish, a name synonymous with chess excellence. As one of the most powerful open-source chess engines available, Stockfish has become the go-to tool for unraveling the complexities of chess positions and refining strategic thinking. While many are familiar with graphical user interfaces (GUIs) for interacting with Stockfish, the true depth of its capabilities lies in the command line interface. In this blog post, we will delve into the art of using Stockfish through the command line, unlocking a realm of analysis and mastery that is both powerful and flexible. Whether you're a command line connoisseur or just starting to explore its possibilities, prepare to embark on a journey to harness Stockfish's potential like never before.
Stockfish is based on the UCI protocol. The following page is based on the Stockfish command documentation
The first and most useful command for beginner is the d
command that display the current position with ASCII art and FEN:
d
+---+---+---+---+---+---+---+---+
| r | n | b | q | k | b | n | r | 8
+---+---+---+---+---+---+---+---+
| p | p | p | p | p | p | p | p | 7
+---+---+---+---+---+---+---+---+
| | | | | | | | | 6
+---+---+---+---+---+---+---+---+
| | | | | | | | | 5
+---+---+---+---+---+---+---+---+
| | | | | | | | | 4
+---+---+---+---+---+---+---+---+
| | | | | | | | | 3
+---+---+---+---+---+---+---+---+
| P | P | P | P | P | P | P | P | 2
+---+---+---+---+---+---+---+---+
| R | N | B | Q | K | B | N | R | 1
+---+---+---+---+---+---+---+---+
a b c d e f g h
Fen: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
Key: 8F8F01D4562F59FB
Checkers:
The command position startpos
reset the game in the start position:
position startpos
d
+---+---+---+---+---+---+---+---+
| r | n | b | q | k | b | n | r | 8
+---+---+---+---+---+---+---+---+
| p | p | p | p | p | p | p | p | 7
+---+---+---+---+---+---+---+---+
| | | | | | | | | 6
+---+---+---+---+---+---+---+---+
| | | | | | | | | 5
+---+---+---+---+---+---+---+---+
| | | | | | | | | 4
+---+---+---+---+---+---+---+---+
| | | | | | | | | 3
+---+---+---+---+---+---+---+---+
| P | P | P | P | P | P | P | P | 2
+---+---+---+---+---+---+---+---+
| R | N | B | Q | K | B | N | R | 1
+---+---+---+---+---+---+---+---+
a b c d e f g h
Fen: rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
Key: 8F8F01D4562F59FB
Checkers:
The current game position can be set by a fenstring or a sequence of moves.
position startpos moves e2e4 d7d5
position fen rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 1
For example, the two last commands set the game in the same position:
d
+---+---+---+---+---+---+---+---+
| r | n | b | q | k | b | n | r | 8
+---+---+---+---+---+---+---+---+
| p | p | p | | p | p | p | p | 7
+---+---+---+---+---+---+---+---+
| | | | | | | | | 6
+---+---+---+---+---+---+---+---+
| | | | p | | | | | 5
+---+---+---+---+---+---+---+---+
| | | | | P | | | | 4
+---+---+---+---+---+---+---+---+
| | | | | | | | | 3
+---+---+---+---+---+---+---+---+
| P | P | P | P | | P | P | P | 2
+---+---+---+---+---+---+---+---+
| R | N | B | Q | K | B | N | R | 1
+---+---+---+---+---+---+---+---+
a b c d e f g h
Fen: rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 1
Key: 96270AD18105C788
Checkers:
The go
command start calculating on the current position set up with the position
command.
go depth 30
calculate with a depth of 30go movetime 5000
calculate for exactly 5 secondsFor example, the following run Stockfish from the starting position.
go depth 10
info string NNUE evaluation using nn-5af11540bbfe.nnue enabled
info depth 1 seldepth 1 multipv 1 score cp 2 nodes 27 nps 27000 hashfull 0 tbhits 0 time 1 pv g1f3
info depth 2 seldepth 2 multipv 1 score cp 2 nodes 53 nps 26500 hashfull 0 tbhits 0 time 2 pv g1f3
info depth 3 seldepth 3 multipv 1 score cp 23 nodes 150 nps 75000 hashfull 0 tbhits 0 time 2 pv d2d4 d7d5 g1f3
info depth 4 seldepth 5 multipv 1 score cp 20 nodes 250 nps 125000 hashfull 0 tbhits 0 time 2 pv e2e4 e7e5 g1f3
info depth 5 seldepth 5 multipv 1 score cp 25 nodes 300 nps 150000 hashfull 0 tbhits 0 time 2 pv e2e4 e7e5 g1f3 b8c6
info depth 6 seldepth 6 multipv 1 score cp 25 nodes 404 nps 202000 hashfull 0 tbhits 0 time 2 pv e2e4 e7e5 g1f3 b8c6 d2d4 e5d4 f3d4
info depth 7 seldepth 9 multipv 1 score cp 25 nodes 486 nps 243000 hashfull 0 tbhits 0 time 2 pv e2e4 e7e5 g1f3 b8c6 d2d4 e5d4 f3d4 g8f6 d4c6
info depth 8 seldepth 9 multipv 1 score cp 25 nodes 584 nps 292000 hashfull 0 tbhits 0 time 2 pv e2e4 e7e5 g1f3 b8c6 d2d4 e5d4 f3d4 g8f6 d4c6
info depth 9 seldepth 11 multipv 1 score cp 25 nodes 813 nps 406500 hashfull 0 tbhits 0 time 2 pv e2e4 e7e5 g1f3 b8c6 d2d4 e5d4 f3d4 g8f6 d4c6
info depth 10 seldepth 11 multipv 1 score cp 28 nodes 977 nps 488500 hashfull 0 tbhits 0 time 2 pv e2e4 e7e5 g1f3 b8c6 d2d4 e5d4 f3d4 g8f6 d4c6 b7c6 f1d3
bestmove e2e4 ponder e7e5
The last line shows the best white move : e2e4
To increase speed, you can use multiple CPU / Threads with the following command:
setoption name Threads value 4
Here is the result:
Stockfish can provide principal variations when searching. For example, the following setting set the 5 best variations:
setoption name MultiPV value 5
When running Stockfish, we get the 5 variations:
go depth 5
info string NNUE evaluation using nn-5af11540bbfe.nnue enabled
info depth 1 seldepth 1 multipv 1 score cp 21 nodes 490 nps 245000 hashfull 0 tbhits 0 time 2 pv d2d4
info depth 1 seldepth 1 multipv 2 score cp 21 nodes 490 nps 245000 hashfull 0 tbhits 0 time 2 pv e2e4
info depth 1 seldepth 1 multipv 3 score cp 17 nodes 490 nps 245000 hashfull 0 tbhits 0 time 2 pv g1f3
info depth 1 seldepth 1 multipv 4 score cp -16 nodes 490 nps 245000 hashfull 0 tbhits 0 time 2 pv e2e3
info depth 1 seldepth 1 multipv 5 score cp -25 nodes 490 nps 245000 hashfull 0 tbhits 0 time 2 pv a2a3
info depth 2 seldepth 2 multipv 1 score cp 30 nodes 1504 nps 752000 hashfull 0 tbhits 0 time 2 pv e2e4
info depth 2 seldepth 2 multipv 2 score cp 17 nodes 1504 nps 752000 hashfull 0 tbhits 0 time 2 pv d2d4 g8f6
info depth 2 seldepth 2 multipv 3 score cp 17 nodes 1504 nps 752000 hashfull 0 tbhits 0 time 2 pv g1f3 d7d5
info depth 2 seldepth 2 multipv 4 score cp 6 nodes 1504 nps 752000 hashfull 0 tbhits 0 time 2 pv e2e3 e7e6
info depth 2 seldepth 2 multipv 5 score cp 3 nodes 1504 nps 752000 hashfull 0 tbhits 0 time 2 pv a2a3 e7e5
info depth 3 seldepth 4 multipv 1 score cp 29 nodes 2697 nps 1348500 hashfull 0 tbhits 0 time 2 pv e2e4 e7e6 d2d4
info depth 3 seldepth 3 multipv 2 score cp 17 nodes 2697 nps 1348500 hashfull 0 tbhits 0 time 2 pv d2d4 g8f6 g1f3
info depth 3 seldepth 3 multipv 3 score cp 17 nodes 2697 nps 1348500 hashfull 0 tbhits 0 time 2 pv g1f3 d7d5 d2d4
info depth 3 seldepth 3 multipv 4 score cp 6 nodes 2697 nps 1348500 hashfull 0 tbhits 0 time 2 pv e2e3 e7e6 g1f3
info depth 3 seldepth 5 multipv 5 score cp 3 nodes 2697 nps 1348500 hashfull 0 tbhits 0 time 2 pv c2c3 g8f6
info depth 4 seldepth 4 multipv 1 score cp 29 nodes 3663 nps 1831500 hashfull 0 tbhits 0 time 2 pv e2e4 e7e6 d2d4
info depth 4 seldepth 4 multipv 2 score cp 17 nodes 3663 nps 1831500 hashfull 0 tbhits 0 time 2 pv d2d4 g8f6 g1f3 d7d5
info depth 4 seldepth 4 multipv 3 score cp 17 nodes 3663 nps 1831500 hashfull 0 tbhits 0 time 2 pv g1f3 d7d5 d2d4 g8f6
info depth 4 seldepth 4 multipv 4 score cp 6 nodes 3663 nps 1831500 hashfull 0 tbhits 0 time 2 pv e2e3 e7e6 g1f3 g8f6
info depth 4 seldepth 4 multipv 5 score cp 3 nodes 3663 nps 1831500 hashfull 0 tbhits 0 time 2 pv c2c3 g8f6 d2d4 c7c5
info depth 5 seldepth 6 multipv 1 score cp 29 nodes 5821 nps 1940333 hashfull 1 tbhits 0 time 3 pv e2e4 e7e6 d2d4
info depth 5 seldepth 5 multipv 2 score cp 17 nodes 5821 nps 1940333 hashfull 1 tbhits 0 time 3 pv d2d4 g8f6 g1f3 d7d5 e2e3
info depth 5 seldepth 5 multipv 3 score cp 17 nodes 5821 nps 1940333 hashfull 1 tbhits 0 time 3 pv g1f3 d7d5 d2d4 g8f6 e2e3
info depth 5 seldepth 5 multipv 4 score cp 6 nodes 5821 nps 1940333 hashfull 1 tbhits 0 time 3 pv e2e3 e7e6 g1f3 g8f6 d2d4
info depth 5 seldepth 5 multipv 5 score cp 3 nodes 5821 nps 1940333 hashfull 1 tbhits 0 time 3 pv c2c3 g8f6 d2d4 c7c5 g1f3
bestmove e2e4 ponder e7e6
Note that in the results cp
means centipawns. This represent the score from the engine's point of view in centipawns.
Above, the variation 1 is favorable to the white of 29 centipaws, the second variation has a score of 17 centipawn, and so on.