From: Fabian Fichter Date: Wed, 18 Nov 2020 19:20:52 +0000 (+0100) Subject: Prevent gating on castling target squares X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=186eeb0a56c942da54f77d53a7eb1e2ce067e13b;p=fairystockfish.git Prevent gating on castling target squares Validate whether the gating square will be blocked by king or rook after castling. Closes #207. --- diff --git a/src/position.cpp b/src/position.cpp index 017382a..c5bd02d 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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.