user26846: 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?

user15223: 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.


26846: <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>
 15223: <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>
