summaryrefslogtreecommitdiff
path: root/chess-polyglot.el
diff options
context:
space:
mode:
authorMario Lang <mlang@delysid.org>2014-04-16 16:36:53 +0200
committerMario Lang <mlang@delysid.org>2014-04-16 16:36:53 +0200
commit9fd14288538d25613070e5bdd8c5e0ef8818eba9 (patch)
tree48c7f099f492f6a528cc9f120790b79da9b72935 /chess-polyglot.el
parent6511a374d94c6683ee8fe47637ce2e9f24b8508a (diff)
chess-ai.el: Spare computing time by consulting the opening book.
Diffstat (limited to 'chess-polyglot.el')
-rw-r--r--chess-polyglot.el19
1 files changed, 10 insertions, 9 deletions
diff --git a/chess-polyglot.el b/chess-polyglot.el
index af1767b..391320d 100644
--- a/chess-polyglot.el
+++ b/chess-polyglot.el
@@ -508,15 +508,16 @@ distribute the probability that a move gets picked."
(cl-flet ((ply-weight (ply)
(round (expt (chess-ply-keyword ply :polyglot-book-weight)
strength))))
- (let* ((plies (chess-polyglot-book-plies book position))
- (random-value (random (cl-reduce #'+ (mapcar #'ply-weight plies))))
- (max 0) ply)
- (while plies
- (if (< random-value (cl-incf max (ply-weight (car plies))))
- (setq ply (car plies) plies nil)
- (setq plies (cdr plies))))
- (cl-assert ply)
- ply)))
+ (let ((plies (chess-polyglot-book-plies book position)))
+ (when plies
+ (let ((random-value (random (cl-reduce #'+ (mapcar #'ply-weight plies))))
+ (max 0) ply)
+ (while plies
+ (if (< random-value (cl-incf max (ply-weight (car plies))))
+ (setq ply (car plies) plies nil)
+ (setq plies (cdr plies))))
+ (cl-assert ply)
+ ply)))))
(defalias 'chess-polyglot-book-close 'kill-buffer
"Close a polyglot book.")