summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2002-04-11 01:06:10 +0000
committerJohn Wiegley <johnw@newartisans.com>2002-04-11 01:06:10 +0000
commit3375c5ff17acb3e9af7f2c011a6961e0623d02ad (patch)
treea4d175e47627b7d2245893a0ad2334249739853a
parentda4dceb58f252519caae28e3b2e049a5bd74c098 (diff)
added undo support
-rw-r--r--chess-crafty.el6
-rw-r--r--chess-display.el18
-rw-r--r--chess-gnuchess.el6
-rw-r--r--chess-phalanx.el6
4 files changed, 36 insertions, 0 deletions
diff --git a/chess-crafty.el b/chess-crafty.el
index b14db83..880ee14 100644
--- a/chess-crafty.el
+++ b/chess-crafty.el
@@ -87,6 +87,12 @@
(and (chess-engine-game nil)
(chess-engine-set-start-position nil)))
+ ((eq event 'undo)
+ (when (chess-engine-game nil)
+ (dotimes (i (car args))
+ (chess-engine-send nil "undo\n"))
+ (chess-game-undo (chess-engine-game nil) (car args))))
+
((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 67fbf3f..51f9ddc 100644
--- a/chess-display.el
+++ b/chess-display.el
@@ -437,6 +437,7 @@ See `chess-display-type' for the different kinds of displays."
(define-key map [?R] 'chess-display-resign)
(define-key map [?A] 'chess-display-abort)
(define-key map [?N] 'chess-display-abort)
+ (define-key map [?U] 'chess-display-undo)
(define-key map [?<] 'chess-display-move-first)
(define-key map [?,] 'chess-display-move-backward)
@@ -668,6 +669,23 @@ Basically, it means we are playing, not editing or reviewing."
(chess-game-run-hooks chess-display-game 'abort)
(ding)))
+(defun chess-display-undo (count)
+ "Abort the current game."
+ (interactive "P")
+ (if (chess-display-active-p)
+ ;; we can't call `chess-game-undo' directly, because not all
+ ;; engines will accept it right away! So we just signal the
+ ;; desire to undo
+ (chess-game-run-hooks
+ chess-display-game 'undo
+ (if count
+ (prefix-numeric-value count)
+ (if (eq (chess-pos-side-to-move
+ (chess-display-position nil))
+ (chess-game-data chess-display-game 'my-color))
+ 2 1)))
+ (ding)))
+
(defun chess-display-list-buffers ()
"List all buffers related to this display's current game."
(interactive)
diff --git a/chess-gnuchess.el b/chess-gnuchess.el
index 4d17d83..2950d86 100644
--- a/chess-gnuchess.el
+++ b/chess-gnuchess.el
@@ -92,6 +92,12 @@
(and (chess-engine-game nil)
(chess-engine-set-start-position nil)))
+ ((eq event 'undo)
+ (when (chess-engine-game nil)
+ (dotimes (i (car args))
+ (chess-engine-send nil "undo\n"))
+ (chess-game-undo (chess-engine-game nil) (car args))))
+
((eq event 'move)
(chess-engine-send nil (concat (chess-ply-to-algebraic (car args))
"\n"))
diff --git a/chess-phalanx.el b/chess-phalanx.el
index 7b902a4..0eb3ae0 100644
--- a/chess-phalanx.el
+++ b/chess-phalanx.el
@@ -57,6 +57,12 @@
(and (chess-engine-game nil)
(chess-engine-set-start-position nil)))
+ ((eq event 'undo)
+ (when (chess-engine-game nil)
+ (dotimes (i (car args))
+ (chess-engine-send nil "undo\n"))
+ (chess-game-undo (chess-engine-game nil) (car args))))
+
((eq event 'move)
(chess-engine-send nil (concat (chess-ply-to-algebraic (car args))
"\n")))))