diff options
| author | John Wiegley <johnw@newartisans.com> | 2002-04-11 07:57:23 +0000 |
|---|---|---|
| committer | John Wiegley <johnw@newartisans.com> | 2002-04-11 07:57:23 +0000 |
| commit | 232756b32dab6030f711b197851c9e4b9540994d (patch) | |
| tree | 083154a439a14c554f9ddfdeb3cecee9a3358dba /chess-crafty.el | |
| parent | 4bf636091a501c662213c8bc80242d2f65e97f09 (diff) | |
*** no comment ***
Diffstat (limited to 'chess-crafty.el')
| -rw-r--r-- | chess-crafty.el | 56 |
1 files changed, 8 insertions, 48 deletions
diff --git a/chess-crafty.el b/chess-crafty.el index 884e372..6e0d733 100644 --- a/chess-crafty.el +++ b/chess-crafty.el @@ -5,8 +5,7 @@ ;; $Revision$ (require 'chess-engine) -(require 'chess-fen) -(require 'chess-algebraic) +(require 'chess-common) (defgroup chess-crafty nil "The publically available chess engine 'crafty'." @@ -18,9 +17,6 @@ :type 'file :group 'chess-crafty) -(defvar chess-crafty-temp-files nil) -(make-variable-buffer-local 'chess-crafty-temp-files) - (defvar chess-crafty-regexp-alist (list (cons (concat "\\(White\\|Black\\)\\s-*([0-9]+):\\s-+\\(" @@ -37,13 +33,7 @@ (defun chess-crafty-handler (event &rest args) (cond ((eq event 'initialize) - (let (proc) - (message "Starting chess program 'crafty'...") - (unless chess-crafty-path - (error "Cannot find crafty executable; check `chess-crafty-path'")) - (setq proc (start-process "chess-process" (current-buffer) - chess-crafty-path)) - (message "Starting chess program 'crafty'...done") + (let ((proc (chess-common-handler 'initialize "crafty"))) (process-send-string proc (concat "display nogeneral\n" "display nochanges\n" "display noextstats\n" @@ -58,47 +48,17 @@ "ansi off\n")) proc)) - ((eq event 'shutdown) - (chess-engine-send nil "quit\n") - (dolist (file chess-crafty-temp-files) - (if (file-exists-p file) - (delete-file file)))) - - ((eq event 'ready) - (and (chess-engine-game nil) - (chess-game-set-data (chess-engine-game nil) 'active t))) - ((eq event 'setup-pos) (chess-engine-send nil (format "setboard %s\n" - (chess-pos-to-fen (car args))))) + (chess-pos-to-string (car args))))) ((eq event 'setup-game) - (let ((file (make-temp-file "cra"))) - (with-temp-file file - (insert (chess-game-to-string (car args)) ?\n)) - (chess-engine-send nil (format "read %s\n" file)) - (push file chess-crafty-temp-files))) - - ((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 'draw) - (chess-engine-default-handler 'decline-draw)) - - ((eq event 'undo) - (when (chess-engine-game nil) - (dotimes (i (car args)) - (chess-engine-send nil "undo\n")) - (chess-game-undo (chess-engine-game nil) (car args)))) + (let ((file (chess-with-temp-file + (insert (chess-game-to-string (car args)) ?\n)))) + (chess-engine-send nil (format "read %s\n" file)))) - ((eq event 'move) - (chess-engine-send nil (concat (chess-ply-to-algebraic (car args)) - "\n"))))) + (t + (apply 'chess-common-handler event args)))) (provide 'chess-crafty) |
