Answers.Body: <p>In alpha/beta pruning, the order that moves are searched in matters a great deal. You always want the best move(s) to be searched first--this creates more beta cutoffs. The basic idea is that before searching each level of the tree, we will sort the moves based on how good they are, then search the moves <em>in that order</em>.</p>
  <p>Of course, this is quasi-paradoxical (&quot;how to find the best move: step 1, find the best move...&quot;) and <em>one of</em> the ways we get around that is using <a href="https://www.chessprogramming.org/Iterative_Deepening" rel="nofollow noreferrer">iterative deepening</a>. Search the position at a smaller depth, then put that move at the very top of the list for the next iteration. This is the point of iterative deepening.</p>
  <hr />
  <p>Because you are just starting out, (and are searching depth 2 in 15 sec), I'd really recommend</p>
  <ol>
  <li>making sure your alpha/beta is bug free (for the love of god, use <a href="https://en.wikipedia.org/wiki/Negamax" rel="nofollow noreferrer">negamax</a>)</li>
  <li>implementing <a href="https://www.chessprogramming.org/Move_Ordering" rel="nofollow noreferrer">other move ordering techniques</a> before iterative deepening.</li>
  <li>implementing <a href="https://www.chessprogramming.org/Null_Move_Pruning" rel="nofollow noreferrer">null move pruning</a></li>
  </ol>
  <p>These last two are (relatively) easy to do, and give essentially free speedups.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-25T09:43:18.740Z
Answers.Text: Thank you for your answer, i understand now. The search to depth2 is  fast, 15 seconds was the entire time i let him search where he gets to depth 5.
Answers.UserDisplayName: philipp
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-24T14:57:29.480Z
Answers.LastActivityDate: 2020-12-24T19:03:06.000Z
Answers.LastEditDate: 2020-12-24T19:03:06.000Z
Answers.UserDisplayName: Noah Caplinger
Body: <p>I implemented a negamax with alpha beta and aspiration windows. Now, it also has iterative deepening. When I let the engine run for 15 seconds in the below position, it finds a move at depth 2 with very good value (135/ d8-d7). But when it goes one depth deeper, the movie is bad because it loses the queen (980). Looking at the best move at the deepest depth, when it fully searches, I get f7-f6 with an evaluation of 200 and it is a way better move.</p>
  <p>Do I just throw away the best move of a previously searched depth, and only look at the deepest fully searched depth? My brain somehow can't find the solution.</p>
  <pre><code>[FEN &quot;rnbqkbnr/5ppp/4p3/2PN2B1/1P2P3/p4N2/P1P1BPPP/1R1QK2R b Kkq - 0 1&quot;]
  </code></pre>
  
Tags: <engines><software>
Title: Iterative deepening: what should I do with previous results?
ThreadText: # Iterative deepening: what should I do with previous results?
  
  (Asked by: username_0 on 2020-12-23)
  
  I implemented a negamax with alpha beta and aspiration windows. Now, it also has iterative deepening. When I let the engine run for 15 seconds in the below position, it finds a move at depth 2 with very good value (135/ d8-d7). But when it goes one depth deeper, the movie is bad because it loses the queen (980). Looking at the best move at the deepest depth, when it fully searches, I get f7-f6 with an evaluation of 200 and it is a way better move.
  Do I just throw away the best move of a previously searched depth, and only look at the deepest fully searched depth? My brain somehow can't find the solution.
  [FEN "rnbqkbnr/5ppp/4p3/2PN2B1/1P2P3/p4N2/P1P1BPPP/1R1QK2R b Kkq - 0 1"]
  
  **Tags:** engines, software
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-12-24. Score: 2 | Accepted answer
  
  In alpha/beta pruning, the order that moves are searched in matters a great deal. You always want the best move(s) to be searched first--this creates more beta cutoffs. The basic idea is that before searching each level of the tree, we will sort the moves based on how good they are, then search the moves *in that order*.
  
  Of course, this is quasi-paradoxical ("how to find the best move: step 1, find the best move...") and *one of* the ways we get around that is using [iterative deepening](https://www.chessprogramming.org/Iterative_Deepening). Search the position at a smaller depth, then put that move at the very top of the list for the next iteration. This is the point of iterative deepening.
  
  ---
  
  Because you are just starting out, (and are searching depth 2 in 15 sec), I'd really recommend
  
  1. making sure your alpha/beta is bug free (for the love of god, use [negamax](https://en.wikipedia.org/wiki/Negamax))
  2. implementing [other move ordering techniques](https://www.chessprogramming.org/Move_Ordering) before iterative deepening.
  3. implementing [null move pruning](https://www.chessprogramming.org/Null_Move_Pruning)
  
  These last two are (relatively) easy to do, and give essentially free speedups.
  
  > **Comments:**
  > **username_0**: Thank you for your answer, i understand now. The search to depth2 is  fast, 15 seconds was the entire time i let him search where he gets to depth 5.  
  
  ---
  
  