1 ;;; chess-ucb.el --- Engine interface to the Novag Universal Chess Board
3 ;; Copyright (C) 2002, 2014 Free Software Foundation, Inc.
5 ;; Author: John Wiegley <johnw@gnu.org>
6 ;; Maintainer: Mario Lang <mlang@delysid.org>
9 ;; This is free software; you can redistribute it and/or modify it under
10 ;; the terms of the GNU General Public License as published by the Free
11 ;; Software Foundation; either version 3, or (at your option) any later
14 ;; This is distributed in the hope that it will be useful, but WITHOUT
15 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; jww (2002-04-25): This code has not been tested yet, since I don't
25 ;; have access to a UCB. If anybody wants to donate one, or the money
26 ;; for one ($300), I would be happy to correct this module. :)
30 (require 'chess-common)
32 (defgroup chess-ucb nil
33 "Interface to the Novag Universal Chess Board."
36 (defcustom chess-ucb-device "/dev/ttyS0"
37 "The serial device used to talk to the Novag UCB."
41 (defvar chess-ucb-handling-event nil)
43 (defvar chess-ucb-regexp-alist
45 (cons "^M\\(..\\)\\(..\\)\\(/\\([QRNB]\\)\\)?\r\n"
48 (let ((move (concat (match-string 1)
51 (promote (match-string 4)))
53 (setq move (concat move "=" promote)))
54 (setq move (chess-engine-convert-algebraic move))
55 ;; I don't use the usual engine logic for this, since
56 ;; technically the UCB is just an input interface, not a
58 (let ((chess-ucb-handling-event t))
59 (chess-game-move (chess-engine-game nil) move))))))))
61 (defun chess-ucb-handler (game event &rest args)
62 (unless chess-ucb-handling-event
64 ((eq event 'initialize)
65 (when (file-exists-p chess-ucb-device)
66 ;; jww (2002-04-25): cat is not bidirectional, so I need
67 ;; something like "nc" that can talk with characters devices
69 (setq chess-engine-process
70 (start-process "*chess-ucb*" (current-buffer)
71 (executable-find "cat") chess-ucb-device))
75 (chess-engine-send nil "N\r\n")
76 (chess-engine-set-position nil)
78 ;; jww (2002-04-25): What happens if we're orienting to a
79 ;; non-standard starting position? How do we inform the UCB of
80 ;; the new position? If it doesn't test move legality, I
81 ;; suppose we could just move all the pieces around one by
83 (unless (eq chess-starting-position (chess-engine-position nil))
87 (dotimes (i (car args))
88 (chess-engine-send nil "T\r\n"))
89 ;; prevent us from handling the `undo' event which this triggers
90 (let ((chess-engine-handling-event t))
91 (chess-game-undo game (car args))))
94 (let ((move (chess-ply-to-algebraic (car args) t)))
96 ((chess-ply-keyword (car args) :en-passant)
97 (setq move (concat move "ep")))
98 ((chess-ply-keyword (car args) :castle)
99 (if (chess-pos-side-to-move (chess-ply-pos (car args)))
101 (setq move "e8-g8")))
102 ((chess-ply-keyword (car args) :long-castle)
103 (if (chess-pos-side-to-move (chess-ply-pos (car args)))
105 (setq move "e8-c8"))))
106 (chess-engine-send nil (format "M%s\r\n" move)))))))
110 ;;; chess-ucb.el ends here