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?
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.