diff options
| -rw-r--r-- | chess-algebraic.el | 4 | ||||
| -rw-r--r-- | chess-display.el | 45 | ||||
| -rw-r--r-- | chess-ics1.el | 3 | ||||
| -rw-r--r-- | chess-pgn.el | 6 | ||||
| -rw-r--r-- | chess-pos.el | 5 |
5 files changed, 44 insertions, 19 deletions
diff --git a/chess-algebraic.el b/chess-algebraic.el index 7aebdf3..69cb073 100644 --- a/chess-algebraic.el +++ b/chess-algebraic.el @@ -57,6 +57,7 @@ This regexp handles both long and short form.") (error "Cannot parse non-algebraic move notation: %s" move)) (let* ((color (chess-pos-side-to-move position)) (mate (match-string 10 move)) + (promotion (match-string 9 move)) (piece (aref move 0)) (changes (if (eq piece ?O) @@ -96,6 +97,9 @@ This regexp handles both long and short form.") (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 "#") diff --git a/chess-display.el b/chess-display.el index 1582817..92f25c7 100644 --- a/chess-display.el +++ b/chess-display.el @@ -209,7 +209,7 @@ variation that was passed in." (chess-display-detach-game nil)) (setq chess-display-game nil chess-display-variation variation - chess-display-index (or index 0) + chess-display-index (chess-var-index variation) chess-display-ply nil chess-display-position nil) (chess-display-update nil t))) @@ -230,7 +230,7 @@ modeline." (chess-display-detach-game nil)) (setq chess-display-game game chess-display-variation nil - chess-display-index (or index 0) + chess-display-index (chess-game-index game) chess-display-ply nil chess-display-position nil) (chess-game-add-hook game 'chess-display-event-handler display) @@ -509,19 +509,38 @@ Basically, it means we are playing, not editing or reviewing." (interactive "sSet from FEN string: ") (chess-display-set-position nil (chess-fen-to-pos fen))) -(defun chess-display-copy-board () +(defun chess-display-copy-board (&optional arg) "Send the current board configuration to the user." - (interactive) - (let* ((x-select-enable-clipboard t) - (fen (chess-pos-to-fen (chess-display-position nil)))) - (kill-new fen))) + (interactive "P") + (let ((x-select-enable-clipboard t)) + (if (and arg chess-display-game) + (kill-new (with-temp-buffer + (chess-game-to-pgn (chess-display-game nil)) + (buffer-string))) + (kill-new (chess-pos-to-fen (chess-display-position nil)))))) (defun chess-display-paste-board () "Send the current board configuration to the user." (interactive) - (let* ((x-select-enable-clipboard t) - (fen (current-kill 0))) - (chess-display-set-from-fen fen))) + (let ((x-select-enable-clipboard t) + (display (current-buffer))) + (with-temp-buffer + (insert (current-kill 0)) + (goto-char (point-max)) + (while (and (bolp) (not (bobp))) + (delete-backward-char 1)) + (goto-char (point-min)) + (cond + ((search-forward "[Event" nil t) + (goto-char (match-beginning 0)) + (chess-display-set-game display (chess-pgn-to-game))) + ((looking-at (concat chess-algebraic-regexp "$")) + (let ((move (buffer-string))) + (with-current-buffer display + (chess-display-manual-move move)))) + (t + (with-current-buffer display + (chess-display-set-from-fen (buffer-string)))))))) (defun chess-display-set-piece () "Set the piece under point to command character, or space for clear." @@ -778,11 +797,7 @@ to the end or beginning." chess-legal-moves)))) (cond ((= (length moves) 1) - (let ((ply (chess-algebraic-to-ply (chess-display-position nil) - (car moves)))) - (unless ply - (error "Illegal move notation: %s" (car moves))) - (chess-display-move nil ply)) + (chess-display-manual-move (car moves)) (setq chess-move-string nil chess-legal-moves nil chess-legal-moves-pos nil)) diff --git a/chess-ics1.el b/chess-ics1.el index 8a6e24d..0ce297e 100644 --- a/chess-ics1.el +++ b/chess-ics1.el @@ -98,7 +98,8 @@ PERSPECTIVE is t for white or nil for black." (interactive) (let ((pos (or position (chess-engine-position nil)))) (with-current-buffer (get-buffer-create "*scratch*") - (chess-ics1-draw pos t)))) + (chess-ics1-draw pos t) + (funcall chess-ics1-popup-function)))) (provide 'chess-ics1) diff --git a/chess-pgn.el b/chess-pgn.el index bc06741..fbd2237 100644 --- a/chess-pgn.el +++ b/chess-pgn.el @@ -21,7 +21,7 @@ (goto-char (match-end 0)) (setq prevpos position) (let* ((move (match-string 0)) - (ply (chess-algebraic-to-ply (chess-game-pos game) + (ply (chess-algebraic-to-ply position (match-string 0)))) (unless ply (error "Error reading move: %s" move)) @@ -69,7 +69,9 @@ (chess-fen-to-pos fen) (chess-pos-copy chess-starting-position)) t) ;; set the starting position to the FEN string - (list (chess-ply-create (chess-fen-to-pos fen)))))) + (list (chess-ply-create (if fen + (chess-fen-to-pos fen) + chess-starting-position)))))) game))) (defun chess-pgn-insert-annotations (game index ply) diff --git a/chess-pos.el b/chess-pos.el index d6aa178..33f1aad 100644 --- a/chess-pos.el +++ b/chess-pos.el @@ -301,7 +301,10 @@ trying to move a blank square." ;; promote the piece if we were meant to (let ((new-piece (cadr (memq :promote changes)))) (if new-piece - (chess-pos-set-piece position (cadr changes) new-piece))) + (chess-pos-set-piece position (cadr changes) + (if color + new-piece + (downcase new-piece))))) ;; did we leave the position in check, mate or stalemate? (cond |
