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 From 5bd1e7248bb9bf3b335cbd6bec250866bd165af1 Mon Sep 17 00:00:00 2001 From: dickmao Date: Wed, 8 Aug 2018 17:57:01 -0400 Subject: assign default chess-engine handler for chess-ics --- chess-ics.el | 1 + 1 file changed, 1 insertion(+) diff --git a/chess-ics.el b/chess-ics.el index f260e06..24162be 100644 --- a/chess-ics.el +++ b/chess-ics.el @@ -470,6 +470,7 @@ See `chess-ics-game'.") (chess-game-set-data game 'ics-game-number game-number) (chess-game-set-data game 'ics-buffer (current-buffer)) (chess-game-set-tag game "Site" chess-ics-server) + (chess-engine-set-response-handler (current-buffer)) (while tags (cl-assert (keywordp (car tags))) (chess-game-set-tag -- cgit v1.2.3