summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--TODO2
-rw-r--r--chess-algebraic.el97
-rw-r--r--chess-display.el2
-rw-r--r--chess-ply.el6
-rw-r--r--chess-pos.el57
6 files changed, 84 insertions, 87 deletions
diff --git a/Makefile b/Makefile
index 9776f49..b4351af 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ chess.dvi: chess-final.texi
$(ENVADD) $(TEXI2DVI) chess-final.texi
clean:
- rm -f *~ chess.dvi chess-final.*
+ rm -f *~ chess.dvi chess-final.* game.* log.*
rm -f *.aux *.cp *.cps *.fn *.fns *.ky *.log *.pg *.toc *.tp *.vr
fullclean: clean
@@ -51,3 +51,8 @@ dist: fullclean all clean
rm -fr /var/tmp/chess-$(VERSION)
mv /var/tmp/chess-$(VERSION).tar.bz2 \
$(HOME)/public_html/Emacs/packages
+
+update:
+ make dist
+ sitecopy
+ make fullclean
diff --git a/TODO b/TODO
index a3461ac..176bab0 100644
--- a/TODO
+++ b/TODO
@@ -30,6 +30,8 @@
- Allow ASCII displays to use a separate frame
+- Add the capacity to abort/resign when there is no engine
+
- Rewrite ics.el
- Make use of the my-color data in chess-game.el to ensure that I only
diff --git a/chess-algebraic.el b/chess-algebraic.el
index 25b13a4..9749220 100644
--- a/chess-algebraic.el
+++ b/chess-algebraic.el
@@ -59,57 +59,54 @@ This regexp handles both long and short form.")
"Convert the algebraic notation MOVE for POSITION to a ply."
(unless (string-match chess-algebraic-regexp-entire move)
(error "Cannot parse non-algebraic move notation: %s" move))
- (let* ((color (chess-pos-side-to-move position))
- (mate (match-string 9 move))
- (promotion (match-string 8 move))
- (piece (aref move 0))
- (changes
- (if (eq piece ?O)
- (let ((rank (if color 7 0))
- (long (= (length (match-string 1 move)) 5)))
- (list (chess-rf-to-index rank 4)
- (chess-rf-to-index rank (if long 2 6))))
- (let ((source (match-string 4 move))
- (target (chess-coord-to-index (match-string 6 move))))
- (if (and source (= (length source) 2))
- (list (chess-coord-to-index source) target)
- (if (= (length source) 0)
- (setq source nil)
- (setq source (aref source 0)))
- (let (candidates which)
- (unless (< piece ?a)
- (setq source piece piece ?P))
- ;; we must use our knowledge of how pieces can
- ;; move, to determine which piece is meant by the
- ;; piece indicator
- (when (setq candidates
- (chess-search-position position target
- (if color piece
- (downcase piece))))
- (if (= (length candidates) 1)
- (list (car candidates) target)
- (if (null source)
- (error "Clarify piece to move by rank or file")
- (while candidates
- (if (if (>= source ?a)
- (eq (chess-index-file (car candidates))
- (- source ?a))
- (eq (chess-index-rank (car candidates))
- (- 7 (- source ?1))))
- (setq which (car candidates) candidates nil)
- (setq candidates (cdr candidates))))
- (if (null which)
- (error "Could not determine which piece to use")
- (list which target)))))))))))
- (if promotion
- (nconc changes
- (list :promote (aref promotion 0))))
+ (let ((mate (match-string 9 move))
+ (piece (aref move 0))
+ changes ply)
+ (if (eq piece ?O)
+ (let ((long (= (length (match-string 1 move)) 5)))
+ (setq ply (chess-ply-create-castle position long)
+ changes (chess-ply-changes ply)))
+ (let ((color (chess-pos-side-to-move position))
+ (promotion (match-string 8 move)))
+ (setq changes
+ (let ((source (match-string 4 move))
+ (target (chess-coord-to-index (match-string 6 move))))
+ (if (and source (= (length source) 2))
+ (list (chess-coord-to-index source) target)
+ (if (= (length source) 0)
+ (setq source nil)
+ (setq source (aref source 0)))
+ (let (candidates which)
+ (unless (< piece ?a)
+ (setq source piece piece ?P))
+ ;; we must use our knowledge of how pieces can
+ ;; move, to determine which piece is meant by the
+ ;; piece indicator
+ (when (setq candidates
+ (chess-search-position position target
+ (if color piece
+ (downcase piece))))
+ (if (= (length candidates) 1)
+ (list (car candidates) target)
+ (if (null source)
+ (error "Clarify piece to move by rank or file")
+ (while candidates
+ (if (if (>= source ?a)
+ (eq (chess-index-file (car candidates))
+ (- source ?a))
+ (eq (chess-index-rank (car candidates))
+ (- 7 (- source ?1))))
+ (setq which (car candidates) candidates nil)
+ (setq candidates (cdr candidates))))
+ (if (null which)
+ (error "Could not determine which piece to use")
+ (list which target)))))))))
+ (if promotion
+ (nconc changes (list :promote (aref promotion 0))))))
(if mate
- (nconc changes
- (list (if (equal mate "#")
- :checkmate
- :check))))
- (and changes (apply 'chess-ply-create position changes))))
+ (nconc changes (list (if (equal mate "#") :checkmate :check))))
+
+ (or ply (and changes (cons (chess-pos-copy position) changes)))))
(defun chess-ply-to-algebraic (ply &optional long)
"Convert the given PLY to algebraic notation.
diff --git a/chess-display.el b/chess-display.el
index fe41a96..f62fdbb 100644
--- a/chess-display.el
+++ b/chess-display.el
@@ -959,7 +959,7 @@ Clicking once on a piece selects it; then click on the target location."
(throw 'invalid t))
(setq ply (chess-ply-create position (cadr last-sel) coord))
(unless ply
- (message "That piece cannot move there in this position.")
+ (message "That is not a legal move.")
(throw 'invalid t))
(chess-display-move nil ply)))
(setq chess-display-last-selected nil))
diff --git a/chess-ply.el b/chess-ply.el
index e1a3af1..391264b 100644
--- a/chess-ply.el
+++ b/chess-ply.el
@@ -88,8 +88,8 @@
(defun chess-ply-create-castle (position &optional long)
"Create a castling ply; this function supports Fischer Random castling."
(let* ((color (chess-pos-side-to-move position))
- (king (chess-pos-search position (if color ?K ?k)))
- (king-target (chess-rf-to-index rank (if long 2 6)))
+ (king (car (chess-pos-search position (if color ?K ?k))))
+ (king-target (chess-rf-to-index (if color 7 0) (if long 2 6)))
(king-file (chess-index-file king))
(file (if long 0 7))
rook)
@@ -102,7 +102,7 @@
(chess-search-position position king-target (if color ?K ?k)))
(cons (chess-pos-copy position)
(list king king-target rook
- (chess-rf-to-index rank (if long 3 5))
+ (chess-rf-to-index (if color 7 0) (if long 3 5))
(if long :long-castle :castle))))))
(defun chess-ply-create (position &rest changes)
diff --git a/chess-pos.el b/chess-pos.el
index f326c09..7249399 100644
--- a/chess-pos.el
+++ b/chess-pos.el
@@ -281,9 +281,7 @@ trying to move a blank square."
(unless (symbolp (car changes))
(let ((piece (downcase (chess-pos-piece position (cadr changes)))))
(cond
- ((and (= piece ?k)
- (equal (car changes)
- (chess-rf-to-index (if color 7 0) 4)))
+ ((= piece ?k)
(chess-pos-set-can-castle position (if color ?K ?k) nil)
(chess-pos-set-can-castle position (if color ?Q ?q) nil))
@@ -380,8 +378,9 @@ indices which indicate where a piece may have moved from."
(if (setq pos (chess-add-index target (- bias) 0))
(if (chess-pos-piece-p position pos piece)
(setq candidates (list pos))
- (when (and (= ? (chess-pos-piece position pos))
- (= (if color 4 3) (chess-index-rank target)))
+ (when (and (chess-pos-piece-p position pos ? )
+ (= (if color 4 3)
+ (chess-index-rank target)))
(setq pos (chess-add-index pos (- bias) 0))
(if (and pos (chess-pos-piece-p position pos piece))
(setq candidates (list pos)))))))))
@@ -410,7 +409,7 @@ indices which indicate where a piece may have moved from."
(progn
(nconc candidates (list pos))
(setq pos nil))
- (if (/= (chess-pos-piece position pos) ? )
+ (if (not (chess-pos-piece-p position pos ? ))
(setq pos nil)
(setq pos (apply 'chess-add-index pos dir))))))
(setq candidates (cdr candidates)))
@@ -430,32 +429,26 @@ indices which indicate where a piece may have moved from."
;; if we can still castle, then the king and rook are in their
;; squares; also, make sure that the user is not attempting to
;; castle through check
- (if (and
- (null candidates)
- (or (and (equal target (chess-rf-to-index rank 6))
- (= (chess-pos-piece position (chess-rf-to-index rank 4))
- (if color ?K ?k))
- (chess-pos-can-castle position (if color ?K ?k))
- (setq pos (chess-rf-to-index rank 5))
- (chess-pos-piece-p position pos ? )
- (not (chess-search-position position pos (not color)))
- (setq pos (chess-rf-to-index rank 6))
- (chess-pos-piece-p position pos ? )
- (not (chess-search-position position pos (not color))))
- (and (equal target (chess-rf-to-index rank 2))
- (= (chess-pos-piece position (chess-rf-to-index rank 4))
- (if color ?K ?k))
- (chess-pos-can-castle position (if color ?Q ?q))
- (setq pos (chess-rf-to-index rank 1))
- (chess-pos-piece-p position pos ? )
- (not (chess-search-position position pos (not color)))
- (setq pos (chess-rf-to-index rank 2))
- (chess-pos-piece-p position pos ? )
- (not (chess-search-position position pos (not color)))
- (setq pos (chess-rf-to-index rank 3))
- (chess-pos-piece-p position pos ? )
- (not (chess-search-position position pos (not color))))))
- (setq candidates (list (chess-rf-to-index rank 4))))))
+ (if (and (null candidates)
+ (or (and (equal target (chess-rf-to-index rank 6))
+ (chess-pos-can-castle position (if color ?K ?k)))
+ (and (equal target (chess-rf-to-index rank 2))
+ (chess-pos-can-castle position (if color ?Q ?q)))))
+ (let* ((king (car (chess-pos-search position piece)))
+ (king-file (chess-index-file king))
+ (long (= 2 (chess-index-file target)))
+ (file (if long 1 6))
+ (legal t))
+ ;; jww (2002-04-10): this needs to be a bit more subtle
+ ;; for Fischer Random castling
+ (while (and legal (funcall (if long '< '>) file king-file))
+ (setq pos (chess-rf-to-index rank file))
+ (if (or (not (chess-pos-piece-p position pos ? ))
+ (chess-search-position position pos (not color)))
+ (setq legal nil)
+ (setq file (funcall (if long '1+ '1-) file))))
+ (if legal
+ (setq candidates (list (chess-rf-to-index rank 4))))))))
;; the knight is a zesty little piece; there may be more than
;; one, but at only one possible square in each direction