Reverse engineer an existing engine/GUI interaction
Install the software. Tested on Ubuntu 22.10:
sudo apt install stockfish scid moreutils
Create a stockfish
wrapper:
mystockfish
#!/usr/bin/env bash
rm -f /tmp/stockfish
tee -a >( ts %.S > /tmp/stockfish-in ) |
stockfish "$@" |
tee -a >( ts %.S > /tmp/stockfish-out )
sort -k2 -t ' ' --version-sort \
<( sed -r 's/^/< /' /tmp/stockfish-in ) \
<( sed -r 's/^/> /' /tmp/stockfish-out ) \
>/tmp/stockfish
TODO: any simpler way to get a similar ouput (interleaved I/O, with each line marked if it is I or O)? My Bash-fu is not good enough! I tried:
tee -a >( sed -r 's/^/< /' >> /tmp/stockfish ) |
stockfish "$@" |
tee -a >( sed -r 's/^/> /' >> /tmp/stockfish )
but then the I/O is not interleaved anymore. One day I'll figure it.
Now we point our UCI compatible UI to the helper, e.g. for scid
:
- Tools
- Analysis Engine
- New
and select mystockfish
as the helper (either entering the full path, or just basename if you placed it in your PATH
.)
Now when we start a game:
- Play
- Serious game
- Optionally to make things go faster: Fixed depth: 3
Now I play the following match against stockfish
:
- e2e4 e7e5
- d2d3 d7d5
- f2f3 g8f6
The file /tmp/stockfish
contains something like the following. I manually added a few obvious blank lines to improve readability:
< 16.582386 uci
> 16.588033 Stockfish 14.1 by the Stockfish developers (see AUTHORS file)
> 16.639218 id name Stockfish 14.1
> 16.639301 id author the Stockfish developers (see AUTHORS file)
> 16.639331
> 16.639359 option name Debug Log File type string default
> 16.639387 option name Threads type spin default 1 min 1 max 512
> 16.639414 option name Hash type spin default 16 min 1 max 33554432
> 16.639440 option name Clear Hash type button
> 16.639467 option name Ponder type check default false
> 16.639494 option name MultiPV type spin default 1 min 1 max 500
> 16.639521 option name Skill Level type spin default 20 min 0 max 20
> 16.639547 option name Move Overhead type spin default 10 min 0 max 5000
> 16.639574 option name Slow Mover type spin default 100 min 10 max 1000
> 16.639619 option name nodestime type spin default 0 min 0 max 10000
> 16.639647 option name UCI_Chess960 type check default false
> 16.639674 option name UCI_AnalyseMode type check default false
> 16.639701 option name UCI_LimitStrength type check default false
> 16.639728 option name UCI_Elo type spin default 1350 min 1350 max 2850
> 16.639755 option name UCI_ShowWDL type check default false
> 16.639782 option name SyzygyPath type string default <empty>
> 16.639809 option name SyzygyProbeDepth type spin default 1 min 1 max 100
> 16.639836 option name Syzygy50MoveRule type check default true
> 16.639863 option name SyzygyProbeLimit type spin default 7 min 0 max 7
> 16.639890 option name Use NNUE type check default true
> 16.639917 option name EvalFile type string default nn-13406b1dcbe0.nnue
> 16.639944 uciok
< 18.825968 isready
> 18.826010 readyok
< 18.826234 position fen rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1
< 18.826317 go depth 3
> 18.826442 info string NNUE evaluation using nn-13406b1dcbe0.nnue enabled
> 18.826703 info depth 1 seldepth 1 multipv 1 score cp -19 nodes 22 nps 22000 tbhits 0 time 1 pv e7e5
> 18.826807 info depth 2 seldepth 2 multipv 1 score cp 4 nodes 43 nps 43000 tbhits 0 time 1 pv e7e5 a2a3
> 18.827150 info depth 3 seldepth 3 multipv 1 score cp -23 nodes 135 nps 67500 tbhits 0 time 2 pv e7e5 a2a3 g8e7
> 18.827231 bestmove e7e5 ponder a2a3
< 19.847364 isready
> 19.847471 readyok
< 19.848898 position fen rnbqkbnr/pppp1ppp/8/4p3/4P3/3P4/PPP2PPP/RNBQKBNR b KQkq - 0 2
< 19.849063 go depth 3
> 19.849119 info string NNUE evaluation using nn-13406b1dcbe0.nnue enabled
> 19.849387 info depth 1 seldepth 1 multipv 1 score cp 15 nodes 34 nps 34000 tbhits 0 time 1 pv b8c6
> 19.849475 info depth 2 seldepth 2 multipv 1 score cp 39 nodes 72 nps 72000 tbhits 0 time 1 pv b8c6 b1d2
> 19.849798 info depth 3 seldepth 3 multipv 1 score cp 13 nodes 205 nps 102500 tbhits 0 time 2 pv d7d5 e4d5 d8d5
> 19.849887 bestmove d7d5 ponder e4d5
< 20.868239 isready
> 20.868378 readyok
< 20.869825 position fen rnbqkbnr/ppp2ppp/8/3pp3/4P3/3P1P2/PPP3PP/RNBQKBNR b KQkq - 0 3
< 20.869973 go depth 3
> 20.870079 info string NNUE evaluation using nn-13406b1dcbe0.nnue enabled
> 20.870387 info depth 1 seldepth 1 multipv 1 score cp 174 nodes 63 nps 63000 tbhits 0 time 1 pv f8c5 e4d5
> 20.870691 info depth 2 seldepth 2 multipv 1 score cp 198 nodes 207 nps 207000 tbhits 0 time 1 pv g8e7 e4d5
> 20.871241 info depth 3 seldepth 4 multipv 1 score cp 124 nodes 462 nps 231000 tbhits 0 time 2 pv g8f6 b1c3 f8c5 e4d5
> 20.871299 bestmove g8f6 ponder b1c3
< 22.544435 stop
< 22.544537 quit
< r value false
So from this we can see what is going on exactly.