I'm currently writing my own chess game with my own AI and have a Question about a move: enter image description here

Here, Purple moved his Pawn from F2 -> F3, which allowes the Green Queen on H4 to capture the King, and I wondered if the F2 -> F3 move is illegal or if it's just an oversight of the player which lost him the game.

New contributor
Kerialstraz is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 2
    the term for this situation is that the pawn in f2 is pinned by the queen, which is to say that it is not allowed to move because it would put the king in check.
    – njzk2

The rules governing chess are the FIDE Laws of Chess. This point is explicitly covered in Article 3: The moves of the pieces

3.9.2 No piece can be moved that will either expose the king of the same colour to check or leave that king in check.

The move f3 violates this rule because it exposes the king to check. As such it is an illegal move. Your program should not allow illegal moves so should not allow this move in just the same way that you do not allow the pawn to move from f2 to f5 in one move.

In a real game when an illegal move is made the move must be taken back and a legal move made in its place. In competition chess there are also penalties for making illegal moves.

  • Twist: If nobody realises that an illegal move has been made, nothing happens. yesterday

Your Answer

Kerialstraz is a new contributor. Be nice, and check out our Code of Conduct.

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.