From 7248e5c89f6d53d3f2a4ecf511167af929241f76 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 26 Apr 2002 19:23:01 +0000 Subject: *** no comment *** --- chess-pos.el | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'chess-pos.el') diff --git a/chess-pos.el b/chess-pos.el index d0b6dd5..46a4c1b 100644 --- a/chess-pos.el +++ b/chess-pos.el @@ -683,25 +683,27 @@ assures that the resulting position is valid." (piece (chess-pos-piece position (car candidates))) other-piece last-cand king-pos) (while cand - ;; determine the resulting position - (chess-pos-set-piece position (car cand) ? ) - (setq other-piece (chess-pos-piece position target)) - (chess-pos-set-piece position target piece) - ;; find the king (only once if the king isn't moving) - (if (or (null king-pos) - (memq piece '(?K ?k))) - (setq king-pos (chess-pos-king-index position color))) - ;; can anybody from the opposite side reach him? if so, drop - ;; the candidate - (if (catch 'in-check - (chess-search-position position king-pos (not color) t)) - (if last-cand - (setcdr last-cand (cdr cand)) - (setq candidates (cdr candidates))) - (setq last-cand cand)) - ;; return the position to its original state - (chess-pos-set-piece position target other-piece) - (chess-pos-set-piece position (car cand) piece) + (unwind-protect + (progn + ;; determine the resulting position + (chess-pos-set-piece position (car cand) ? ) + (setq other-piece (chess-pos-piece position target)) + (chess-pos-set-piece position target piece) + ;; find the king (only once if the king isn't moving) + (if (or (null king-pos) + (memq piece '(?K ?k))) + (setq king-pos (chess-pos-king-index position color))) + ;; can anybody from the opposite side reach him? if so, + ;; drop the candidate + (if (catch 'in-check + (chess-search-position position king-pos (not color) t)) + (if last-cand + (setcdr last-cand (cdr cand)) + (setq candidates (cdr candidates))) + (setq last-cand cand))) + ;; return the position to its original state + (chess-pos-set-piece position target other-piece) + (chess-pos-set-piece position (car cand) piece)) ;; try the next candidate (setq cand (cdr cand))) candidates)) -- cgit v1.2.3