1

I am trying to understand and parse the UCI (Universal Chess Interface) output of a chess engine (here Stockfish 15.1). Specifically, I calling Stockfish with the following command and want to get the best move, the best move continuation and stockfish's evaluation of the position (the score). For this, I call the engine with

  1. position fen <FEN>
  2. go movetime 100

In the following two examples of the output that I am getting from the engine. In the first example everything seems good. The last line gives me the best move and from the line before, I can take the score and the best continuation.

info depth 1 seldepth 1 multipv 1 score cp -53 nodes 34 nps 34000 hashfull 0 tbhits 0 time 1 pv d7d6

info depth 2 seldepth 2 multipv 1 score cp -53 nodes 68 nps 68000 hashfull 0 tbhits 0 time 1 pv d7d6 f1c4

[...]

info depth 13 seldepth 17 multipv 1 score cp -41 nodes 55000 nps 611111 hashfull 25 tbhits 0 time 90 pv d7d6 d2d4 e5d4 f1c4 f8e7 f3d4 g8f6 b1c3 e8g8 e1g1 g8h8 f1e1 b8c6

info depth 14 seldepth 17 multipv 1 score cp -41 nodes 62297 nps 604825 hashfull 28 tbhits 0 time 103 pv d7d6 d2d4 e5d4 f1c4 f8e7 f3d4 g8f6 b1c3 e8g8 e1g1 g8h8 f1e1 b8c6

bestmove d7d6 ponder d2d4

However, in this second example, while the last line gives me the best move, the line beforehand does not give a full continuation as pv, but only the move "c7c6". This is not even the same move that is considered in the second to last line, so it seems that I cannot fall back to that line for the best continuation?

info depth 1 seldepth 1 multipv 1 score cp -134 nodes 32 nps 32000 hashfull 0 tbhits 0 time 1 pv b8c6

info depth 2 seldepth 2 multipv 1 score cp -122 nodes 73 nps 73000 hashfull 0 tbhits 0 time 1 pv c7c6

[...]

info depth 13 seldepth 16 multipv 1 score cp -141 nodes 36495 nps 598278 hashfull 12 tbhits 0 time 61 pv b8c6 e1g1 d7d6 d2d4 g8e7 c1e3 e7g6 d4e5 d6e5

info depth 14 seldepth 20 multipv 1 score cp -124 lowerbound nodes 61850 nps 612376 hashfull 26 tbhits 0 time 101 pv c7c6

bestmove c7c6 ponder b1c3

Why does the engine give the output sometimes like this? It seems to mention "lowerbound" or "upperbound" in these cases? How do I get the best continuation pv from the engine in this case?

1
  • One approach is to extend the search time. Once the pv has more than one move, you can stop it and get the info you need.
    – ferdy
    Commented Dec 7, 2023 at 14:46

1 Answer 1

1

In that second example, the "lowerbound" indicates that Stockfish established that the position is at least a score of -124 centipawns, but it may actually be better. At depth 13, Stockfish determined b8c6 to be the best move. However, at depth 14, it found that c7c6 is better, but it was not able to complete the full search at this ply. There may be a different better move at this depth, but it was at least able to determine that c7c6 is at least better than b8c6.

This happened because Stockfish uses an Aspiration Search where it will assume that the correct evaluation for a move is within some pre-determined window (in this case, it would be some range around the evaluation from depth 13). This normally allows it to cut off a lot of moves early that fall outside of this narrow window. However, sometimes, it might find that there is a better move that lies outside of this window, so it needs to restart the search around some other window. In this case, Stockfish found that c7c6 was a better move that was outside of the upper bound of the window, meaning that it was able to establish the lowerbound for the score for this move. It reported that evaluation with the lowerbound score, but it wasn't able to finish the re-search in time to get the actual score, nor was it able to report the remaining moves in the principal variation.

Ultimately, the issue was that you are asking it to spend 100ms to perform the search, and that time elapsed after an inconvenient output. To get a better PV, you can try re-running the search for this position with more time, or you can run the search after making the recommended best move.

The big thing to remember is that Stockfish (and the UCI protocol in general) is ultimately built to play chess, so all that it really guarantees is that it will yield the best move after performing the search. Access to the full PV is just a bonus that is usually, though not always, available.


See Also:

1
  • Perfect, thank you very much for the detailed explanation. I will then revert for my purposes to use the last fully finished output, ignoring any lowerbound/upperbound result that might arise on a higher depth. Commented Nov 29, 2023 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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