1 ;;; chess-stockfish.el --- Play against stockfish!
3 ;; Copyright (C) 2014 Free Software Foundation, Inc.
5 ;; Author: Mario Lang <mlang@delysid.org>
6 ;; Keywords: games, processes
8 ;; This program 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 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program 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.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
25 (defgroup chess-stockfish nil
26 "The publically available chess engine 'stockfish'."
28 :link '(url-link "http://www.stockfishchess.com"))
30 (defcustom chess-stockfish-path (executable-find "stockfish")
31 "*The path to the stockfish executable."
33 :group 'chess-stockfish)
35 (defvar chess-stockfish-regexp-alist
37 chess-uci-regexp-alist
39 (cons (concat "^info\\s-+.*nps\\s-+\\([0-9]+\\).*pv\\s-+\\("
40 chess-uci-long-algebraic-regexp
41 "\\(\\s-+" chess-uci-long-algebraic-regexp "\\)+\\)")
44 (setq-local chess-stockfish-nps (string-to-number (match-string 1)))
45 (setq-local chess-stockfish-pv
46 (split-string (match-string 2) " ")))))))
47 "Patterns used to match stockfish output.")
49 (defun chess-stockfish-handler (game event &rest args)
50 (unless chess-engine-handling-event
52 ((eq event 'initialize)
53 (let ((proc (chess-uci-handler game 'initialize "stockfish")))
54 (when (and proc (processp proc) (eq (process-status proc) 'run))
55 (process-send-string proc "uci\n")
56 (setq chess-engine-process proc)
60 (if (and (eq event 'undo)
61 (= 1 (mod (car args) 2)))
62 (error "Cannot undo until after stockfish moves"))
64 (apply 'chess-uci-handler game event args)))))
66 (provide 'chess-stockfish)
68 ;;; chess-stockfish.el ends here