1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; Play against an opponent over the network
7 (require 'chess-engine)
9 (require 'chess-algebraic)
11 (defvar chess-network-regexp-alist
12 (list (cons (concat chess-algebraic-regexp "$")
15 (funcall chess-engine-response-handler 'move
20 (funcall chess-engine-response-handler 'pass))))
21 (cons "name\\s-+\\(.+\\)"
24 (funcall chess-engine-response-handler 'connect
26 (cons "fen\\s-+\\(.+\\)"
29 (funcall chess-engine-response-handler 'setup
34 (funcall chess-engine-response-handler 'quit))))
38 (funcall chess-engine-response-handler 'resign))))))
40 (defun chess-network-handler (event &rest args)
41 "Initialize the network chess engine."
43 ((eq event 'initialize)
44 (let ((which (read-char "Are you the c)lient or s)erver? "))
46 (message "Starting network client/server...")
47 (setq proc (if (eq which ?s)
48 (start-process "*chess-network*"
49 (current-buffer) "/usr/bin/nc"
50 "-l" "-p" (read-string "Port: "))
51 (open-network-stream "*chess-network*" (current-buffer)
52 (read-string "Host: ")
53 (read-string "Port: "))))
55 (message "Now waiting for your opponent to connect...")
56 (process-send-string proc (format "name %s\n" (user-full-name)))
57 (message "You have connected; pass now or make your move."))
62 (chess-engine-send nil "quit\n")))
65 (chess-engine-send nil (format "fen %s\n"
66 (chess-pos-to-fen (car args)))))
69 (chess-engine-send nil "pass\n"))
72 (chess-engine-send nil "resign\n"))
75 (chess-engine-send nil (concat (chess-ply-to-algebraic (car args))
78 (provide 'chess-network)
80 ;;; chess-network.el ends here