From c4dfc98b7cb5f9cfee689a852549022b80345033 Mon Sep 17 00:00:00 2001 From: Mario Lang Date: Mon, 26 Jan 2004 12:35:51 +0000 Subject: (chess-pos-move): There was a bug in castling removal when a Rook moved, now compare chess-pos-can-castle and the source square of the moving piece to figure out if we need to remove castling priveledges --- chess-pos.el | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/chess-pos.el b/chess-pos.el index bd6d400..ccfb0fb 100644 --- a/chess-pos.el +++ b/chess-pos.el @@ -556,7 +556,7 @@ This string should have been created by `chess-pos-to-string'." '((move-from-blank . "Attempted piece move from blank square %s"))) (defun chess-pos-move (position &rest changes) - "Move a piece on the POSITION directly, using the indices FROM and TO. + "Move a piece on the POSITION directly, using the indices in CHANGES. This function does not check any rules, it only makes sure you are not trying to move a blank square." (assert (vectorp position)) @@ -579,7 +579,6 @@ trying to move a blank square." ;; now fix up the resulting position (let ((color (chess-pos-side-to-move position))) - ;; if the move was en-passant, remove the captured pawn (if (memq :en-passant changes) (chess-pos-set-piece position @@ -599,13 +598,13 @@ trying to move a blank square." (chess-pos-set-can-castle position (if color ?Q ?q) nil)) ((= piece ?r) - (let ((king (chess-pos-king-index position color))) - (if (and (chess-pos-can-castle position (if color ?Q ?q)) - (< (chess-index-file (car changes)) king)) - (chess-pos-set-can-castle position (if color ?Q ?q) nil) - (if (and (chess-pos-can-castle position (if color ?K ?k)) - (> (chess-index-file (car changes)) king)) - (chess-pos-set-can-castle position (if color ?K ?k) nil))))) + (if (and (chess-pos-can-castle position (if color ?Q ?q)) + (= (car changes) (chess-pos-can-castle position (if color ?Q ?q)))) + (chess-pos-set-can-castle position (if color ?Q ?q) nil) + (if (and (chess-pos-can-castle position (if color ?K ?k)) + (= (car changes) (chess-pos-can-castle position + (if color ?K ?k)))) + (chess-pos-set-can-castle position (if color ?K ?k) nil)))) ((and (= piece ?p) (> (abs (- (chess-index-rank (cadr changes)) -- cgit v1.2.3