diff options
| author | Mario Lang <mlang@delysid.org> | 2014-03-25 21:51:47 +0100 |
|---|---|---|
| committer | Mario Lang <mlang@delysid.org> | 2014-03-25 21:51:47 +0100 |
| commit | 1b21391aa8e4a8df1c1e1b81a3f8cf0376fb3799 (patch) | |
| tree | 07af2da8fe0680a8b0a0412db7009b5fef7be891 | |
| parent | c13af40e27c350e18343da079ab2cb8781d96d9b (diff) | |
Optionally allow UCI engines to query a book provided by polyglot.
| -rw-r--r-- | chess-uci.el | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/chess-uci.el b/chess-uci.el index 6795f57..2413cd8 100644 --- a/chess-uci.el +++ b/chess-uci.el @@ -27,6 +27,20 @@ ;;; Code: (require 'chess-common) +(require 'chess-polyglot) + +(defgroup chess-uci nil + "Customisations for Chess engines based on the UCI protocol" + :group 'chess) + +(defcustom chess-uci-polyglot-book-file nil + "The path to a polyglot binary opening book file." + :group 'chess-uci + :type '(choice (const :tag "Not specified" nil) file)) + +(defvar chess-uci-book nil + "A (polyglot) opening book object. +See `chess-uci-polyglot-book-file' for details on how to enable this.") (defvar chess-uci-long-algebraic-regexp "\\([a-h][1-8]\\)\\([a-h][1-8]\\)\\([nbrq]\\)?" "A regular expression matching a UCI log algebraic move.") @@ -93,12 +107,27 @@ If conversion fails, this function fired an 'illegal event." "Default handler for UCI based engines." (unless chess-engine-handling-event (cond + ((eq event 'initialize) + (when chess-uci-polyglot-book-file + (unless chess-uci-book + (setq chess-uci-book (chess-polyglot-book-open + chess-uci-polyglot-book-file)))) + (apply #'chess-common-handler game event args)) + ((eq event 'move) (when (= 1 (chess-game-index game)) (chess-game-set-tag game "White" chess-full-name) (chess-game-set-tag game "Black" chess-engine-opponent-name)) - (chess-engine-send nil (concat (chess-uci-position game) "go\n")) + (let ((book-plies (and chess-uci-book (bufferp chess-uci-book) + (buffer-live-p chess-uci-book) + (chess-polyglot-book-plies chess-uci-book + (chess-game-pos game))))) + (if book-plies + (let ((chess-display-handling-event nil)) + (funcall chess-engine-response-handler 'move (car book-plies))) + (chess-engine-send nil (concat (chess-uci-position game) "go\n")))) + (if (chess-game-over-p game) (chess-game-set-data game 'active nil))) |
