summaryrefslogtreecommitdiff
path: root/chess-ai.el
diff options
context:
space:
mode:
authorMario Lang <mlang@delysid.org>2014-06-04 22:43:13 +0200
committerMario Lang <mlang@delysid.org>2014-06-04 22:43:13 +0200
commitd3bd3c6f07e0c9a2a7a1488e43b47439a5f8ac54 (patch)
tree6880ccc0d0694bd1af272c90108d68d95b58791e /chess-ai.el
parent4f6e6e7cac21f21586b221e2a65e657a4c2a7213 (diff)
Sync from ELPA.
Diffstat (limited to 'chess-ai.el')
-rw-r--r--chess-ai.el95
1 files changed, 47 insertions, 48 deletions
diff --git a/chess-ai.el b/chess-ai.el
index bc6f400..b0a0bcf 100644
--- a/chess-ai.el
+++ b/chess-ai.el
@@ -250,54 +250,53 @@ for all leave nodes of the resulting tree.
A `cons' cell is returned where `cdr' is the supposedly best move from POSITION
and `car' is the score of that move. If there is no legal move from POSITION
\(or DEPTH is 0), `cdr' will be nil."
- (let ((chess-ply-allow-interactive-query nil))
- (if (zerop depth)
- (cons (funcall eval-fn position) nil)
- (let ((plies (let ((chess-ai-mobility nil)
- (chess-ai-quiescence nil))
- (sort
- (mapcar
- (lambda (ply)
- (chess-ply-set-keyword
- ply :score
- (- (chess-ai-search (chess-ply-next-pos ply)
- 1
- (1+ most-negative-fixnum)
- most-positive-fixnum
- #'chess-ai-eval-static)))
- ply)
- (chess-legal-plies
- position :color (chess-pos-side-to-move position)))
- (lambda (lhs rhs)
- (> (chess-ply-keyword lhs :score)
- (chess-ply-keyword rhs :score)))))))
- (if (null plies)
- (cons (funcall eval-fn position) nil)
- (let* ((best-ply (car plies))
- (progress (make-progress-reporter
- (format "Thinking... (%s) "
- (chess-ply-to-algebraic best-ply))
- 0 (length plies))))
- (cl-loop for i from 1
- for ply in plies
- do (let ((value (- (chess-ai-search
- (chess-ply-next-pos ply)
- (1- depth) (- upper-bound) (- lower-bound)
- eval-fn))))
- (progress-reporter-update progress i)
- (accept-process-output nil 0.05)
- (when (> value lower-bound)
- (setq lower-bound value
- best-ply ply)
- (progress-reporter-force-update
- progress
- i
- (format "Thinking... (%s {cp=%d}) "
- (chess-ply-to-algebraic best-ply)
- lower-bound))))
- until (>= lower-bound upper-bound))
- (progress-reporter-done progress)
- (cons lower-bound best-ply)))))))
+ (if (zerop depth)
+ (cons (funcall eval-fn position) nil)
+ (let ((plies (let ((chess-ai-mobility nil)
+ (chess-ai-quiescence nil))
+ (sort
+ (mapcar
+ (lambda (ply)
+ (chess-ply-set-keyword
+ ply :score
+ (- (chess-ai-search (chess-ply-next-pos ply)
+ 1
+ (1+ most-negative-fixnum)
+ most-positive-fixnum
+ #'chess-ai-eval-static)))
+ ply)
+ (chess-legal-plies
+ position :color (chess-pos-side-to-move position)))
+ (lambda (lhs rhs)
+ (> (chess-ply-keyword lhs :score)
+ (chess-ply-keyword rhs :score)))))))
+ (if (null plies)
+ (cons (funcall eval-fn position) nil)
+ (let* ((best-ply (car plies))
+ (progress (make-progress-reporter
+ (format "Thinking... (%s) "
+ (chess-ply-to-algebraic best-ply))
+ 0 (length plies))))
+ (cl-loop for i from 1
+ for ply in plies
+ do (let ((value (- (chess-ai-search
+ (chess-ply-next-pos ply)
+ (1- depth) (- upper-bound) (- lower-bound)
+ eval-fn))))
+ (progress-reporter-update progress i)
+ (accept-process-output nil 0.05)
+ (when (> value lower-bound)
+ (setq lower-bound value
+ best-ply ply)
+ (progress-reporter-force-update
+ progress
+ i
+ (format "Thinking... (%s {cp=%d}) "
+ (chess-ply-to-algebraic best-ply)
+ lower-bound))))
+ until (>= lower-bound upper-bound))
+ (progress-reporter-done progress)
+ (cons lower-bound best-ply))))))
(defun chess-ai-best-move (position &optional depth eval-fn)
"Find the best move for POSITION.