1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; A module for connecting two engines. If one is a protocol
4 ;; transport (like chess-network), and the other is a computing engine
5 ;; (like chess-gnuchess), this will allow you to expose a bot over the
10 (require 'chess-engine)
12 (defun chess-link-response-handler (event &rest args)
13 "This function handles responses from the bot's computing engine."
15 (chess-game-data (chess-engine-game nil) 'first-engine))
17 (chess-game-data (chess-engine-game nil) 'second-engine))
21 (chess-engine-command nil 'accept)
25 (let ((chess-engine-inhibit-auto-pass t))
27 (apply 'chess-engine-default-handler event args)))
29 ;; but now transfer the event to the other engine
30 (apply 'chess-engine-command
31 (if (eq (current-buffer) first-engine)
33 first-engine) event args)
37 (defun chess-link-connect (first-engine second-engine)
38 "Connect two engines, so that they rely events back and forth."
39 (chess-engine-set-response-handler first-engine
40 'chess-link-response-handler)
41 (chess-engine-set-response-handler second-engine
42 'chess-link-response-handler))
45 (defun chess-link (first-engine-type second-engine-type)
46 "Play out a game between two engines, and watch the progress.
47 If you want to run an engine as a bot, make the transport the first
48 engine, and the computer the second engine."
49 (interactive "sFirst engine: \nsSecond engine: ")
50 (setq first-engine-type (intern (concat "chess-" first-engine-type))
51 second-engine-type (intern (concat "chess-" second-engine-type)))
52 (let* ((my-color t) ; we start out as white always
53 (display (chess-create-display my-color))
54 (game (chess-display-game display)))
55 (chess-game-set-data game 'my-color my-color)
56 (chess-module-set-leader display)
57 (chess-display-disable-popup display)
59 (when (and (require first-engine-type)
60 (require second-engine-type))
62 (chess-engine-create first-engine-type game))
64 (chess-engine-create second-engine-type game)))
66 (chess-game-set-data game 'first-engine first-engine)
67 (chess-engine-command first-engine 'ready)
69 (chess-game-set-data game 'second-engine second-engine)
70 (chess-link-connect first-engine second-engine)
71 (chess-engine-command second-engine 'ready)
73 ;; tell the first engine to start moving
74 (chess-engine-command first-engine 'pass))
76 (chess-display-update display)
77 (chess-display-popup display))
79 (chess-module-destroy display)
80 (error (error-message-string err))))))
84 ;;; chess-link.el ends here