1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; Play against crafty!
7 (require 'chess-engine)
9 (require 'chess-algebraic)
11 (defvar chess-crafty-now-moving nil)
13 (defvar chess-crafty-regexp-alist
15 (concat "\\s-*\\(White\\|Black\\)\\s-*([0-9]+):\\s-+\\("
16 chess-algebraic-regexp "\\)\\s-*$")
17 'chess-crafty-perform-move)
18 (cons "Illegal move:\\s-*\\(.*\\)"
21 (signal 'chess-illegal (match-string 1)))))))
23 (defun chess-crafty-perform-move ()
24 (let ((position (chess-engine-position nil))
25 (move (match-string 2)) ply)
26 (when (string= (if (chess-pos-side-to-move position)
29 (setq ply (chess-algebraic-to-ply position move))
31 (error "Could not convert engine move: %s" move))
32 (let ((chess-crafty-now-moving t))
33 (funcall chess-engine-response-handler 'move ply)))))
35 (defun chess-crafty-handler (event &rest args)
37 ((eq event 'initialize)
39 (message "Starting chess program 'crafty'...")
40 (setq proc (start-process "chess-process" (current-buffer)
41 (or (executable-find "crafty")
42 (executable-find "wcrafty"))))
43 (message "Starting chess program 'crafty'...done")
44 (process-send-string proc (concat "display nogeneral\n"
46 "display noextstats\n"
47 "display nohashstats\n"
53 "display novariation\n"
59 (chess-engine-send nil "quit\n"))
62 (chess-engine-send nil (format "setboard %s\n"
63 (chess-pos-to-fen (car args)))))
66 (chess-engine-send nil "go\n"))
69 (unless chess-crafty-now-moving
70 (chess-engine-send nil (concat (chess-ply-to-algebraic (car args))
73 (provide 'chess-crafty)
75 ;;; chess-crafty.el ends here