blob: 7b902a43f6b3e376bbfd8605e5dc1c9fe0d1cdc6 (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Play against phalanx!
;;
;; $Revision$
(require 'chess-engine)
(require 'chess-fen)
(require 'chess-algebraic)
(defgroup chess-phalanx nil
"The publically available chess engine 'phalanx'."
:group 'chess-engine)
(defcustom chess-phalanx-path (executable-find "phalanx")
"The path to the phalanx executable."
:type 'file
:group 'chess-phalanx)
(defvar chess-phalanx-regexp-alist
(list
(cons (concat "my move is P?\\(" chess-algebraic-regexp "\\)\\s-*$")
(function
(lambda ()
(funcall chess-engine-response-handler 'move
(chess-engine-convert-algebraic (match-string 1))))))
(cons "Illegal move:\\s-*\\(.*\\)"
(function
(lambda ()
(signal 'chess-illegal (match-string 1)))))))
(defun chess-phalanx-handler (event &rest args)
(cond
((eq event 'initialize)
(let (proc)
(message "Starting chess program 'phalanx'...")
(unless chess-phalanx-path
(error "Cannot find phalanx executable; check `chess-phalanx-path'"))
(setq proc (start-process "chess-process" (current-buffer)
chess-phalanx-path))
(message "Starting chess program 'phalanx'...done")
(process-send-string proc "nopost\n")
proc))
((eq event 'shutdown)
(chess-engine-send nil "quit\n"))
((eq event 'ready)
(and (chess-engine-game nil)
(chess-game-set-data (chess-engine-game nil) 'active t)))
((eq event 'pass)
(chess-engine-send nil "go\n"))
((memq event '(abort resign))
(chess-engine-send nil "new\n")
(and (chess-engine-game nil)
(chess-engine-set-start-position nil)))
((eq event 'move)
(chess-engine-send nil (concat (chess-ply-to-algebraic (car args))
"\n")))))
(provide 'chess-phalanx)
;;; chess-phalanx.el ends here
|