summaryrefslogtreecommitdiff
path: root/chess-gnuchess.el
blob: 09fe89e70703e225c00fbc48a032d880b2fbf927 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Play against gnuchess!
;;
;; $Revision$

(require 'chess-engine)
(require 'chess-fen)
(require 'chess-algebraic)

(defvar chess-gnuchess-regexp-alist
  (list (cons (concat "My move is : \\(" chess-algebraic-regexp "\\)")
	      (function
	       (lambda ()
		 (funcall chess-engine-response-handler 'move
			  (chess-algebraic-to-ply (chess-engine-position nil)
						  (match-string 1))))))
	(cons "Illegal move:"
	      (function
	       (lambda ()
		 (signal 'chess-illegal "Illegal move"))))))

(defun chess-gnuchess-handler (event &rest args)
  (cond
   ((eq event 'initialize)
    (let (proc)
      (message "Starting chess program 'gnuchess'...")
      (setq proc (start-process "chess-process" (current-buffer)
				(executable-find "gnuchess")))
      (message "Starting chess program 'gnuchess'...done")
      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)
    (chess-engine-send
     nil (concat (chess-ply-to-algebraic
		  (car args) nil
		  (chess-engine-search-function nil)) "\n")))))

(provide 'chess-gnuchess)

;;; chess-gnuchess.el ends here