Prevent gating on castling target squares
authorFabian Fichter <ianfab@users.noreply.github.com>
Wed, 18 Nov 2020 19:20:52 +0000 (20:20 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Wed, 18 Nov 2020 19:20:52 +0000 (20:20 +0100)
Validate whether the gating square will be blocked
by king or rook after castling.

Closes #207.

src/position.cpp

index 017382a..c5bd02d 100644 (file)
@@ -938,6 +938,11 @@ bool Position::legal(Move m) const {
           if (attackers_to(s, ~us))
               return false;
 
+      // Will the gate be blocked by king or rook?
+      Square rto = to + (to_sq(m) > from_sq(m) ? WEST : EAST);
+      if (is_gating(m) && (gating_square(m) == to || gating_square(m) == rto))
+          return false;
+
       // In case of Chess960, verify that when moving the castling rook we do
       // not discover some hidden checker.
       // For instance an enemy queen in SQ_A1 when castling rook is in SQ_B1.