From d3bd3c6f07e0c9a2a7a1488e43b47439a5f8ac54 Mon Sep 17 00:00:00 2001 From: Mario Lang Date: Wed, 4 Jun 2014 22:43:13 +0200 Subject: Sync from ELPA. --- chess-input.el | 87 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 42 deletions(-) (limited to 'chess-input.el') diff --git a/chess-input.el b/chess-input.el index e782066..ce7b348 100644 --- a/chess-input.el +++ b/chess-input.el @@ -1,6 +1,10 @@ ;;; chess-input.el --- Keyboard entry of algebraic notation, using shortcut notation -;; Copyright (C) 2014 Free Software Foundation, Inc. +;; Copyright (C) 2002, 2005, 2014 Free Software Foundation, Inc. + +;; Author: John Wiegley +;; Maintainer: Mario Lang +;; Keywords: games ;; This is free software; you can redistribute it and/or modify it under ;; the terms of the GNU General Public License as published by the Free @@ -17,9 +21,14 @@ ;;; Commentary: -;; This scheme was adapted from the way SCID -;; (http://scid.sourceforge.net), by Shane Hudson, behaves. It's the -;; only way to move your pieces around! +;; This scheme was adapted from the way SCID (), +;; by Shane Hudson, behaves. It is based on standard algebraic notation. +;; You do not need to type all characters from the corresponding SAN of a move, +;; chess-input will automatically pick the move once it is unambiguous. +;; +;; Additionally, optional characters from SAN are treated as such. +;; You do not need to type x or =, although you can, if you prefer to. +;; For instance, "bxc8=N#" can be selected by typing `b c 8 n'. ;;; Code: @@ -39,12 +48,11 @@ (make-variable-buffer-local 'chess-input-position-function) (make-variable-buffer-local 'chess-input-move-function) -(defun chess-input-test-move (move-ply) - "Return the given MOVE if it matches the user's current input." - (let* ((move (cdr move-ply)) +(defun chess-input-test-move (ply) + "Return the given PLY if it matches the user's current input." + (let* ((move (chess-ply-to-algebraic ply)) (i 0) (x 0) (l (length move)) - (xl (length chess-input-move-string)) - (match t)) + (xl (length chess-input-move-string))) (unless (or (and (equal (downcase chess-input-move-string) "ok") (string-match "\\`O-O[+#]?\\'" move)) (and (equal (downcase chess-input-move-string) "oq") @@ -52,21 +60,19 @@ (while (and (< i l) (< x xl)) (let ((move-char (aref move i)) (entry-char (aref chess-input-move-string x))) - (if (and (= move-char ?x) - (/= entry-char ?x)) - (setq i (1+ i)) - (if (/= entry-char (if (< entry-char ?a) - move-char - (downcase move-char))) - (setq match nil i l) - (setq i (1+ i) x (1+ x))))))) - (if match - move-ply))) + (cond + ((or (and (= move-char ?x) (/= entry-char ?x)) + (and (= move-char ?=) (/= entry-char ?=))) + (setq i (1+ i))) + ((/= entry-char (if (< entry-char ?a) move-char (downcase move-char))) + (setq ply nil i l)) + (t (setq i (1+ i) x (1+ x))))))) + ply)) (defsubst chess-input-display-moves (&optional move-list) (if (> (length chess-input-move-string) 0) (message "[%s] %s" chess-input-move-string - (mapconcat 'cdr + (mapconcat #'chess-ply-to-algebraic (or move-list (delq nil (mapcar 'chess-input-test-move (cdr chess-input-moves)))) @@ -107,27 +113,24 @@ (cons char (sort - (mapcar - (function - (lambda (ply) - (cons ply (chess-ply-to-algebraic ply)))) - (if (eq char ?b) - (append (chess-legal-plies - position :piece (if color ?P ?p) :file 1) - (chess-legal-plies - position :piece (if color ?B ?b))) - (if (and (>= char ?a) - (<= char ?h)) - (chess-legal-plies position - :piece (if color ?P ?p) - :file (- char ?a)) - (chess-legal-plies position - :piece (if color - (upcase char) - (downcase char)))))) + (if (eq char ?b) + (append (chess-legal-plies + position :piece (if color ?P ?p) :file 1) + (chess-legal-plies + position :piece (if color ?B ?b))) + (if (and (>= char ?a) + (<= char ?h)) + (chess-legal-plies position + :piece (if color ?P ?p) + :file (- char ?a)) + (chess-legal-plies position + :piece (if color + (upcase char) + (downcase char))))) (function (lambda (left right) - (string-lessp (cdr left) (cdr right)))))))))) + (string-lessp (chess-ply-to-algebraic left) + (chess-ply-to-algebraic right)))))))))) (let ((moves (delq nil (mapcar 'chess-input-test-move (cdr chess-input-moves))))) (cond @@ -137,10 +140,10 @@ ;; case, always take the b-pawn move; to select the bishop ;; move, use B to begin the keyboard shortcut (and (= (length moves) 2) - (string= (downcase (cdr (car moves))) - (downcase (cdr (cadr moves)))) + (string= (downcase (chess-ply-to-algebraic (car moves))) + (downcase (chess-ply-to-algebraic (cadr moves)))) (setq moves (cdr moves)))) - (funcall chess-input-move-function nil (caar moves)) + (funcall chess-input-move-function nil (car moves)) (setq chess-input-move-string nil chess-input-moves nil chess-input-moves-pos nil)) -- cgit v1.2.3