Answers.Body: <p>The first three lines:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Are not actually complete searches. The <code>lowerbound</code> and <code>upperbound</code> following <code>score cp ...</code> 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 <a href="https://www.chessprogramming.org/Aspiration_Windows" rel="nofollow noreferrer">aspiration window</a>.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-06T17:30:02.803Z
Answers.LastActivityDate: 2019-08-06T17:30:02.803Z
Answers.UserDisplayName: konsolas
Body: <p>I'm trying to understand how a chess engine like Stockfish works. I use Stockfish 10 directly, without an UI.</p>
  
  <p>For example, for this position <strong>(white to move)</strong>...</p>
  
  <pre><code>r3n1k1/1bpp2pp/pp2p3/2P1P3/R2P4/3B1rPq/7P/1Q3RK1 w - - - 0 26
  </code></pre>
  
  <p>...Stockfish (depth limited to 31) returns the following informations; I only kept the last lines, eliminating those where the depth was less than 31:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I don't understand what criteria allow Stockfish to say that <code>d4d5</code> is the best move.
  The line corresponding to d4d5...</p>
  
  <pre><code>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
  </code></pre>
  
  <p>... proposes a score ("cp score") equal to -788 which is smaller e.g. than -771 (see the following line) by example:</p>
  
  <pre><code>info depth 31 seldepth 47 multipv 1 score cp -771 lowerbound nodes 86977322 nps 1898570 hashfull 990 tbhits 0 time 45812 pv f1f3
  </code></pre>
  
  <p><strong>If it is not the <code>cp score</code> that is decisive, what is the criterion used?</strong></p>
  
  <p>Any help would be appreciated !</p>
  
Tags: <engines><analysis><stockfish>
Title: Leaving the score aside, what are the criteria allowing Stockfish to choose its "best move"?
ThreadText: # Leaving the score aside, what are the criteria allowing Stockfish to choose its "best move"?
  
  (Asked by: username_0 on 2019-08-06)
  
  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 !
  
  **Tags:** engines, analysis, stockfish
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-08-06. Score: 4 | Accepted answer
  
  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.
  
  
  ---
  
  