Answers.Body: <p>Stockfish (at a search depth of 99 moves) evaluates the initial position as actually a mate-in-19.</p>
  
  <pre><code>[FEN "2n5/1p6/1P3k2/R1K1p1p1/2p1PpPp/5P1P/8/8 w - - 4 1"]
  
  1.Ra8 Ne7 Kxc4 Nc6 Kc5 Ke7 Rc8 Nd8 Kd5 Ne6 Kxe5 Kd7 Kd5 Ke7 Re8+ Kxe8 Kxe6 Kf8 e5 Kg7 Kd6 Kg8 e6 Kf8 Kd7 Kg8 e7 Kf7 e8=Q+ Kf6 Kd6 Kg7 Ke7 Kh6 Kf8 Kh7 Qh5#
  </code></pre>
  
  <p>The next position is a mate in 18 moves.</p>
  
  <pre><code>[FEN "R7/1p2n3/1P3k2/2K1p1p1/2p1PpPp/5P1P/8/8 w - - 6 2"]
  
  1.Kxc4 Nc6 Kc5 Ke7 Rc8 Nd8 Kd5 Ne6 Kxe5 Kd7 Kd5 Ke7 Re8+ Kxe8 Kxe6 Kf8 e5 Kg7 Kd6 Kg8 e6 Kf8 Kd7 Kg8 e7 Kf7 e8=Q+ Kf6 Kd6 Kg7 Ke7 Kh6 Kf8 Kh7 Qh5#
  </code></pre>
  
  <p>The final position is mate in 17 moves.</p>
  
  <pre><code>[FEN "R7/1p6/1Pn2k2/4p1p1/2K1PpPp/5P1P/8/8 w - - 1 3"]
  
  1.Kc5 Ke7 Rc8 Nd8 Kd5 Ne6 Kxe5 Kd7 Kd5 Ke7 Re8+ Kxe8 Kxe6 Kf8 e5 Kg7 Kd6 Kg8 e6 Kf8 Kd7 Kg8 e7 Kf7 e8=Q+ Kf6 Kd6 Kg7 Ke7 Kh6 Kf8 Kh7 Qh5#
  </code></pre>
  
  <p>You probably didn't give the engine sufficient time to find the mate.</p>
  
  <p>Another important fact to note is that the Lichess app uses the javascript version of Stockfish. The problem with this version is that it cannot make use of hash tables. So when the engine evaluates a position and then left to evaluate another position resulting from a move in the initial position, it evaluates the position as if it was restarted before evaluation. I am pretty sure if you give the engine some time to evaluate the second and last positions it will come up with the mate.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-10T13:19:37.177Z
Answers.LastActivityDate: 2018-02-10T13:19:37.177Z
Answers.UserDisplayName: Wais Kamal
Answers.Body: <p>Engines do not calculate <em>every single variation</em> up until their depth.  It would take far too long to do this at a depth of, say, 20 moves.  After only the first four moves in chess, there over a billion positions.</p>
  
  <p>Engines choose what variations to calculate based off their evaluation algorithms (how they evaluate positions).  For example, assume it gets to a position in its calculations where the opponent has 5 possible moves.  If it evaluates that 3 of these moves are +10 for the computer, it could entirely skip these variations and only calculate the remaining 2.  This saves large amounts of time and processing power.</p>
  
  <p>Thus, if an engine calls "mate in X", that is really just its best guess.  It's possible the engine incorrectly thought some variation was bad for the opponent, and thus chose not to calculate it.  However, maybe it turns out this variation actually prolonged the game a few more moves.</p>
  
  <p>An engine's evaluation algorithm is based on a number of factors regarding <em>the current position in its calculations</em>.  Black could have had a move that "looked" worse to the engine (based off its evaluation algorithm), causing it not to calculate the resulting variation.  Concretely though, this move could have been <em>objectively</em> the best, as it prolonged mate.</p>
  
  <p>The reason an engine often changes its evaluation from "mate in X" to something like +60 is that, after "going down the rabbit hole" as far as it can, it then checks over and refines its previous calculations.  It wouldn't make sense to refine/perfect its calculations first, as this is like the cherry on the cake.  Analyzing to a high depth is of highest priority - refining its previous calculations is almost always secondary.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-08T10:12:08.907Z
Answers.LastActivityDate: 2018-02-08T10:12:08.907Z
Answers.UserDisplayName: Inertial Ignorance
Answers.Body: <p>Many engines are notoriously bad at "remembering" their own variations from 3 moves ago and try to reinvent the wheel each move, so to say.</p>
  
  <p>For me, the Lichess Stockfish calculates</p>
  
  <ul>
  <li>Mate in 22 for 1. Ra8</li>
  <li>Mate in 21 for 2. Kxc4</li>
  <li>Mate in 14 for 3. Rc8 (Black screwed up in his last move it seems)</li>
  <li>Mate in 18 for 3. Kc5</li>
  <li>Mate in 19 for 3. Rg8</li>
  <li>+64 for 3. Kd5</li>
  </ul>
  
  <p>With search depth of 35 each time. </p>
  
  <p>Looks like your analysis at move 3 did not go deep enough and recommended the "wrong" move Kd5 (which still wins, of course). Note that until a depth of around 30, I only got +50 to +60 evaluations too. My bet is that on your phone Stockfish could not reach the depth where it flips back to showing the mate. After making the move, it started to realize that it lost the track to the mate and began readjusting the evaluation (to +10).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-07T14:16:34.423Z
Answers.Text: Is this ultimately due to *pruning* or to something else?
Answers.UserDisplayName: user1583209
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-07T14:19:51.067Z
Answers.Text: Ok, i can understand why different machines show different results, because of their power. But why a forced mate was lost if I did the "right" moves?
Answers.UserDisplayName: Superluminal
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-07T14:19:52.250Z
Answers.Text: @user1583209 I don't know in detail how Stockfish works. But I think it's very likely that the one on OP's phone did cut off the wrong branch at some point.
Answers.UserDisplayName: Annatar
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-07T14:34:55.003Z
Answers.Text: @S.G. Did the engine really show 3. Kd5 as the main continuation in the evaluation of the first move (you should be able to see that much of the line)? I doubt that. As I said, it "forgot" the move 1 (and 2) analysis when it did the move 3 one.
Answers.UserDisplayName: Annatar
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-07T14:13:25.150Z
Answers.LastActivityDate: 2018-02-07T14:13:25.150Z
Answers.UserDisplayName: Annatar
Body: <p>It is going from #26 through +60 to +9. Thats all engines best moves with deep analysis. Schould it not be a forced checkmate if I will follow the engine evaluation?</p>
  
  <p><img src="https://i.sstatic.net/HJWgk.jpg" alt="enter image description here">
  <a href="https://i.sstatic.net/cjbUk.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cjbUk.jpg" alt="enter image description here"></a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-07T13:56:28.777Z
Comments.Text: Interestingly my stockfish says mate in 23 moves from the first position.
Comments.UserDisplayName: user1583209
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-07T13:57:39.380Z
Comments.Text: @user1583209 Mine says #22. But yeah. That "deep analysis" likely just wasn't deep enough.
Comments.UserDisplayName: Annatar
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-07T13:59:53.877Z
Comments.Text: For practical purposes all these evaluations are equally winning for white. I'd be worried if it switched to an evaluation of 0 or so.
Comments.UserDisplayName: user1583209
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-07T15:17:24.037Z
Comments.Text: maybe the depth between the evaluation is different. Such as it expecting multiple free pieces, but eventually finding a sacrifice the mitigates the damage
Comments.UserDisplayName: TheAutomaton
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-02-08T10:38:28.130Z
Comments.Text: Engines aren't perfect, and one move later they can see deeper. Sometimes they think a move wins but in the end it turns out it doesn't, then you get this.
Comments.UserDisplayName: RemcoGerlich
Tags: <engines>
Title: Why doing the Engine suggested move worsen my position?
ThreadText: # Why doing the Engine suggested move worsen my position?
  
  (Asked by: username_0 on 2018-02-07)
  
  It is going from #26 through +60 to +9. Thats all engines best moves with deep analysis. Schould it not be a forced checkmate if I will follow the engine evaluation?
  
  ![enter image description here](https://i.sstatic.net/HJWgk.jpg)
  [![enter image description here](https://i.sstatic.net/cjbUk.jpg)](https://i.sstatic.net/cjbUk.jpg)
  
  **Tags:** engines
  
  > **Comments:**
  > **username_1**: Interestingly my stockfish says mate in 23 moves from the first position.  
  > **username_2**: @username_1 Mine says #22. But yeah. That "deep analysis" likely just wasn't deep enough.  
  > **username_1**: For practical purposes all these evaluations are equally winning for white. I'd be worried if it switched to an evaluation of 0 or so.  
  > **username_3**: maybe the depth between the evaluation is different. Such as it expecting multiple free pieces, but eventually finding a sacrifice the mitigates the damage  
  > **username_4**: Engines aren't perfect, and one move later they can see deeper. Sometimes they think a move wins but in the end it turns out it doesn't, then you get this.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_5 on 2018-02-10. Score: 2
  
  Stockfish (at a search depth of 99 moves) evaluates the initial position as actually a mate-in-19.
  
  ```
  [FEN "2n5/1p6/1P3k2/R1K1p1p1/2p1PpPp/5P1P/8/8 w - - 4 1"]
  
  1.Ra8 Ne7 Kxc4 Nc6 Kc5 Ke7 Rc8 Nd8 Kd5 Ne6 Kxe5 Kd7 Kd5 Ke7 Re8+ Kxe8 Kxe6 Kf8 e5 Kg7 Kd6 Kg8 e6 Kf8 Kd7 Kg8 e7 Kf7 e8=Q+ Kf6 Kd6 Kg7 Ke7 Kh6 Kf8 Kh7 Qh5#
  
  ```
  
  The next position is a mate in 18 moves.
  
  ```
  [FEN "R7/1p2n3/1P3k2/2K1p1p1/2p1PpPp/5P1P/8/8 w - - 6 2"]
  
  1.Kxc4 Nc6 Kc5 Ke7 Rc8 Nd8 Kd5 Ne6 Kxe5 Kd7 Kd5 Ke7 Re8+ Kxe8 Kxe6 Kf8 e5 Kg7 Kd6 Kg8 e6 Kf8 Kd7 Kg8 e7 Kf7 e8=Q+ Kf6 Kd6 Kg7 Ke7 Kh6 Kf8 Kh7 Qh5#
  
  ```
  
  The final position is mate in 17 moves.
  
  ```
  [FEN "R7/1p6/1Pn2k2/4p1p1/2K1PpPp/5P1P/8/8 w - - 1 3"]
  
  1.Kc5 Ke7 Rc8 Nd8 Kd5 Ne6 Kxe5 Kd7 Kd5 Ke7 Re8+ Kxe8 Kxe6 Kf8 e5 Kg7 Kd6 Kg8 e6 Kf8 Kd7 Kg8 e7 Kf7 e8=Q+ Kf6 Kd6 Kg7 Ke7 Kh6 Kf8 Kh7 Qh5#
  
  ```
  
  You probably didn't give the engine sufficient time to find the mate.
  
  Another important fact to note is that the Lichess app uses the javascript version of Stockfish. The problem with this version is that it cannot make use of hash tables. So when the engine evaluates a position and then left to evaluate another position resulting from a move in the initial position, it evaluates the position as if it was restarted before evaluation. I am pretty sure if you give the engine some time to evaluate the second and last positions it will come up with the mate.
  
  
  ---
  
  ### Answer by username_6 on 2018-02-08. Score: 1
  
  Engines do not calculate *every single variation* up until their depth. It would take far too long to do this at a depth of, say, 20 moves. After only the first four moves in chess, there over a billion positions.
  
  Engines choose what variations to calculate based off their evaluation algorithms (how they evaluate positions). For example, assume it gets to a position in its calculations where the opponent has 5 possible moves. If it evaluates that 3 of these moves are +10 for the computer, it could entirely skip these variations and only calculate the remaining 2. This saves large amounts of time and processing power.
  
  Thus, if an engine calls "mate in X", that is really just its best guess. It's possible the engine incorrectly thought some variation was bad for the opponent, and thus chose not to calculate it. However, maybe it turns out this variation actually prolonged the game a few more moves.
  
  An engine's evaluation algorithm is based on a number of factors regarding *the current position in its calculations*. Black could have had a move that "looked" worse to the engine (based off its evaluation algorithm), causing it not to calculate the resulting variation. Concretely though, this move could have been *objectively* the best, as it prolonged mate.
  
  The reason an engine often changes its evaluation from "mate in X" to something like +60 is that, after "going down the rabbit hole" as far as it can, it then checks over and refines its previous calculations. It wouldn't make sense to refine/perfect its calculations first, as this is like the cherry on the cake. Analyzing to a high depth is of highest priority - refining its previous calculations is almost always secondary.
  
  
  ---
  
  ### Answer by username_2 on 2018-02-07. Score: 0
  
  Many engines are notoriously bad at "remembering" their own variations from 3 moves ago and try to reinvent the wheel each move, so to say.
  
  For me, the Lichess Stockfish calculates
  
  * Mate in 22 for 1. Ra8
  * Mate in 21 for 2. Kxc4
  * Mate in 14 for 3. Rc8 (Black screwed up in his last move it seems)
  * Mate in 18 for 3. Kc5
  * Mate in 19 for 3. Rg8
  * +64 for 3. Kd5
  
  With search depth of 35 each time.
  
  Looks like your analysis at move 3 did not go deep enough and recommended the "wrong" move Kd5 (which still wins, of course). Note that until a depth of around 30, I only got +50 to +60 evaluations too. My bet is that on your phone Stockfish could not reach the depth where it flips back to showing the mate. After making the move, it started to realize that it lost the track to the mate and began readjusting the evaluation (to +10).
  
  > **Comments:**
  > **username_1**: Is this ultimately due to *pruning* or to something else?  
  > **username_0**: Ok, i can understand why different machines show different results, because of their power. But why a forced mate was lost if I did the "right" moves?  
  > **username_2**: @username_1 I don't know in detail how Stockfish works. But I think it's very likely that the one on OP's phone did cut off the wrong branch at some point.  
  > **username_2**: @S.G. Did the engine really show 3. Kd5 as the main continuation in the evaluation of the first move (you should be able to see that much of the line)? I doubt that. As I said, it "forgot" the move 1 (and 2) analysis when it did the move 3 one.  
  
  ---
  
  