]> code.delx.au - gnu-emacs-elpa/blob - chess-phalanx.el
more fixes to draw support
[gnu-emacs-elpa] / chess-phalanx.el
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;
3 ;; Play against phalanx!
4 ;;
5 ;; $Revision$
6
7 (require 'chess-engine)
8 (require 'chess-fen)
9 (require 'chess-algebraic)
10
11 (defgroup chess-phalanx nil
12 "The publically available chess engine 'phalanx'."
13 :group 'chess-engine)
14
15 (defcustom chess-phalanx-path (executable-find "phalanx")
16 "The path to the phalanx executable."
17 :type 'file
18 :group 'chess-phalanx)
19
20 (defvar chess-phalanx-regexp-alist
21 (list
22 (cons (concat "my move is P?\\(" chess-algebraic-regexp "\\)\\s-*$")
23 (function
24 (lambda ()
25 (funcall chess-engine-response-handler 'move
26 (chess-engine-convert-algebraic (match-string 1))))))
27 (cons "Illegal move:\\s-*\\(.*\\)"
28 (function
29 (lambda ()
30 (signal 'chess-illegal (match-string 1)))))))
31
32 (defun chess-phalanx-handler (event &rest args)
33 (cond
34 ((eq event 'initialize)
35 (let (proc)
36 (message "Starting chess program 'phalanx'...")
37 (unless chess-phalanx-path
38 (error "Cannot find phalanx executable; check `chess-phalanx-path'"))
39 (setq proc (start-process "chess-process" (current-buffer)
40 chess-phalanx-path))
41 (message "Starting chess program 'phalanx'...done")
42 (process-send-string proc "nopost\n")
43 proc))
44
45 ((eq event 'shutdown)
46 (chess-engine-send nil "quit\n"))
47
48 ((eq event 'ready)
49 (and (chess-engine-game nil)
50 (chess-game-set-data (chess-engine-game nil) 'active t)))
51
52 ((eq event 'pass)
53 (chess-engine-send nil "go\n"))
54
55 ((memq event '(abort resign))
56 (chess-engine-send nil "new\n")
57 (and (chess-engine-game nil)
58 (chess-engine-set-start-position nil)))
59
60 ((eq event 'draw)
61 (chess-engine-default-handler 'decline-draw))
62
63 ((eq event 'undo)
64 (when (chess-engine-game nil)
65 (dotimes (i (car args))
66 (chess-engine-send nil "undo\n"))
67 (chess-game-undo (chess-engine-game nil) (car args))))
68
69 ((eq event 'move)
70 (chess-engine-send nil (concat (chess-ply-to-algebraic (car args))
71 "\n")))))
72
73 (provide 'chess-phalanx)
74
75 ;;; chess-phalanx.el ends here