summaryrefslogtreecommitdiff
path: root/chess-pos.el
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2002-04-26 19:23:01 +0000
committerJohn Wiegley <johnw@newartisans.com>2002-04-26 19:23:01 +0000
commit7248e5c89f6d53d3f2a4ecf511167af929241f76 (patch)
tree8d1f7c8dd8be449e9445268fb9e16e22a672e597 /chess-pos.el
parent0690915d43e400c7713cafdadf205d233122ac20 (diff)
*** no comment ***
Diffstat (limited to 'chess-pos.el')
-rw-r--r--chess-pos.el40
1 files changed, 21 insertions, 19 deletions
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))