summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2002-04-08 23:03:39 +0000
committerJohn Wiegley <johnw@newartisans.com>2002-04-08 23:03:39 +0000
commitc67544683ffed1660bad0d5e67a6e5d47e288be1 (patch)
treeb1fe54ca64b0458e753e77aec16368c012a77fb8
parentecaf5a3842adc0bd38b069184a031b8530c620cb (diff)
*** no comment ***
-rw-r--r--chess-display.el8
-rw-r--r--chess-engine.el21
-rw-r--r--chess-gnuchess.el16
-rw-r--r--chess-network.el10
4 files changed, 39 insertions, 16 deletions
diff --git a/chess-display.el b/chess-display.el
index aba88ec..9dc80a3 100644
--- a/chess-display.el
+++ b/chess-display.el
@@ -316,6 +316,7 @@ See `chess-display-type' for the different kinds of displays."
(define-key map [?X] 'chess-display-quit)
(define-key map [?M] 'chess-display-manual-move)
(define-key map [?@] 'chess-display-remote)
+ (define-key map [? ] 'chess-display-pass)
(define-key map [?<] 'chess-display-move-first)
(define-key map [?,] 'chess-display-move-backward)
@@ -467,6 +468,13 @@ Basically, it means we are playing, not editing or reviewing."
(chess-display-set-game (chess-display-create 'chess-images t)
(chess-display-game nil))))
+(defun chess-display-pass ()
+ "Pass the move to your opponent. Only valid on the first move."
+ (interactive)
+ (when (and (chess-display-active-p)
+ (= 0 (chess-display-index nil)))
+ (chess-game-run-hooks chess-display-game 'pass)))
+
(defun chess-display-set-current (dir)
"Change the currently displayed board.
Direction may be - or +, to move forward or back, or t or nil to jump
diff --git a/chess-engine.el b/chess-engine.el
index 318c205..419444b 100644
--- a/chess-engine.el
+++ b/chess-engine.el
@@ -56,7 +56,21 @@
(defun chess-engine-default-handler (event &rest args)
(cond
((eq event 'move)
- (chess-engine-do-move (car args)))))
+ (chess-engine-do-move (car args)))
+
+ ((eq event 'pass)
+ (message "Your opponent has passed the first move to you"))
+
+ ((eq event 'connect)
+ (message "Your opponent, %s, is now ready to play" (car args)))
+
+ ((eq event 'quit)
+ (message "Your opponent has quit playing"))
+
+ ((eq event 'setup)
+ (let* ((position (chess-fen-to-pos (car args)))
+ (ply (chess-ply-create position)))
+ (chess-game-set-plies (chess-engine-game nil) (list ply))))))
(defun chess-engine-create (module &optional user-handler &rest args)
(let ((regexp-alist (intern-soft (concat (symbol-name module)
@@ -178,10 +192,7 @@
(chess-engine-destroy engine))
((eq event 'setup)
- (chess-engine-set-game engine (car args)))
-
- ((eq event 'pass)
- (chess-engine-pass engine)))))
+ (chess-engine-set-game engine (car args))))))
(defun chess-engine-filter (proc string)
"Filter for receiving text for an engine from an outside source."
diff --git a/chess-gnuchess.el b/chess-gnuchess.el
index 48803ea..e7f2aa4 100644
--- a/chess-gnuchess.el
+++ b/chess-gnuchess.el
@@ -58,13 +58,19 @@
(delete-file file)))))
((eq event 'setup)
- (let ((file (make-temp-file "gch")))
- (with-temp-file file
- (insert (chess-pos-to-fen (car args)) ?\n))
- (chess-engine-send nil (format "epdload %s\n" file))
- (push file chess-gnuchess-temp-files)))
+ (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-fen (car args)) ?\n))
+ (chess-engine-send nil (format "epdload %s\n" file))
+ (push file chess-gnuchess-temp-files))))
((eq event 'pass)
+ (chess-engine-send nil (concat (if (chess-pos-side-to-move
+ (chess-engine-position nil))
+ "white" "black")
+ "\n"))
(chess-engine-send nil "go\n"))
((eq event 'move)
diff --git a/chess-network.el b/chess-network.el
index c2aae2c..8c4f558 100644
--- a/chess-network.el
+++ b/chess-network.el
@@ -16,7 +16,7 @@
(cons "pass"
(function
(lambda ()
- (message "Your opponent has passed the move to you"))))
+ (funcall chess-engine-response-handler 'pass))))
(cons "name\\s-+\\(.+\\)"
(function
(lambda ()
@@ -25,14 +25,12 @@
(cons "fen\\s-+\\(.+\\)"
(function
(lambda ()
- (let* ((position (chess-fen-to-pos (match-string 1)))
- (ply (chess-ply-create position)))
- (chess-game-set-plies (chess-engine-game nil)
- (list ply))))))
+ (funcall chess-engine-response-handler 'setup
+ (match-string 1)))))
(cons "quit"
(function
(lambda ()
- (message "Your opponent has quit playing"))))))
+ (funcall chess-engine-response-handler 'quit))))))
(defun chess-network-perform-move ()
(let* ((move (match-string 1))