summaryrefslogtreecommitdiff
path: root/chess-ucb.el
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2002-04-26 19:23:01 +0000
committerJohn Wiegley <johnw@newartisans.com>2002-04-26 19:23:01 +0000
commit7248e5c89f6d53d3f2a4ecf511167af929241f76 (patch)
tree8d1f7c8dd8be449e9445268fb9e16e22a672e597 /chess-ucb.el
parent0690915d43e400c7713cafdadf205d233122ac20 (diff)
*** no comment ***
Diffstat (limited to 'chess-ucb.el')
-rw-r--r--chess-ucb.el85
1 files changed, 45 insertions, 40 deletions
diff --git a/chess-ucb.el b/chess-ucb.el
index 7d35152..5819f20 100644
--- a/chess-ucb.el
+++ b/chess-ucb.el
@@ -18,6 +18,8 @@
:type 'file
:group 'chess-ucb)
+(defvar chess-ucb-handling-event nil)
+
(defvar chess-ucb-regexp-alist
(list
(cons "^M\\(..\\)\\(..\\)\\(/\\([QRNB]\\)\\)?\r\n"
@@ -29,55 +31,58 @@
(promote (match-string 4)))
(if promote
(setq move (concat move "=" promote)))
+ (setq move (chess-engine-convert-algebraic move))
;; I don't use the usual engine logic for this, since
;; technically the UCB is just an input interface, not a
;; true engine.
- (chess-game-move game
- (chess-engine-convert-algebraic move))))))))
+ (let ((chess-ucb-handling-event t))
+ (chess-game-move game move))))))))
(defun chess-ucb-handler (game event &rest args)
- (cond
- ((eq event 'initialize)
- (when (file-exists-p chess-ucb-device)
- ;; jww (2002-04-25): cat is not bidirectional, so I need
- ;; something like "nc" that can talk with characters devices
- ;; at 9600 8N1.
- (start-process "*chess-ucb*" (current-buffer)
- (executable-find "cat") chess-ucb-device)
- t))
+ (unless chess-ucb-handling-event
+ (cond
+ ((eq event 'initialize)
+ (when (file-exists-p chess-ucb-device)
+ ;; jww (2002-04-25): cat is not bidirectional, so I need
+ ;; something like "nc" that can talk with characters devices
+ ;; at 9600 8N1.
+ (start-process "*chess-ucb*" (current-buffer)
+ (executable-find "cat") chess-ucb-device)
+ t))
- ((memq event 'orient)
- (chess-engine-send nil "N\r\n")
- (chess-engine-set-position nil)
+ ((memq event 'orient)
+ (chess-engine-send nil "N\r\n")
+ (chess-engine-set-position nil)
- ;; jww (2002-04-25): What happens if we're orienting to a
- ;; non-standard starting position? How do we inform the UCB of
- ;; the new position? If it doesn't test move legality, I suppose
- ;; we could just move all the pieces around one by one...
- (unless (eq chess-starting-position (chess-engine-position nil))
- nil))
+ ;; jww (2002-04-25): What happens if we're orienting to a
+ ;; non-standard starting position? How do we inform the UCB of
+ ;; the new position? If it doesn't test move legality, I
+ ;; suppose we could just move all the pieces around one by
+ ;; one...
+ (unless (eq chess-starting-position (chess-engine-position nil))
+ nil))
- ((eq event 'undo)
- (dotimes (i (car args))
- (chess-engine-send nil "T\r\n"))
- ;; prevent us from handling the `undo' event which this triggers
- (let ((chess-engine-handling-event t))
- (chess-game-undo game (car args))))
+ ((eq event 'undo)
+ (dotimes (i (car args))
+ (chess-engine-send nil "T\r\n"))
+ ;; prevent us from handling the `undo' event which this triggers
+ (let ((chess-engine-handling-event t))
+ (chess-game-undo game (car args))))
- ((eq event 'move)
- (let ((move (chess-ply-to-algebraic (car args) t)))
- (cond
- ((chess-ply-keyword (car args) :en-passant)
- (setq move (concat move "ep")))
- ((chess-ply-keyword (car args) :castle)
- (if (chess-pos-side-to-move (chess-ply-pos (car args)))
- (setq move "e1-g1")
- (setq move "e8-g8")))
- ((chess-ply-keyword (car args) :long-castle)
- (if (chess-pos-side-to-move (chess-ply-pos (car args)))
- (setq move "e1-c1")
- (setq move "e8-c8"))))
- (chess-engine-send nil (format "M%s\r\n" move))))))
+ ((eq event 'move)
+ (let ((move (chess-ply-to-algebraic (car args) t)))
+ (cond
+ ((chess-ply-keyword (car args) :en-passant)
+ (setq move (concat move "ep")))
+ ((chess-ply-keyword (car args) :castle)
+ (if (chess-pos-side-to-move (chess-ply-pos (car args)))
+ (setq move "e1-g1")
+ (setq move "e8-g8")))
+ ((chess-ply-keyword (car args) :long-castle)
+ (if (chess-pos-side-to-move (chess-ply-pos (car args)))
+ (setq move "e1-c1")
+ (setq move "e8-c8"))))
+ (chess-engine-send nil (format "M%s\r\n" move)))))))
(provide 'chess-ucb)