diff options
| author | dickmao <rchiang@cs.stonybrook.edu> | 2018-05-29 01:03:24 -0400 |
|---|---|---|
| committer | dickmao <rchiang@cs.stonybrook.edu> | 2018-05-29 01:03:24 -0400 |
| commit | 709b56300a14f01053e4f484ba4b503d2eb65bb4 (patch) | |
| tree | 780a80de13b8667e1f758ba0c7e45c29664f3c78 /chess-ply.el | |
| parent | 999fcdd7f9c82c3ec2e8343c5de7b4dea53bf8d0 (diff) | |
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. |
