0

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?

4
  • 5
    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.
    – user21820
    Jun 21 at 18:46
  • 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 Jun 21 at 20:07
  • 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.
    – user21820
    Jun 21 at 20:27
  • For my chess engine, I just use an opening book for around 5-10 moves before turning on the engine. Jun 22 at 12:49
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.