summaryrefslogtreecommitdiff
path: root/chess-pos.el
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-01-25 04:36:03 +0000
committerJohn Wiegley <johnw@newartisans.com>2004-01-25 04:36:03 +0000
commit01d81baed9ef3bcf544f456668c985c29d7f91c5 (patch)
treee77ebb9299917627c51d0e4917ac63b74871575e /chess-pos.el
parent1b870e3ce5d600149276535949483f6213ab8625 (diff)
Added an argument to chess-search-position, so that if we are
searching for the source of an algebraic move, and it is not a castle, then do not check castle moves.
Diffstat (limited to 'chess-pos.el')
-rw-r--r--chess-pos.el18
1 files changed, 10 insertions, 8 deletions
diff --git a/chess-pos.el b/chess-pos.el
index 403b8ee..5cc463f 100644
--- a/chess-pos.el
+++ b/chess-pos.el
@@ -649,7 +649,8 @@ trying to move a blank square."
(throw 'in-check t)
(push candidate candidates)))
-(defun chess-search-position (position target piece &optional check-only)
+(defun chess-search-position (position target piece &optional
+ check-only no-castling)
"Look on POSITION from TARGET for a PIECE that can move there.
This routine looks along legal paths of movement for PIECE. It
differs from `chess-pos-search', which is a more basic function that
@@ -749,7 +750,7 @@ indices which indicate where a piece may have moved from."
(apply 'chess-incr-index pos dir)))))
;; test whether the rook can move to the target by castling
- (if (= test-piece ?R)
+ (if (and (= test-piece ?R) (not no-castling))
(let (rook)
(if (and (equal target (chess-rf-to-index (if color 7 0) 5))
(setq rook (chess-pos-can-castle position
@@ -777,12 +778,13 @@ indices which indicate where a piece may have moved from."
(setq dirs (cdr dirs))))
;; test whether the king can move to the target by castling
- (if (or (and (equal target (chess-rf-to-index (if color 7 0) 6))
- (chess-pos-can-castle position (if color ?K ?k))
- (chess-ply-castling-changes position))
- (and (equal target (chess-rf-to-index (if color 7 0) 2))
- (chess-pos-can-castle position (if color ?Q ?q))
- (chess-ply-castling-changes position t)))
+ (if (and (not no-castling)
+ (or (and (equal target (chess-rf-to-index (if color 7 0) 6))
+ (chess-pos-can-castle position (if color ?K ?k))
+ (chess-ply-castling-changes position))
+ (and (equal target (chess-rf-to-index (if color 7 0) 2))
+ (chess-pos-can-castle position (if color ?Q ?q))
+ (chess-ply-castling-changes position t))))
(chess--add-candidate (chess-pos-king-index position color)))))
;; the knight is a zesty little piece; there may be more than