Given a position, is there a way we can classify a it, such as if whether there is a pin, fork, or trap, or a mate a mate in 2 or 3? If it is possible, what would be a better approach, an algorithmic way or a machine learning/reinforcement learning? Or are there any other alternatives ways?

  • 2
    Yes, you can algorithmically determine whether there is a mate in 2 or 3, a pin or a fork (I'm not sure why you think machine learning would be helpful here). Whether it can determine if there's a "trap" depends on how you define this term, but if you mean a short tactical sequence that loses material or allows checkmate, then also yes. Aug 2, 2021 at 16:36
  • 3
    The epic success of ML (i.e. Alpha Zero) should not distract from the fact that ML is horribly ineffective compared with an algorithm... if an algorithm exists. The problem is that "simple" algorithm (e.g. find a #2) will not be of much use to play good chess. This notwithstanding, it would be an interesting experiment whether e.g. Alpha Zero can classify tactics. Aug 2, 2021 at 19:30

1 Answer 1


Yes. Let's break it down.

Pin, fork

This is easily done by bitboard operations. I'm not aware of an independent package that can do that, but it's not hard to do it yourself. You just need to work out all the attackers (White and Black), where your pieces are, do some bitwise AND XOR operations. Please take a look at Stockfish's evaluate.cpp.

mate a mate in 2 or 3

Easy! Just run Stockfish or even better a mate tactics solver such as Crystal!


This is going to be very challenging if possible with our current technology. Chess engine doesn't really understand the moves, they assume best play. Computers doesn't understand human-imperfect-level dirty plays. You can work out some simple traps by passing the move to the other colour (e.g. lichess, chess.com etc), but you're not going to get perfect results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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