]> code.delx.au - gnu-emacs-elpa/blob - packages/chess/chess-fruit.el
Initial import of chess.el.
[gnu-emacs-elpa] / packages / chess / chess-fruit.el
1 ;;; chess-fruit.el --- Play against fruit!
2
3 ;; Copyright (C) 2014 Free Software Foundation, Inc.
4
5 ;; Author: Mario Lang <mlang@delysid.org>
6 ;; Keywords: games
7
8 ;; This file is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
12
13 ;; This file is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
22
23 ;;; Code:
24
25 (require 'chess-uci)
26
27 (defgroup chess-fruit nil
28 "The publically available chess engine 'fruit'."
29 :group 'chess-engine
30 :link '(url-link "http://www.fruitchess.com/"))
31
32 (defcustom chess-fruit-path (executable-find "fruit")
33 "*The path to the fruit executable."
34 :type 'file
35 :group 'chess-fruit)
36
37 (defvar chess-fruit-regexp-alist chess-uci-regexp-alist
38 "Patterns used to match engine output.")
39
40 (defun chess-fruit-handler (game event &rest args)
41 (unless chess-engine-handling-event
42 (cond
43 ((eq event 'initialize)
44 (let ((proc (chess-uci-handler game 'initialize "fruit")))
45 (when (and proc (processp proc) (eq (process-status proc) 'run))
46 (process-send-string proc "uci\n")
47 (setq chess-engine-process proc)
48 t)))
49
50 (t
51 (if (and (eq event 'undo)
52 (= 1 (mod (car args) 2)))
53 (error "Cannot undo until after fruit moves"))
54
55 (apply 'chess-uci-handler game event args)))))
56
57 (provide 'chess-fruit)
58
59 ;;; chess-fruit.el ends here