diff options
| author | John Wiegley <johnw@newartisans.com> | 2018-08-09 10:51:04 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-09 10:51:04 -0400 |
| commit | 29dd9bb233e149cae62a2277020074f8fec1eec8 (patch) | |
| tree | 381b8cbac3eedbb0e49fafb36eaf7fd1a974997d /chess-ply.el | |
| parent | 999fcdd7f9c82c3ec2e8343c5de7b4dea53bf8d0 (diff) | |
| parent | 5bd1e7248bb9bf3b335cbd6bec250866bd165af1 (diff) | |
Merge pull request #20 from dickmao/master
avoid ask-promotion returning nil
Diffstat (limited to 'chess-ply.el')
| -rw-r--r-- | chess-ply.el | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/chess-ply.el b/chess-ply.el index 66df7f3..f49c7ad 100644 --- a/chess-ply.el +++ b/chess-ply.el @@ -176,22 +176,21 @@ (cl-assert (vectorp position)) (list position)) - (defconst promotion-options - '((queen ?Q ?q) - (rook ?R ?r) - (bishop ?B ?b) - (knight ?N ?n))) + '((?q ?Q "[q]ueen") + (?r ?R "(r)ook") + (?b ?B "(b)ishop") + (?n ?N "k(n)ight"))) (defun ask-promotion (white) - (nth (if white 1 2) - (assoc (intern-soft - (or (completing-read - "Symbol? " - (mapcar (lambda (x) (symbol-name (car x))) - promotion-options)) - "queen")) - promotion-options))) + (let ((prompts (mapcar (lambda (x) (nth 2 x)) promotion-options)) + (choices (append '(?\n ?\r) (mapcar (lambda (x) (car x)) promotion-options)))) + (nth (if white 1 0) + (or + (assoc + (read-char-choice (concat "Promote to: " (mapconcat 'identity prompts " ") " ? ") + choices t) promotion-options) + (car promotion-options))))) (defun chess-ply-create (position &optional valid-p &rest changes) "Create a ply from the given POSITION by applying the supplied CHANGES. |
