diff options
| author | Mario Lang <mlang@delysid.org> | 2004-01-10 19:12:19 +0000 |
|---|---|---|
| committer | Mario Lang <mlang@delysid.org> | 2004-01-10 19:12:19 +0000 |
| commit | 13ae76922f913e7dbbe93687465ebe698d0d37f0 (patch) | |
| tree | cf47986b690ef842aafb4cb4e7526714c78e9f78 /chess-crafty.el | |
| parent | 2a6a2ad60df7af86a164349545a80bb45ae0079f (diff) | |
Support for xboards analyze mode.
(chess-engine-command crafty 'analyze t) enables analyze mode and
eventually sets chess-crafty-analyzing-p to t.
When new predicted variations arrive, corresponding epd opcodes
are set for (chess-engine-position nil): acd, ce, pv (acn is not set because
it is likely that it overflows the emacs integer bounds, and I am not
yet sure what to do about this.)
(chess-engine-command crafty 'analyze nil) turns analyze mode off again.
Diffstat (limited to 'chess-crafty.el')
| -rw-r--r-- | chess-crafty.el | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/chess-crafty.el b/chess-crafty.el index b6b0dac..936627b 100644 --- a/chess-crafty.el +++ b/chess-crafty.el @@ -19,10 +19,14 @@ (make-variable-buffer-local 'chess-crafty-evaluation) +(defvar chess-crafty-analyzing-p nil + "Non-nil if Crafty is currently in analysis mode.") + +(make-variable-buffer-local 'chess-crafty-analyzing-p) + (defvar chess-crafty-regexp-alist (list - (cons (concat "move\\s-+\\(" - chess-algebraic-regexp "\\)\\s-*$") + (cons (concat "move\\s-+\\(" chess-algebraic-regexp "\\)\\s-*$") (function (lambda () (funcall chess-engine-response-handler 'move @@ -36,6 +40,51 @@ (function (lambda () (setq chess-engine-opponent-name (match-string 1))))) + (cons "Analyze Mode: type \"exit\" to terminate.$" + (function + (lambda () + (setq chess-crafty-analyzing-p t)))) + (cons (concat "\t ?\\([0-9]+\\)\\s-+" + "\\(-?[0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+" + "\\(" ;; The list of moves + "\\( *[1-9][0-9]*\\. " + "\\(\\.\\.\\.\\|" chess-algebraic-regexp "\\)" + "\\( " chess-algebraic-regexp "\\)?\\)+\\)$") + (function + (lambda () + (when chess-crafty-analyzing-p + ;; We can translate this information to EPD opcodes + (let ((depth (read (match-string 1))) + (centipawn (read (match-string 2))) + (nodes (match-string 4)) + (pos (chess-engine-position nil))) + (chess-pos-set-epd pos 'acd depth) + (chess-pos-set-epd pos 'ce centipawn) + (chess-pos-set-epd + pos + 'pv ; predicted variation + (save-restriction + (narrow-to-region (match-beginning 5) (match-end 5)) + (let ((var (chess-var-create pos))) + (goto-char (point-min)) + (while (not (eobp)) + (cond + ((looking-at "[1-9][0-9]*\\.[ .]*") + (goto-char (match-end 0))) + ((looking-at chess-algebraic-regexp) + (goto-char (match-end 0)) + (let ((ply (chess-algebraic-to-ply + (chess-var-pos var) + (match-string-no-properties 0)))) + (unless ply + (error "unable to read move '%s'" move)) + (chess-var-move var ply)))) + (skip-chars-forward " ")) + var)))))))) + (cons "analyze complete.$" + (function + (lambda () + (setq chess-crafty-analyzing-p nil)))) (cons "{\\(Black\\|White\\) resigns}" (function (lambda () @@ -56,7 +105,7 @@ (let ((proc (chess-common-handler game 'initialize "crafty"))) (when (and proc (processp proc) (eq (process-status proc) 'run)) - (process-send-string proc (concat "xboard\n")) + (process-send-string proc "xboard\n") (setq chess-engine-process proc) t))) @@ -73,6 +122,11 @@ (sit-for 0 100 t)) chess-crafty-evaluation)) + ((eq event 'analyze) + (if (car args) + (chess-engine-send nil "analyze\npost\n") + (chess-engine-send nil "exit\nnopost\n"))) + ((eq event 'setup-game) (let ((file (chess-with-temp-file (insert (chess-game-to-string (car args)) ?\n)))) |
