summaryrefslogtreecommitdiff
path: root/chess-stockfish.el
diff options
context:
space:
mode:
authorMario Lang <mlang@delysid.org>2014-03-24 01:58:43 +0100
committerMario Lang <mlang@delysid.org>2014-03-24 01:58:43 +0100
commit1c1607589eadf378812f1dbfd18b2826cf921db0 (patch)
treed567d220af14740e596114378ce36c22a79ec61a /chess-stockfish.el
parent69b3e6329652da55900ca40f5e72f12138c6330e (diff)
(incomplete) support for the stockfish engine.
Diffstat (limited to 'chess-stockfish.el')
-rw-r--r--chess-stockfish.el69
1 files changed, 69 insertions, 0 deletions
diff --git a/chess-stockfish.el b/chess-stockfish.el
new file mode 100644
index 0000000..f01c75b
--- /dev/null
+++ b/chess-stockfish.el
@@ -0,0 +1,69 @@
+;;; chess-stockfish.el --- Play against stockfish!
+
+;; Copyright (C) 2014 Free Software Foundation, Inc.
+
+;; Author: Mario Lang <mlang@delysid.org>
+;; Keywords: games
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; This file is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Code:
+
+(require 'chess-uci)
+
+(defgroup chess-stockfish nil
+ "The publically available chess engine 'stockfish'."
+ :group 'chess-engine
+ :link '(url-link "http://www.stockfishchess.com"))
+
+(defcustom chess-stockfish-path (executable-find "stockfish")
+ "*The path to the stockfish executable."
+ :type 'file
+ :group 'chess-stockfish)
+
+(defvar chess-stockfish-regexp-alist
+ (list
+ (cons (concat "^bestmove\\s-+\\(" chess-algebraic-regexp "\\)")
+ (function
+ (lambda ()
+ (message "move")
+ (funcall chess-engine-response-handler 'move
+ (chess-engine-convert-algebraic (match-string 1) t)))))
+ (cons "^id\\s-+name\\s-+\\(.+\\)$"
+ (function
+ (lambda ()
+ (setq-local chess-engine-opponent-name (match-string 1)))))))
+
+(defun chess-stockfish-handler (game event &rest args)
+ (unless chess-engine-handling-event
+ (cond
+ ((eq event 'initialize)
+ (let ((proc (chess-uci-handler game 'initialize "stockfish")))
+ (when (and proc (processp proc) (eq (process-status proc) 'run))
+ (process-send-string proc "uci\n")
+ (setq chess-engine-process proc)
+ t)))
+
+ (t
+ (if (and (eq event 'undo)
+ (= 1 (mod (car args) 2)))
+ (error "Cannot undo until after stockfish moves"))
+
+ (apply 'chess-uci-handler game event args)))))
+
+(provide 'chess-stockfish)
+
+;;; chess-stockfish.el ends here