summaryrefslogtreecommitdiff
path: root/chess-ply.el
diff options
context:
space:
mode:
authorMario Lang <mlang@delysid.org>2014-04-21 13:41:56 +0200
committerMario Lang <mlang@delysid.org>2014-04-21 13:41:56 +0200
commite9823070847892ed90aa9e9ce9d252b104872b0a (patch)
treeb9de6f6a1894751b018c953583181f598edc21ed /chess-ply.el
parent51a97cafe5d46d948b1adecb76c709724de73af2 (diff)
chess-pos-search*: New function.
Search for several pieces in one swipe of the board, returning an alist of pieces and their indices. Use this in chess-legal-plies for the common case where we want all legal plies for a certain color makes the testsuite time go down to 9m57s.
Diffstat (limited to 'chess-ply.el')
-rw-r--r--chess-ply.el15
1 files changed, 8 insertions, 7 deletions
diff --git a/chess-ply.el b/chess-ply.el
index 7c4d741..7e35046 100644
--- a/chess-ply.el
+++ b/chess-ply.el
@@ -249,8 +249,7 @@ maneuver."
(next-color (not color))
(king (chess-pos-king-index next-pos next-color))
(in-check (catch 'in-check
- (chess-search-position next-pos king
- (not next-color) t))))
+ (chess-search-position next-pos king color t))))
;; first, see if the moves leaves the king in check.
;; This is tested by seeing if any of the opponent's
;; pieces can reach the king in the position that will
@@ -343,12 +342,14 @@ position object passed in."
(catch 'any-found
(apply 'chess-legal-plies position (delq :any keywords)))))
((memq :color keywords)
- (let ((plies (list t))
- (color (cadr (memq :color keywords))))
- (dolist (p '(?P ?R ?N ?B ?K ?Q))
+ (let* ((plies (list t))
+ (color (cadr (memq :color keywords)))
+ (pieces (if color '(?P ?N ?B ?R ?Q ?K) '(?p ?n ?b ?r ?q ?k)))
+ (candidates (apply #'chess-pos-search* position pieces)))
+ (dolist (p pieces)
(nconc plies (chess-legal-plies position
- :piece (if color p
- (downcase p)))))
+ :piece p
+ :candidates (cdr (assq p candidates)))))
(cdr plies)))
(t
(let* ((piece (cadr (memq :piece keywords)))