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?
1 Answer
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.
-
right thanks man, tried both of the above things, first one seems to be working fine for now! Commented Jun 23, 2021 at 10:30
d4
ande4
. 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.