4

I'm trying to understand how a chess engine like Stockfish works. I use Stockfish 10 directly, without an UI.

For example, for this position (white to move)...

r3n1k1/1bpp2pp/pp2p3/2P1P3/R2P4/3B1rPq/7P/1Q3RK1 w - - - 0 26

...Stockfish (depth limited to 31) returns the following informations; I only kept the last lines, eliminating those where the depth was less than 31:

info depth 31 seldepth 47 multipv 1 score cp -771 lowerbound nodes 86977322 nps 1898570 hashfull 990 tbhits 0 time 45812 pv f1f3
info depth 31 seldepth 47 multipv 1 score cp -761 lowerbound nodes 87198087 nps 1898499 hashfull 990 tbhits 0 time 45930 pv f1f3
info depth 31 seldepth 47 multipv 1 score cp -790 upperbound nodes 99439222 nps 1905696 hashfull 992 tbhits 0 time 52180 pv f1f3 b7f3
info depth 31 seldepth 51 multipv 1 score cp -788 nodes 134293602 nps 1906577 hashfull 995 tbhits 0 time 70437 pv d4d5 f3f1 d3f1 h3h5 c5c6 d7c6 a4h4 h5e5 b1h7 g8f8 h4f4 e8f6 h7h8 f8f7 d5e6 e5e6 h8h5 f7e7 h5f3 a8e8 f4c4 b6b5 c4c2 e7d8 f3d3 d8c8 c2e2 f6e4 d3e3 c6c5 f1g2 c5c4 g2e4 b7e4 e3d4 b5b4
bestmove d4d5 weight f3f1

I don't understand what criteria allow Stockfish to say that d4d5 is the best move. The line corresponding to d4d5...

info depth 31 seldepth 51 multipv 1 score cp -788 nodes 134293602 nps 1906577 hashfull 995 tbhits 0 time 70437 pv d4d5 f3f1 d3f1 h3h5 c5c6 d7c6 a4h4 h5e5 b1h7 g8f8 h4f4 e8f6 h7h8 f8f7 d5e6 e5e6 h8h5 f7e7 h5f3 a8e8 f4c4 b6b5 c4c2 e7d8 f3d3 d8c8 c2e2 f6e4 d3e3 c6c5 f1g2 c5c4 g2e4 b7e4 e3d4 b5b4

... proposes a score ("cp score") equal to -788 which is smaller e.g. than -771 (see the following line) by example:

info depth 31 seldepth 47 multipv 1 score cp -771 lowerbound nodes 86977322 nps 1898570 hashfull 990 tbhits 0 time 45812 pv f1f3

If it is not the cp score that is decisive, what is the criterion used?

Any help would be appreciated !

4

The first three lines:

info depth 31 seldepth 47 multipv 1 score cp -771 lowerbound nodes 86977322 nps 1898570 hashfull 990 tbhits 0 time 45812 pv f1f3
info depth 31 seldepth 47 multipv 1 score cp -761 lowerbound nodes 87198087 nps 1898499 hashfull 990 tbhits 0 time 45930 pv f1f3
info depth 31 seldepth 47 multipv 1 score cp -790 upperbound nodes 99439222 nps 1905696 hashfull 992 tbhits 0 time 52180 pv f1f3 b7f3

Are not actually complete searches. The lowerbound and upperbound following score cp ... indicates that the value is not the actual value of the move. Instead, the value is a bound that was obtained when stockfish failed outside of its aspiration window.

When this happens, Stockfish needs to perform a search at the same depth again, with a wider aspiration window. This is why you have 4 lines at depth 31: stockfish searched the position a total of 4 times at depth 31 because it failed outside of its aspiration window 3 times in a row. The first three scores are not exact, and hence only the score from the 4th search (which is exact) is used to determine the best move.

So the criterion used to determine the best move is the internal score of the deepest search which did not fail outside of its aspiration window.

The internal score differs from the cp score in that stockfish evaluates positions with a granularity of 1/256 of a pawn, rather than 1/100 of a pawn. So two positions may have the same cp score, but stockfish may still be able to rank them internally.

The answer changes again when stockfish uses multiple threads. In this case, a voting system is used, where each thread has a different voting weight based on its score and max depth reached.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.