summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2017-01-22 21:05:14 -0800
committerJohn Wiegley <johnw@newartisans.com>2017-01-22 21:05:14 -0800
commit8257a9d47fa617851b977c0303794a520e51e1f3 (patch)
treef2cd967ade6c07b690fe40422cf708b535032b2f
parent03f961a1d8bb9178ebe9a399eacfed3ade36a80c (diff)
A little bit of code golfing
-rw-r--r--chess-ply.el35
1 files changed, 14 insertions, 21 deletions
diff --git a/chess-ply.el b/chess-ply.el
index dfae21f..66df7f3 100644
--- a/chess-ply.el
+++ b/chess-ply.el
@@ -177,26 +177,21 @@
(list position))
-(defvar promotion-options
- '(queen rook bishop knight))
+(defconst promotion-options
+ '((queen ?Q ?q)
+ (rook ?R ?r)
+ (bishop ?B ?b)
+ (knight ?N ?n)))
(defun ask-promotion (white)
- (let ((p (ido-completing-read "Symbol? " (mapcar #'symbol-name promotion-options))))
- (cond ((string= "queen" p)
- (if white ?Q ?q))
-
- ((string= "rook" p)
- (if white ?R ?r))
-
- ((string= "bishop" p)
- (if white ?B ?b))
-
- ((string= "knight" p)
- (if white ?N ?n))
-
- ;; Promote to queen as fallback
- (t (if white ?Q ?q)))))
-
+ (nth (if white 1 2)
+ (assoc (intern-soft
+ (or (completing-read
+ "Symbol? "
+ (mapcar (lambda (x) (symbol-name (car x)))
+ promotion-options))
+ "queen"))
+ promotion-options)))
(defun chess-ply-create (position &optional valid-p &rest changes)
"Create a ply from the given POSITION by applying the supplied CHANGES.
@@ -246,9 +241,7 @@ maneuver."
(= (if color 0 7)
(chess-index-rank (cadr changes))))
(let ((promo (ask-promotion color)))
- (setq changes
- (append changes (list :promote promo)))
-
+ (nconc changes (list :promote promo))
(setq ply (cons position changes))))
;; is this an en-passant capture?