]> code.delx.au - gnu-emacs-elpa/blobdiff - chess-phalanx.el
*** no comment ***
[gnu-emacs-elpa] / chess-phalanx.el
index 7b902a43f6b3e376bbfd8605e5dc1c9fe0d1cdc6..846946ea429b3348988c7e911252e1824e141de9 100644 (file)
@@ -5,8 +5,7 @@
 ;; $Revision$
 
 (require 'chess-engine)
-(require 'chess-fen)
-(require 'chess-algebraic)
+(require 'chess-common)
 
 (defgroup chess-phalanx nil
   "The publically available chess engine 'phalanx'."
         (function
          (lambda ()
            (funcall chess-engine-response-handler 'move
-                    (chess-engine-convert-algebraic (match-string 1))))))
+                    (chess-engine-convert-algebraic (match-string 1) t)))))
    (cons "Illegal move:\\s-*\\(.*\\)"
         (function
          (lambda ()
-           (signal 'chess-illegal (match-string 1)))))))
-
-(defun chess-phalanx-handler (event &rest args)
-  (cond
-   ((eq event 'initialize)
-    (let (proc)
-      (message "Starting chess program 'phalanx'...")
-      (unless chess-phalanx-path
-       (error "Cannot find phalanx executable; check `chess-phalanx-path'"))
-      (setq proc (start-process "chess-process" (current-buffer)
-                               chess-phalanx-path))
-      (message "Starting chess program 'phalanx'...done")
-      (process-send-string proc "nopost\n")
-      proc))
-
-   ((eq event 'shutdown)
-    (chess-engine-send nil "quit\n"))
-
-   ((eq event 'ready)
-    (and (chess-engine-game nil)
-        (chess-game-set-data (chess-engine-game nil) 'active t)))
-
-   ((eq event 'pass)
-    (chess-engine-send nil "go\n"))
-
-   ((memq event '(abort resign))
-    (chess-engine-send nil "new\n")
-    (and (chess-engine-game nil)
-        (chess-engine-set-start-position nil)))
-
-   ((eq event 'move)
-    (chess-engine-send nil (concat (chess-ply-to-algebraic (car args))
-                                  "\n")))))
+           (error (match-string 1)))))))
+
+(defun chess-phalanx-handler (game event &rest args)
+  (unless chess-engine-handling-event
+    (cond
+     ((eq event 'initialize)
+      (let ((proc (chess-common-handler game 'initialize "phalanx")))
+       (when (and (processp proc)
+                  (eq (process-status proc) 'run))
+         (process-send-string proc "nopost\n")
+         t)))
+
+     (t
+      (apply 'chess-common-handler game event args)))))
 
 (provide 'chess-phalanx)