diff options
| -rw-r--r-- | chess-display.el | 12 | ||||
| -rw-r--r-- | chess-engine.el | 12 | ||||
| -rw-r--r-- | chess-game.el | 21 | ||||
| -rw-r--r-- | chess-irc.el | 2 | ||||
| -rw-r--r-- | chess.el | 4 |
5 files changed, 40 insertions, 11 deletions
diff --git a/chess-display.el b/chess-display.el index 24a4638..0bcd022 100644 --- a/chess-display.el +++ b/chess-display.el @@ -289,8 +289,12 @@ See `chess-display-type' for the different kinds of displays." (chess-display-destroy nil))) ((eq event 'pass) - (chess-display-set-perspective - nil (not (chess-display-perspective nil)))) + (let ((my-color (if chess-display-game + (chess-game-get-data chess-display-game 'my-color) + (chess-display-perspective nil)))) + (if chess-display-game + (chess-game-set-data chess-display-game 'my-color (not my-color))) + (chess-display-set-perspective nil (not my-color)))) ((memq event '(move game-over resign)) (chess-display-set-index nil (chess-game-index @@ -634,7 +638,9 @@ to the end or beginning." (defun chess-keyboard-shortcut-delete () (interactive) - (when chess-move-string + (when (and chess-move-string + (stringp chess-move-string) + (> (length chess-move-string) 1)) (setq chess-move-string (substring chess-move-string 0 (1- (length chess-move-string)))) diff --git a/chess-engine.el b/chess-engine.el index 6c5df34..fd448fe 100644 --- a/chess-engine.el +++ b/chess-engine.el @@ -62,10 +62,16 @@ (let ((chess-engine-handling-event t)) (cond ((eq event 'move) + ;; if the game index is still 0, then our opponent is white, and ;; we need to pass over the move - (if (= (chess-game-index (chess-engine-game nil)) 0) - (chess-game-run-hooks (chess-engine-game nil) 'pass)) + (let ((game (chess-engine-game nil))) + (when (and game (chess-game-get-data game 'my-color) + (= (chess-game-index game) 0)) + (chess-game-run-hooks game 'pass) + ;; if no one else flipped my-color, we'll do it + (if (chess-game-get-data game 'my-color) + (chess-game-set-data game 'my-color nil)))) (let ((ply (chess-algebraic-to-ply (chess-engine-position nil) (car args)))) @@ -78,7 +84,7 @@ ((eq event 'connect) (message "Your opponent, %s, is now ready to play" (car args)) - (chess-engine-send nil "name %s\n" (user-full-name))) + (chess-engine-send nil (format "name %s\n" (user-full-name)))) ((eq event 'quit) (message "Your opponent has quit playing")) diff --git a/chess-game.el b/chess-game.el index cd39624..6e22ff8 100644 --- a/chess-game.el +++ b/chess-game.el @@ -82,12 +82,25 @@ (chess-game-run-hooks game 'delete-tag tag)) -(defsubst chess-game-data (game) +(defsubst chess-game-data-alist (game) (nth 2 game)) -(defsubst chess-game-set-data (game data) - (setcar (nthcdr 1 game) data) - (chess-game-run-hooks game 'set-data)) +(defun chess-game-set-data (game key value) + (let ((alist (chess-game-data-alist game))) + (if (null alist) + (setcar (nthcdr 1 game) (list (cons key value))) + (push (cons key value) alist)) + (chess-game-run-hooks game 'set-data key))) + +(defun chess-game-get-data (game key) + (let ((alist (chess-game-data-alist game))) + (if alist + (cdr (assq key alist))))) + +(defun chess-game-del-data (game key) + (let ((alist (chess-game-data-alist game))) + (if alist + (assq-delete-all key alist)))) (defsubst chess-game-plies (game) diff --git a/chess-irc.el b/chess-irc.el index 033beea..d1fe256 100644 --- a/chess-irc.el +++ b/chess-irc.el @@ -65,7 +65,7 @@ (set-process-filter proc 'chess-irc-filter) (set-process-buffer proc (current-buffer)) (set-marker (process-mark proc) (point)) - (message "Now waiting for 'name USER' via /msg; or use `M-x chess-irc-engage'"))) + (message "Now waiting for 'name USER' via /msg; or `M-x chess-irc-engage'"))) (setq chess-irc-process proc)) nil) @@ -111,9 +111,13 @@ minibuffer, which works well for Emacspeak users." (interactive "P") (let ((game (chess-game-create)) ; start out as white always display engine) + (game (chess-game-create))) + (chess-game-set-data game 'my-color t) + (require chess-default-display) (chess-display-set-game (chess-display-create chess-default-display t) game) + (chess-display-set-main display) (let ((engine-module (if arg (intern (or (read-string "Engine module to play against: ") |
