I am currently attempting to make a basic chess engine in Python (Learning some basic concepts), but for some reason the engine is suicidal and does not detect the scholars mate. I am using python-chess for the board because I am lazy, but I think the issue is my implementation of negamax? I've read on chessprogramming wiki but still can't figure out the issue.

Here is the code on GitHub: https://github.com/AggressiveBee15/LousyEngine

  • Why do I need to add a negative sign? Sorry I don't really understand negamax yet (I was doing separate subroutines before I switched) Aug 4, 2017 at 5:08
  • 1
    If score >= beta, you should return the score, not beta.
    – SmallChess
    Aug 4, 2017 at 5:11
  • Also, your code doesn't detect checkmate.
    – SmallChess
    Aug 4, 2017 at 5:12
  • For the negative sign before the initial call, wikipedia seems to say that a negative sign isn't required before the root negamax call. Aug 4, 2017 at 5:40
  • 2
    The community has decided that questions about chess programming are on-topic. This is also stated in the help center: Chess-specific questions about programming a chess engine or other chess software are welcome.
    – Glorfindel
    Aug 5, 2017 at 8:21

1 Answer 1


I didn't run your code, but by just looking:

  • You should return the score when score >= beta. This is consistent to Wikipedia:

enter image description here

Note when alpha >= beta, Wikipedia returns the score, not beta.

  • Your code doesn't detect checkmate? I don't see how your engine can report Scholar mate without detecting checkmate.
  • Minor issue. The condition should be >= not >, but that shouldn't change anything.
  • What outputs did you get from: print('New good move ...?
  • Previously, when I used my minimal implementation, the engine could prevent simple checkmates. Coincidence??? Aug 4, 2017 at 5:21
  • @AggresiveBee15 I don't know about your previous implementation, but I don't see how your engine would work if you don't check for end of game by checkmate.
    – SmallChess
    Aug 4, 2017 at 5:21
  • Where would I add the checkmate check? Should I add the check right after the move is pushed? Aug 4, 2017 at 5:22
  • In evaluation, if the position is checkmate your evaluator must return infinity.
    – SmallChess
    Aug 4, 2017 at 5:23
  • Also, currently I run the engine with the depth of 3. The game went: 1. e4 a5 2. d4 b5 3. Bxb5 Why did it blunder a pawn? The evaluation function is really basic, but should be able to calculate the material loss. Aug 4, 2017 at 13:16

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.