From 709b56300a14f01053e4f484ba4b503d2eb65bb4 Mon Sep 17 00:00:00 2001 From: dickmao Date: Tue, 29 May 2018 01:03:24 -0400 Subject: avoid ask-promotion returning nil --- chess-game.el | 2 +- chess-ply.el | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/chess-game.el b/chess-game.el index aace91b..ed38288 100644 --- a/chess-game.el +++ b/chess-game.el @@ -223,7 +223,7 @@ if INDEX is nil)." (defun chess-game-ply (game &optional index) "Return a ply of GAME. -If INDEX is non-nil, the last played ply is returned." +If INDEX is nil, the last played ply is returned." (cl-assert game) (if index (nth index (chess-game-plies game)) 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. -- cgit v1.2.3