diff options
| author | John Wiegley <johnw@newartisans.com> | 2002-04-25 22:15:08 +0000 |
|---|---|---|
| committer | John Wiegley <johnw@newartisans.com> | 2002-04-25 22:15:08 +0000 |
| commit | 599cd3f6e4e44c5a8e2cf527d1ae72b33e9a8511 (patch) | |
| tree | cc7b667bba7687bdf793eefebbb82db81a6266dc | |
| parent | 0fe55d3c807d535fab83a23fd00eea1e4708e25e (diff) | |
*** no comment ***
| -rw-r--r-- | chess-common.el | 4 | ||||
| -rw-r--r-- | chess-ucb.el | 84 |
2 files changed, 86 insertions, 2 deletions
diff --git a/chess-common.el b/chess-common.el index faef364..7f32eb4 100644 --- a/chess-common.el +++ b/chess-common.el @@ -67,7 +67,7 @@ ((eq event 'drawn) (chess-game-set-data game 'active nil)) - ((memq event '(resign abort)) + ((memq event '(resign abort new)) (chess-engine-send nil "new\n") (chess-engine-set-position nil)) @@ -77,7 +77,7 @@ (if (= 1 (mod (car args) 2)) (chess-engine-send nil "go\n")) - ;; prevent use from handling the `undo' event which this triggers + ;; prevent us from handling the `undo' event which this triggers (let ((chess-engine-handling-event t)) (chess-game-undo game (car args)))) diff --git a/chess-ucb.el b/chess-ucb.el new file mode 100644 index 0000000..7d35152 --- /dev/null +++ b/chess-ucb.el @@ -0,0 +1,84 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Engine interface to the Novag Universal Chess Board +;; +;; jww (2002-04-25): This code has not been tested yet, since I don't +;; have access to a UCB. If anybody wants to donate one, or the money +;; for one ($300), I would be happy to correct this module. :) +;; + +(require 'chess-common) + +(defgroup chess-ucb nil + "Interface to the Novag Universal Chess Board." + :group 'chess-engine) + +(defcustom chess-ucb-device "/dev/ttyS0" + "The serial device used to talk to the Novag UCB." + :type 'file + :group 'chess-ucb) + +(defvar chess-ucb-regexp-alist + (list + (cons "^M\\(..\\)\\(..\\)\\(/\\([QRNB]\\)\\)?\r\n" + (function + (lambda () + (let ((move (concat (match-string 1) + "-" + (match-string 2))) + (promote (match-string 4))) + (if promote + (setq move (concat move "=" promote))) + ;; 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)))))))) + +(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)) + + ((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)) + + ((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)))))) + +(provide 'chess-ucb) + +;;; chess-ucb.el ends here |
