X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/f4e9c77bc700222590ada4799c619152354244f2..6b8ac5acf330b03e88d0b342c79abbb7d338e0c2:/chess-crafty.el diff --git a/chess-crafty.el b/chess-crafty.el index 5418d3600..3b58f11f3 100644 --- a/chess-crafty.el +++ b/chess-crafty.el @@ -8,19 +8,23 @@ (require 'chess-fen) (require 'chess-algebraic) +(defgroup chess-crafty nil + "The publically available chess engine 'crafty'." + :group 'chess-engine) + +(defcustom chess-crafty-path (or (executable-find "crafty") + (executable-find "wcrafty")) + "The path to the crafty executable." + :type 'file + :group 'chess-crafty) + (defvar chess-crafty-regexp-alist - (list (cons - (concat "\\s-*\\(White\\|Black\\)\\s-*([0-9]+):\\s-+\\(" - chess-algebraic-regexp "\\)\\s-*$") - (function - (lambda () - (let ((position (chess-engine-position nil))) - (if (string= (if (chess-pos-side-to-move position) - "White" "Black") - (match-string 1)) - (funcall chess-engine-response-handler 'move - (chess-algebraic-to-ply position - (match-string 2)))))))) + (list (cons (concat "\\s-*\\(White\\|Black\\)\\s-*([0-9]+):\\s-+\\(" + chess-algebraic-regexp "\\)\\s-*$") + (function + (lambda () + (funcall chess-engine-response-handler 'move + (match-string 0))))) (cons "Illegal move:\\s-*\\(.*\\)" (function (lambda () @@ -31,9 +35,10 @@ ((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) - (or (executable-find "crafty") - (executable-find "wcrafty")))) + chess-crafty-path)) (message "Starting chess program 'crafty'...done") (process-send-string proc (concat "display nogeneral\n" "display nochanges\n" @@ -48,22 +53,21 @@ "alarm off\n" "ansi off\n")) proc)) + ((eq event 'shutdown) (chess-engine-send nil "quit\n")) + ((eq event 'setup) (chess-engine-send nil (format "setboard %s\n" (chess-pos-to-fen (car args))))) + ((eq event 'pass) (chess-engine-send nil "go\n")) + ((eq event 'move) - (cond - ((chess-engine-game nil) - (chess-game-move (chess-engine-game nil) (car args))) - (t - (apply 'chess-pos-move (car args)))) - (chess-engine-send nil (concat (chess-ply-to-algebraic - (car args) nil - (chess-engine-search-function nil)) + (chess-engine-send nil (concat (chess-ply-to-algebraic (car args)) "\n"))))) +(provide 'chess-crafty) + ;;; chess-crafty.el ends here