Answers.Body: <p>In that second example, the &quot;lowerbound&quot; 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.</p>
  <p>This happened because Stockfish uses an <a href="https://www.chessprogramming.org/Aspiration_Windows" rel="nofollow noreferrer">Aspiration Search</a> 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.</p>
  <p>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.</p>
  <p>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.</p>
  <hr />
  <p>See Also:</p>
  <ul>
  <li><a href="https://chess.stackexchange.com/a/35590/30255">Example of &quot;lowerbound&quot; and &quot;upperbound&quot; in the UCI protocol</a></li>
  <li><a href="https://chess.stackexchange.com/a/7692/30255">Stop SF MultiPV from returning an upperbound</a></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-29T16:50:17.187Z
Answers.Text: 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.
Answers.UserDisplayName: Mercutio1243
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-28T22:30:05.237Z
Answers.LastActivityDate: 2023-11-28T22:30:05.237Z
Answers.UserDisplayName: Nelson O
Body: <p>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</p>
  <ol>
  <li>position fen &lt;FEN&gt;</li>
  <li>go movetime 100</li>
  </ol>
  <p>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.</p>
  <blockquote>
  <p>info depth 1 seldepth 1 multipv 1 score cp -53 nodes 34 nps 34000 hashfull 0 tbhits 0 time 1 pv d7d6</p>
  </blockquote>
  <blockquote>
  <p>info depth 2 seldepth 2 multipv 1 score cp -53 nodes 68 nps 68000 hashfull 0 tbhits 0 time 1 pv d7d6 f1c4</p>
  </blockquote>
  <blockquote>
  <p>[...]</p>
  </blockquote>
  <blockquote>
  <p>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</p>
  </blockquote>
  <blockquote>
  <p>info depth 14 seldepth 17 multipv 1 <strong>score cp -41</strong> nodes 62297 nps 604825 hashfull 28 tbhits 0 time 103 <strong>pv d7d6 d2d4 e5d4 f1c4 f8e7 f3d4 g8f6 b1c3 e8g8 e1g1 g8h8 f1e1 b8c6</strong></p>
  </blockquote>
  <blockquote>
  <p><strong>bestmove d7d6 ponder d2d4</strong></p>
  </blockquote>
  <p>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 &quot;c7c6&quot;. 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?</p>
  <blockquote>
  <p>info depth 1 seldepth 1 multipv 1 score cp -134 nodes 32 nps 32000 hashfull 0 tbhits 0 time 1 pv b8c6</p>
  </blockquote>
  <blockquote>
  <p>info depth 2 seldepth 2 multipv 1 score cp -122 nodes 73 nps 73000 hashfull 0 tbhits 0 time 1 pv c7c6</p>
  </blockquote>
  <blockquote>
  <p>[...]</p>
  </blockquote>
  <blockquote>
  <p>info depth 13 seldepth 16 multipv 1 score cp -141 nodes 36495 nps 598278 hashfull 12 tbhits 0 time 61 pv <strong>b8c6</strong> e1g1 d7d6 d2d4 g8e7 c1e3 e7g6 d4e5 d6e5</p>
  </blockquote>
  <blockquote>
  <p>info depth 14 seldepth 20 multipv 1 score cp -124 <strong>lowerbound</strong> nodes 61850 nps 612376 hashfull 26 tbhits 0 time 101 <strong>pv c7c6</strong></p>
  </blockquote>
  <blockquote>
  <p><strong>bestmove c7c6 ponder b1c3</strong></p>
  </blockquote>
  <p>Why does the engine give the output sometimes like this? It seems to mention &quot;lowerbound&quot; or &quot;upperbound&quot; in these cases? How do I get the best continuation pv from the engine in this case?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-12-07T14:46:08.337Z
Comments.Text: 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.
Comments.UserDisplayName: ferdy
Tags: <engines><uci>
Title: Understanding UCI Output of Chess Engine - how to get best continuation
ThreadText: # Understanding UCI Output of Chess Engine - how to get best continuation
  
  (Asked by: username_0 on 2023-11-28)
  
  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?
  
  **Tags:** engines, uci
  
  > **Comments:**
  > **username_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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2023-11-28. Score: 1 | Accepted answer
  
  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](https://www.chessprogramming.org/Aspiration_Windows) 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:
  
  * [Example of "lowerbound" and "upperbound" in the UCI protocol](https://chess.stackexchange.com/a/35590/30255)
  * [Stop SF MultiPV from returning an upperbound](https://chess.stackexchange.com/a/7692/30255)
  
  > **Comments:**
  > **username_0**: 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.  
  
  ---
  
  