Answers.Body: <p>This lack of opening diversity problem affects even the strongest engines, so don't worry about it. Still, there are things you can do:</p>
  <ul>
  <li>Add some small random factor to your eval, such that most positions do not return exactly the same number. Many of the strongest engines already do this, not because they want to play different openings, but because it encourages the engine to search certain branches more.</li>
  <li>Use an <a href="https://en.wikipedia.org/wiki/Chess_opening_book_(computers)" rel="nofollow noreferrer">opening book</a>.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-23T10:30:51.753Z
Answers.Text: right thanks man, tried both of the above things, first one seems to be working fine for now!
Answers.UserDisplayName: David Gladson
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-06-23T00:29:36.150Z
Answers.LastActivityDate: 2021-06-23T00:29:36.150Z
Answers.UserDisplayName: Allure
Body: <p>I created a chess engine using the Python chess library. It has an evaluation function (piece values, piece square values, and capture values) and minimax. Alpha-beta pruning is also implemented. At depth three, it always starts with a knight for both White and Black. Sometimes it only plays with a knight for at least 10 moves. How do I avoid this? Is there a way to add some opening knowledge to the engine?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-06-21T18:46:25.070Z
Comments.Text: Doesn't it just imply that your piece-square values are bad? Pawns in the centre ought to be given higher value, so it doesn't make sense that the best moves just have the knight running around.
Comments.UserDisplayName: user21820
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-06-21T20:07:27.830Z
Comments.Text: exactly, tried the same by playing around with piece-square values, still doesn't solve the problem, Knight moves are coming up as the top ones in move order list
Comments.UserDisplayName: David Gladson
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-06-21T20:27:22.617Z
Comments.Text: Make pawn in the centre squares have extremely large value, forcing the best moves by White to be to push `d4` and `e4`. Also turn off alpha-beta. If that still doesn't work then clearly your code is incorrect. Alpha-beta never changes the result (unless implemented wrongly). By the way, it makes no sense to use minimax instead of negamax.
Comments.UserDisplayName: user21820
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-06-22T12:49:38.970Z
Comments.Text: For my chess engine, I just use an opening book for around 5-10 moves before turning on the engine.
Comments.UserDisplayName: Rushabh Mehta
Tags: <engines><computer-chess><mathematics><python><minimax>
Title: How to avoid the same opening move in an engine built using Python chess
ThreadText: # How to avoid the same opening move in an engine built using Python chess
  
  (Asked by: username_0 on 2021-06-21)
  
  I created a chess engine using the Python chess library. It has an evaluation function (piece values, piece square values, and capture values) and minimax. Alpha-beta pruning is also implemented. At depth three, it always starts with a knight for both White and Black. Sometimes it only plays with a knight for at least 10 moves. How do I avoid this? Is there a way to add some opening knowledge to the engine?
  
  **Tags:** engines, computer-chess, mathematics, python, minimax
  
  > **Comments:**
  > **username_1**: Doesn't it just imply that your piece-square values are bad? Pawns in the centre ought to be given higher value, so it doesn't make sense that the best moves just have the knight running around.  
  > **username_0**: exactly, tried the same by playing around with piece-square values, still doesn't solve the problem, Knight moves are coming up as the top ones in move order list  
  > **username_1**: Make pawn in the centre squares have extremely large value, forcing the best moves by White to be to push `d4` and `e4`. Also turn off alpha-beta. If that still doesn't work then clearly your code is incorrect. Alpha-beta never changes the result (unless implemented wrongly). By the way, it makes no sense to use minimax instead of negamax.  
  > **username_2**: For my chess engine, I just use an opening book for around 5-10 moves before turning on the engine.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2021-06-23. Score: 2
  
  This lack of opening diversity problem affects even the strongest engines, so don't worry about it. Still, there are things you can do:
  
  * Add some small random factor to your eval, such that most positions do not return exactly the same number. Many of the strongest engines already do this, not because they want to play different openings, but because it encourages the engine to search certain branches more.
  * Use an [opening book](https://en.wikipedia.org/wiki/Chess_opening_book_(computers)).
  
  > **Comments:**
  > **username_0**: right thanks man, tried both of the above things, first one seems to be working fine for now!  
  
  ---
  
  