]> code.delx.au - gnu-emacs-elpa/blob - chess-gnuchess.el
Gnuchess can be played against (up until a pawn take occurs).
[gnu-emacs-elpa] / chess-gnuchess.el
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;
3 ;; Play against gnuchess!
4 ;;
5 ;; $Revision$
6
7 (require 'chess-engine)
8 (require 'chess-fen)
9 (require 'chess-algebraic)
10
11 (defvar chess-gnuchess-regexp-alist
12 (list (cons (concat "My move is : \\(" chess-algebraic-regexp "\\)")
13 (function
14 (lambda ()
15 (funcall chess-engine-response-handler 'move
16 (chess-algebraic-to-ply (chess-engine-position nil)
17 (match-string 1))))))
18 (cons "Illegal move:"
19 (function
20 (lambda ()
21 (signal 'chess-illegal "Illegal move"))))))
22
23 (defun chess-gnuchess-handler (event &rest args)
24 (cond
25 ((eq event 'initialize)
26 (let (proc)
27 (message "Starting chess program 'gnuchess'...")
28 (setq proc (start-process "chess-process" (current-buffer)
29 (executable-find "gnuchess")))
30 (message "Starting chess program 'gnuchess'...done")
31 proc))
32 ((eq event 'shutdown)
33 (chess-engine-send nil "quit\n"))
34 ((eq event 'setup)
35 (chess-engine-send nil (format "setboard %s\n"
36 (chess-pos-to-fen (car args)))))
37 ((eq event 'pass)
38 (chess-engine-send nil "go\n"))
39 ((eq event 'move)
40 (chess-engine-send
41 nil (concat (chess-ply-to-algebraic
42 (car args) nil
43 (chess-engine-search-function nil)) "\n")))))
44
45 (provide 'chess-gnuchess)
46
47 ;;; chess-gnuchess.el ends here