diff options
| author | John Wiegley <johnw@newartisans.com> | 2002-04-10 23:55:13 +0000 |
|---|---|---|
| committer | John Wiegley <johnw@newartisans.com> | 2002-04-10 23:55:13 +0000 |
| commit | a0769011c2a98841156559aa37978156766cc09f (patch) | |
| tree | 407832c3c0fac049e9e7d567614894cc47e76f3c | |
| parent | 5fbbfaf36f1dc7da3c7539568fe473bbf079c513 (diff) | |
Added support for aborting a game. Use A or N from a display.
| -rw-r--r-- | chess-crafty.el | 12 | ||||
| -rw-r--r-- | chess-display.el | 17 | ||||
| -rw-r--r-- | chess-engine.el | 13 | ||||
| -rw-r--r-- | chess-game.el | 19 | ||||
| -rw-r--r-- | chess-gnuchess.el | 17 | ||||
| -rw-r--r-- | chess-ics.el | 3 | ||||
| -rw-r--r-- | chess-link.el | 13 | ||||
| -rw-r--r-- | chess-network.el | 9 |
8 files changed, 77 insertions, 26 deletions
diff --git a/chess-crafty.el b/chess-crafty.el index 12ffb3a..b14db83 100644 --- a/chess-crafty.el +++ b/chess-crafty.el @@ -29,7 +29,7 @@ (lambda () (funcall chess-engine-response-handler 'move (chess-engine-convert-algebraic (match-string 2)))))) - (cons "Illegal move:\\s-*\\(.*\\)" + (cons "\\(Illegal move\\|unrecognized/illegal command\\):\\s-*\\(.*\\)" (function (lambda () (signal 'chess-illegal (match-string 1))))))) @@ -65,9 +65,8 @@ (delete-file file)))) ((eq event 'ready) - (let ((game (chess-engine-game nil))) - (if game - (chess-game-set-data game 'active t)))) + (and (chess-engine-game nil) + (chess-game-set-data (chess-engine-game nil) 'active t))) ((eq event 'setup-pos) (chess-engine-send nil (format "setboard %s\n" @@ -83,6 +82,11 @@ ((eq event 'pass) (chess-engine-send nil "go\n")) + ((memq event '(abort resign)) + (chess-engine-send nil "new\n") + (and (chess-engine-game nil) + (chess-engine-set-start-position nil))) + ((eq event 'move) (chess-engine-send nil (concat (chess-ply-to-algebraic (car args)) "\n"))))) diff --git a/chess-display.el b/chess-display.el index d725e6d..67fbf3f 100644 --- a/chess-display.el +++ b/chess-display.el @@ -393,9 +393,11 @@ See `chess-display-type' for the different kinds of displays." ((eq event 'orient) ;; Set the display's perspective to whichever color I'm playing - (if chess-display-game - (chess-display-set-perspective* - nil (chess-game-data chess-display-game 'my-color)))) + (when chess-display-game + (chess-display-set-index* + nil (chess-game-index (chess-display-game nil))) + (chess-display-set-perspective* + nil (chess-game-data chess-display-game 'my-color)))) ((memq event '(move game-over resign)) (chess-display-set-index* @@ -433,6 +435,8 @@ See `chess-display-type' for the different kinds of displays." (define-key map [? ] 'chess-display-pass) (define-key map [?S] 'chess-display-shuffle) (define-key map [?R] 'chess-display-resign) + (define-key map [?A] 'chess-display-abort) + (define-key map [?N] 'chess-display-abort) (define-key map [?<] 'chess-display-move-first) (define-key map [?,] 'chess-display-move-backward) @@ -657,6 +661,13 @@ Basically, it means we are playing, not editing or reviewing." (chess-game-resign chess-display-game) (ding))) +(defun chess-display-abort () + "Abort the current game." + (interactive) + (if (chess-display-active-p) + (chess-game-run-hooks chess-display-game 'abort) + (ding))) + (defun chess-display-list-buffers () "List all buffers related to this display's current game." (interactive) diff --git a/chess-engine.el b/chess-engine.el index ba85444..189ad15 100644 --- a/chess-engine.el +++ b/chess-engine.el @@ -128,7 +128,7 @@ ;; accepting side (unless game (setq game (chess-engine-set-game nil (chess-game-create)))) - (chess-engine-set-start-position engine) + (chess-engine-set-start-position nil) t)) ((eq event 'setup-pos) @@ -159,6 +159,12 @@ (when game (chess-game-resign game) (chess-game-set-data game 'active nil) + t)) + + ((eq event 'abort) + (when game + (message "Your opponent has aborted the game") + (chess-game-set-data game 'active nil) t))))) (defun chess-engine-create (module &optional response-handler &rest args) @@ -311,6 +317,10 @@ function in all cases; this is merely a bandwidth-saver." (chess-with-current-buffer engine (chess-engine-command engine 'resign))) +(defun chess-engine-abort (engine) + (chess-with-current-buffer engine + (chess-engine-command engine 'abort))) + (defun chess-engine-send (engine string) "Send the given STRING to ENGINE." (chess-with-current-buffer engine @@ -372,7 +382,6 @@ function in all cases; this is merely a bandwidth-saver." (if chess-engine-last-pos (goto-char chess-engine-last-pos) (goto-char (point-min))) - (beginning-of-line) (while (not (eobp)) (let ((triggers chess-engine-regexp-alist)) (while triggers diff --git a/chess-game.el b/chess-game.el index 995e741..35e41ce 100644 --- a/chess-game.el +++ b/chess-game.el @@ -101,11 +101,14 @@ matches." (nth 2 game)) (defun chess-game-set-data (game key value) - (let ((alist (chess-game-data-alist game))) - (if (null alist) - (setcar (nthcdr 2 game) (list (cons key value))) - (push (cons key value) alist) - (setcar (nthcdr 2 game) alist)) + (let* ((alist (chess-game-data-alist game)) + (cell (assq key alist))) + (if cell + (setcdr cell value) + (if (null alist) + (setcar (nthcdr 2 game) (list (cons key value))) + (push (cons key value) alist) + (setcar (nthcdr 2 game) alist))) (chess-game-run-hooks game 'set-data key))) (defun chess-game-data (game key) @@ -163,6 +166,12 @@ matches." (chess-game-set-plies game (list ply))))) +(defsubst chess-game-over-p (game) + "Return the position related to GAME's INDEX position." + (let ((last-ply (car (last game 2)))) + (and last-ply (chess-ply-final-p last-ply)))) + + (defsubst chess-game-to-string (game &optional indented) (chess-game-to-pgn game indented t)) diff --git a/chess-gnuchess.el b/chess-gnuchess.el index dbf529d..4d17d83 100644 --- a/chess-gnuchess.el +++ b/chess-gnuchess.el @@ -66,13 +66,11 @@ (chess-game-set-data game 'active t)))) ((eq event 'setup-pos) - (if (equal (car args) chess-starting-position) - (chess-engine-send nil "new\n") - (let ((file (make-temp-file "gch"))) - (with-temp-file file - (insert (chess-pos-to-string (car args)) ?\n)) - (chess-engine-send nil (format "epdload %s\n" file)) - (push file chess-gnuchess-temp-files)))) + (let ((file (make-temp-file "gch"))) + (with-temp-file file + (insert (chess-pos-to-string (car args)) ?\n)) + (chess-engine-send nil (format "epdload %s\n" file)) + (push file chess-gnuchess-temp-files))) ((eq event 'setup-game) (let ((file (make-temp-file "gch"))) @@ -89,6 +87,11 @@ (chess-engine-send nil "go\n") (setq chess-gnuchess-bad-board nil)) + ((memq event '(abort resign)) + (chess-engine-send nil "new\n") + (and (chess-engine-game nil) + (chess-engine-set-start-position nil))) + ((eq event 'move) (chess-engine-send nil (concat (chess-ply-to-algebraic (car args)) "\n")) diff --git a/chess-ics.el b/chess-ics.el index f6fea32..cd47b44 100644 --- a/chess-ics.el +++ b/chess-ics.el @@ -198,6 +198,9 @@ who is black." ((eq event 'resign) (chess-engine-send nil "resign\n")) + ((eq event 'abort) + (chess-engine-send nil "abort\n")) + ((eq event 'send) (comint-send-string (get-buffer-process (current-buffer)) (car args))))) diff --git a/chess-link.el b/chess-link.el index 47e58e8..a65a583 100644 --- a/chess-link.el +++ b/chess-link.el @@ -14,20 +14,25 @@ "This function handles responses from the bot's computing engine." (let* ((game (chess-engine-game nil)) (first-engine (chess-game-data game 'first-engine)) - (second-engine (chess-game-data game 'second-engine))) + (second-engine (chess-game-data game 'second-engine)) + return-value) (cond ((eq event 'connect) - (chess-engine-command nil 'accept)) + (chess-engine-command nil 'accept) + t) (t (let ((chess-engine-inhibit-auto-pass t)) - (apply 'chess-engine-default-handler event args)) + (setq return-value + (apply 'chess-engine-default-handler event args))) ;; but now transfer the event to the other engine (apply 'chess-engine-command (if (eq (current-buffer) first-engine) second-engine - first-engine) event args))))) + first-engine) event args) + + return-value)))) (defun chess-link-connect (first-engine second-engine) "Connect two engines, so that they rely events back and forth." diff --git a/chess-network.el b/chess-network.el index a4befa2..32dc70b 100644 --- a/chess-network.el +++ b/chess-network.el @@ -46,7 +46,11 @@ (cons "resign$" (function (lambda () - (funcall chess-engine-response-handler 'resign)))))) + (funcall chess-engine-response-handler 'resign)))) + (cons "abort$" + (function + (lambda () + (funcall chess-engine-response-handler 'abort)))))) (defun chess-network-handler (event &rest args) "Initialize the network chess engine." @@ -94,6 +98,9 @@ ((eq event 'resign) (chess-engine-send nil "resign\n")) + ((eq event 'abort) + (chess-engine-send nil "abort\n")) + ((eq event 'move) (chess-engine-send nil (concat (chess-ply-to-algebraic (car args)) "\n"))))) |
