From f4fab47ee91e371dfdfce9ebf4c6bcd3a8497564 Mon Sep 17 00:00:00 2001 From: Mario Lang Date: Fri, 18 Apr 2014 01:14:16 +0200 Subject: chess-legal-plies: It is illegal to castle if the king is in check right now. --- chess-ply.el | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/chess-ply.el b/chess-ply.el index fef4bc3..7c4d741 100644 --- a/chess-ply.el +++ b/chess-ply.el @@ -440,21 +440,22 @@ position object passed in." (chess-pos-piece-p position pos (not color)))) (chess-ply--add nil nil pos))) - (if (chess-pos-can-castle position (if color ?K ?k)) - (let ((changes (chess-ply-castling-changes position nil - candidate))) - (if changes - (if chess-ply-throw-if-any - (throw 'any-found t) - (push (cons position changes) plies))))) - - (if (chess-pos-can-castle position (if color ?Q ?q)) - (let ((changes (chess-ply-castling-changes position t - candidate))) - (if changes - (if chess-ply-throw-if-any - (throw 'any-found t) - (push (cons position changes) plies)))))) + (unless (chess-search-position position candidate (not color) nil t) + (if (chess-pos-can-castle position (if color ?K ?k)) + (let ((changes (chess-ply-castling-changes position nil + candidate))) + (if changes + (if chess-ply-throw-if-any + (throw 'any-found t) + (push (cons position changes) plies))))) + + (if (chess-pos-can-castle position (if color ?Q ?q)) + (let ((changes (chess-ply-castling-changes position t + candidate))) + (if changes + (if chess-ply-throw-if-any + (throw 'any-found t) + (push (cons position changes) plies))))))) ;; the knight is a zesty little piece; there may be more than ;; one, but at only one possible square in each direction -- cgit v1.2.3