summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMario Lang <mlang@delysid.org>2014-04-18 01:14:16 +0200
committerMario Lang <mlang@delysid.org>2014-04-18 01:14:16 +0200
commitf4fab47ee91e371dfdfce9ebf4c6bcd3a8497564 (patch)
treeebe31be309c328fccf2801dc98ad4dc55c7e1f3a
parent530b3c3cf0727d311582f6b983b966f3598ea8ba (diff)
chess-legal-plies: It is illegal to castle if the king is in check right now.
-rw-r--r--chess-ply.el31
1 files 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