From 186eeb0a56c942da54f77d53a7eb1e2ce067e13b Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Wed, 18 Nov 2020 20:20:52 +0100 Subject: [PATCH] Prevent gating on castling target squares Validate whether the gating square will be blocked by king or rook after castling. Closes #207. --- src/position.cpp | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) 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. -- 1.7.0.4