diff options
| -rw-r--r-- | chess-engine.el | 37 | ||||
| -rw-r--r-- | chess-network.el | 30 | ||||
| -rw-r--r-- | chess-transport.el | 4 |
3 files changed, 37 insertions, 34 deletions
diff --git a/chess-engine.el b/chess-engine.el index be1d3ab..4c6c259 100644 --- a/chess-engine.el +++ b/chess-engine.el @@ -15,7 +15,6 @@ (defvar chess-engine-regexp-alist nil) (defvar chess-engine-event-handler nil) (defvar chess-engine-response-handler nil) -(defvar chess-engine-internal-object nil) (defvar chess-engine-current-marker nil) (defvar chess-engine-position nil) (defvar chess-engine-game nil) @@ -23,7 +22,6 @@ (make-variable-buffer-local 'chess-engine-regexp-alist) (make-variable-buffer-local 'chess-engine-event-handler) (make-variable-buffer-local 'chess-engine-response-handler) -(make-variable-buffer-local 'chess-engine-internal-object) (make-variable-buffer-local 'chess-engine-current-marker) (make-variable-buffer-local 'chess-engine-position) (make-variable-buffer-local 'chess-engine-game) @@ -69,14 +67,13 @@ chess-engine-event-handler handler chess-engine-response-handler (or 'chess-engine-default-handler user-handler)) - (let ((object (funcall handler 'initialize))) - (when (processp object) - (unless (memq (process-status object) '(run open)) + (let ((proc (funcall handler 'initialize))) + (when (processp proc) + (unless (memq (process-status proc) '(run open)) (error "Failed to start chess engine process")) - (set-process-buffer object (current-buffer)) - (set-process-filter object 'chess-engine-filter)) - (setq chess-engine-current-marker (point-marker) - chess-engine-internal-object object)) + (set-process-buffer proc (current-buffer)) + (set-process-filter proc 'chess-engine-filter)) + (setq chess-engine-current-marker (point-marker))) (current-buffer)))) (defun chess-engine-destroy (engine) @@ -150,21 +147,21 @@ (defun chess-engine-send (engine string) "Send the given STRING to ENGINE." (chess-with-current-buffer engine - (let ((object chess-engine-internal-object)) - (if (and (processp object)) - (if (memq (process-status object) '(run open)) - (process-send-string object string) + (let ((proc (get-buffer-process (current-buffer)))) + (if proc + (if (memq (process-status proc) '(run open)) + (process-send-string proc string) (error "The engine you were using is no longer running")) (chess-engine-command nil 'send string))))) (defun chess-engine-submit (engine string) "Submit the given STRING, so ENGINE sees it in its input stream." (chess-with-current-buffer engine - (let ((object chess-engine-internal-object)) - (if (and (processp object) - (not (memq (process-status object) '(run open)))) + (let ((proc (get-buffer-process (current-buffer)))) + (if (and (processp proc) + (not (memq (process-status proc) '(run open)))) (error "The engine you were using is no longer running")) - (chess-engine-filter object string)))) + (chess-engine-filter nil string)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; @@ -186,10 +183,10 @@ ((eq event 'pass) (chess-engine-pass engine))))) -(defun chess-engine-filter (object string) +(defun chess-engine-filter (proc string) "Filter for receiving text for an engine from an outside source." - (let ((buf (if (processp object) - (process-buffer object) + (let ((buf (if (processp proc) + (process-buffer proc) (current-buffer)))) (when (buffer-live-p buf) (with-current-buffer buf diff --git a/chess-network.el b/chess-network.el index b2d9f01..aed1851 100644 --- a/chess-network.el +++ b/chess-network.el @@ -11,28 +11,28 @@ (defvar chess-network-now-moving nil) (defvar chess-network-regexp-alist - (list (cons (concat "\\(Black\\|White\\):\\s-*" - chess-algebraic-regexp "\\s-+") + (list (cons (concat "<move color=\"\\(black\\|white\\)\">" + chess-algebraic-regexp "</move>") 'chess-network-perform-move) - (cons "PASS" + (cons "<pass/>" (function (lambda () (message "Your opponent has passed the move to you")))) - (cons "CONNECT\\s-+\\(.*\\)" + (cons "<connect name=\"\\(.*\\)\"/>" (function (lambda () ;; jww (2002-04-07): Set the appropriate Black or ;; White tag at this point (message "Your opponent, %s, has connected" (match-string 1))))) - (cons "SETBOARD\\s-+\\(.*\\)" + (cons "<setup fen=\"\\(.*\\)\"/>" (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)))))) - (cons "QUIT" + (cons "<quit/>" (function (lambda () (message "Your opponent has quit playing")))))) @@ -41,7 +41,7 @@ (let ((position (chess-engine-position nil)) (move (match-string 2)) ply) (when (string= (if (chess-pos-side-to-move position) - "White" "Black") + "white" "black") (match-string 1)) (setq ply (chess-algebraic-to-ply position move)) (unless ply @@ -71,23 +71,25 @@ ((eq event 'shutdown) (ignore-errors - (chess-engine-send nil "QUIT\n"))) + (chess-engine-send nil "<quit/>\n"))) ((eq event 'setup) - (chess-engine-send nil (format "SETBOARD %s\n" + (chess-engine-send nil (format "<setup fen=\"%s\">\n" (chess-pos-to-fen (car args))))) ((eq event 'pass) - (chess-engine-send nil "PASS\n")) + (chess-engine-send nil "<pass/>\n")) ((eq event 'move) (unless chess-network-now-moving (chess-engine-send - nil (concat (if (chess-pos-side-to-move (chess-ply-pos (car args))) - "White:" - "Black:") + nil (concat "<move color=\"" + (if (chess-pos-side-to-move (chess-ply-pos (car args))) + "white" + "black") + "\">" (chess-ply-to-algebraic (car args)) - "\n")))))) + "</move>\n")))))) (provide 'chess-network) diff --git a/chess-transport.el b/chess-transport.el index dc5995d..8049e7c 100644 --- a/chess-transport.el +++ b/chess-transport.el @@ -5,6 +5,10 @@ ;; receive. This could be used for transmitting chess.el protocol ;; over CTCP, for example. ;; +;; NOTE: Make sure that any housekeeping data you use is kept in +;; buffer-local variables. Otherwise, multiple games played using the +;; same kind of transport might collide. +;; ;; $Revision$ (require 'chess-network) |
