Answers.Body: <p>Following <code>Vintarel</code>'s advice, I reviewed my code and saw there was an error. Indeed, the evaluation function returned different values, depending on the AI or the player. So, for example, it would return -3 for the AI and 3 for the player, resulting in a wrong max/min optimization.</p>
  <p>I modified the evaluation function, so that it returns the same value, independently of the player. After, the score is minimized or maximized, according to the current player (AI or human). In the end, odd/even depth has no impact and the algorithm works as expected!
  Thanks</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-18T12:59:30.537Z
Answers.LastActivityDate: 2022-04-18T12:59:30.537Z
Answers.UserDisplayName: Carmellose
Body: <p>I implemented the <a href="https://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning" rel="nofollow noreferrer">minimax algorithm with alpha-beta pruning</a> to see how it works, with application to the <a href="https://en.wikipedia.org/wiki/Connect_Four" rel="nofollow noreferrer">connect four game</a>.</p>
  <p>My AI works fine, considering the AI is the MAX player (VS human player, which is the MIN), e.g. the Minimax root node of the tree.</p>
  <p>However, since the root node is always the MAX player (AI), does this means that the leaf nodes, where pruning occurs, should be at an odd depth?</p>
  <p>Whenever I use an odd number for depth, my algorithm works fine. But when I use an even number, the bottom node because a min node and AI looses the game.</p>
  <p>Can anyone confirm that when using MAX as the root node, the depth should always be an odd number? AFAIK, it's never said explicitly in the algorithm's description.</p>
  <p>Thanks</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-02-16T19:03:55.887Z
Comments.Text: Do you use a transposition table and iterative deepening ? If yes, results of even depth-searches can trouble results of odd depth-searches, but shouldn't give bad moves as well. If no, there is no reason for an even search-depth to give a bad move (i used to have depths of even number).
Comments.UserDisplayName: Vintarel
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-02-17T21:48:37.667Z
Comments.Text: @Vintarel no I don't use move ordering techniques. But when the depth is even the algorithm ends up computing a score for the min. Is this expected?
Comments.UserDisplayName: Carmellose
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-02-19T17:23:32.963Z
Comments.Text: For even depths, the score should be a little lower (not too much though) than for odd depths, as the tree on leaves is supplied with moves favoring the MIN player. On my chess program, the scores could change of around 0.2 point when switching parity of depths, but a good move (score of 3 or more) still remained a good move. Try to see for shallow searches (depth = 1, 2) or by printing the results at every upper nodes if you can spot what happens.
Comments.UserDisplayName: Vintarel
Tags: <minimax><alpha-beta-pruning>
Title: Should minimax with alpha beta pruning depth be an odd number?
UserDisplayName: Carmellose
ThreadText: # Should minimax with alpha beta pruning depth be an odd number?
  
  (Asked by: username_0 on 2022-02-15)
  
  I implemented the [minimax algorithm with alpha-beta pruning](https://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning) to see how it works, with application to the [connect four game](https://en.wikipedia.org/wiki/Connect_Four).
  
  My AI works fine, considering the AI is the MAX player (VS human player, which is the MIN), e.g. the Minimax root node of the tree.
  
  However, since the root node is always the MAX player (AI), does this means that the leaf nodes, where pruning occurs, should be at an odd depth?
  
  Whenever I use an odd number for depth, my algorithm works fine. But when I use an even number, the bottom node because a min node and AI looses the game.
  
  Can anyone confirm that when using MAX as the root node, the depth should always be an odd number? AFAIK, it's never said explicitly in the algorithm's description.
  
  Thanks
  
  **Tags:** minimax, alpha-beta-pruning
  
  > **Comments:**
  > **username_1**: Do you use a transposition table and iterative deepening ? If yes, results of even depth-searches can trouble results of odd depth-searches, but shouldn't give bad moves as well. If no, there is no reason for an even search-depth to give a bad move (i used to have depths of even number).  
  > **username_0**: @username_1 no I don't use move ordering techniques. But when the depth is even the algorithm ends up computing a score for the min. Is this expected?  
  > **username_1**: For even depths, the score should be a little lower (not too much though) than for odd depths, as the tree on leaves is supplied with moves favoring the MIN player. On my chess program, the scores could change of around 0.2 point when switching parity of depths, but a good move (score of 3 or more) still remained a good move. Try to see for shallow searches (depth = 1, 2) or by printing the results at every upper nodes if you can spot what happens.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-04-18. Score: 3 | Accepted answer
  
  Following `username_1`'s advice, I reviewed my code and saw there was an error. Indeed, the evaluation function returned different values, depending on the AI or the player. So, for example, it would return -3 for the AI and 3 for the player, resulting in a wrong max/min optimization.
  
  I modified the evaluation function, so that it returns the same value, independently of the player. After, the score is minimized or maximized, according to the current player (AI or human). In the end, odd/even depth has no impact and the algorithm works as expected!
  Thanks
  
  
  ---
  
  