[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 02/02: (chessalgebraicregexp, chessalgebraictoply): Optional
From: 
Mario Lang 
Subject: 
[elpa] 02/02: (chessalgebraicregexp, chessalgebraictoply): Optionally allow "00" and "000" in addition to "OO" and "OOO" to mean castling. (chessalgebraicregexp, chessalgebraictoply): Handle figurine notation. 
Date: 
Sat, 14 Jun 2014 11:32:48 +0000 
mlang pushed a commit to branch externals/chess
in repository elpa.
commit 3a442940cedaf94d4ddd2805b79f8f08b06cd54e
Author: Mario Lang <address@hidden>
Date: Sat Jun 14 13:30:39 2014 +0200
(chessalgebraicregexp, chessalgebraictoply): Optionally allow "00"
and "000" in addition to "OO" and "OOO" to mean castling.
(chessalgebraicregexp, chessalgebraictoply): Handle figurine
notation.

ChangeLog  4 +++
chessalgebraic.el  61 ++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 23 deletions()
diff git a/ChangeLog b/ChangeLog
index 2ae3d04..400a5e6 100644
 a/ChangeLog
+++ b/ChangeLog
@@ 2,6 +2,10 @@
* chessalgebraic.el (chessplytoalgebraic): If TYPE is `:numeric',
generate ICCF numeric notation.
+ (chessalgebraicregexp, chessalgebraictoply): Optionally allow "00"
+ and "000" in addition to "OO" and "OOO" to mean castling.
+ (chessalgebraicregexp, chessalgebraictoply): Handle figurine
+ notation.
20140613 Mario Lang <address@hidden>
diff git a/chessalgebraic.el b/chessalgebraic.el
index 13ae97b..5ca7895 100644
 a/chessalgebraic.el
+++ b/chessalgebraic.el
@@ 52,36 +52,39 @@
;;; Code:
(evalwhencompile (require 'cllib))

(require 'chessmessage)
(require 'chessply)
(require 'chesspos)
+(require 'cllib)
+
+(defconst chessalgebraicfigurinepieces
+ '((?K . #x2654) (?Q . #x2655) (?R . #x2656)
+ (?B . #x2657) (?N . #x2658) (?P . #x2659)
+ (?k . #x265A) (?q . #x265B) (?r . #x265C)
+ (?b . #x265D) (?n . #x265E) (?p . #x265F))
+ "Map internal piece representation to Unicode chess figures (as used in
figurine
+notation.")
(defconst chessalgebraicregexp
 (rx (group (or (or "OO" "OOO")
 (and (optional (group (char ?N ?B ?R ?Q ?K)))
+ (rx (group (or (or "OO" "OOO" "00" "000")
+ (and (optional (group (char ?N ?B ?R ?Q ?K
+ ?♔ ?♕ ?♖ ?♗ ?♘
+ ?♚ ?♛ ?♜ ?♝ ?♞)))
(optional (char ?/))
(group (optional (char "ah")) (optional (char "18")))
(optional (group (char ? ?x)))
(group (char "ah") (char "18"))
 (optional (group ?= (group (char ?N ?B ?R ?Q ?K)))))))
+ (optional (group ?= (group (char ?N ?B ?R ?Q ?K
+ ?♔ ?♕ ?♖ ?♗ ?♘
+ ?♚ ?♛ ?♜ ?♝ ?♞)))))))
(optional (group (char ?+ ?#))))
"A regular expression that matches all possible algebraic moves.
This regexp handles both long and short form.")
+This regexp matches short, long and figurine notation.")
(defconst chessalgebraicregexpentire (concat chessalgebraicregexp "$"))
(defconst chessalgebraicregexpws (concat chessalgebraicregexp "\\s"))
(defconst chessalgebraicfigurinepieces
 '((?K . #x2654) (?Q . #x2655) (?R . #x2656)
 (?B . #x2657) (?N . #x2658) (?P . #x2659)
 (?k . #x265A) (?q . #x265B) (?r . #x265C)
 (?b . #x265D) (?n . #x265E) (?p . #x265F))
 "Map internal piece characters to Unicode chess figures (as used in figurine
notation.")

(chessmessagecatalog 'english
'((clarifypiece . "Clarify piece to move by rank or file")
(couldnotclarify . "Could not determine which piece to use")
@@ 90,9 +93,7 @@ notation.")
(atmovestring . "At algebraic move '%s': %s")))
(defun chessalgebraictoply (position move &optional trust)
 "Convert the (short or long) algebraic notation MOVE for POSITION to a ply.

Figurine notation is currently not supported."
+ "Convert (short, long or figurine) algebraic notation MOVE for POSITION to a
ply."
(clchecktype position chesspos)
(clchecktype move string)
(let ((casefoldsearch nil))
@@ 100,8 +101,8 @@ Figurine notation is currently not supported."
(let ((color (chesspossidetomove position))
(mate (matchstring 8 move))
(piece (aref move 0))
 changes longstyle)
 (if (eq piece ?O)
+ changes type)
+ (if (or (eq piece ?O) (eq piece ?0))
(setq changes (chessplycastlingchanges
position (= (length (matchstring 1 move)) 5)))
(let ((promotion (matchstring 7 move)))
@@ 112,11 +113,17 @@ Figurine notation is currently not supported."
(if (and source (= (length source) 2))
(prog1
(list (chesscoordtoindex source) target)
 (setq longstyle t))
+ (setq type :lan))
(if (= (length source) 0)
(setq source nil)
(setq source (aref source 0)))
(let (candidates which)
+ (when (and (not type) (< piece ?a))
+ (setq type :san))
+ (when (rassq piece chessalgebraicfigurinepieces)
+ (unless type (setq type :fan))
+ (setq piece (upcase
+ (car (rassq piece
chessalgebraicfigurinepieces)))))
(unless (< piece ?a)
(setq source piece piece ?P))
;; we must use our knowledge of how pieces can
@@ 145,16 +152,24 @@ Figurine notation is currently not supported."
(chesserror 'couldnotclarify)
(list which target))))
(chesserror 'nocandidates move))))))
+
(when promotion
 (nconc changes (list :promote (aref promotion 0))))))
+ (nconc changes
+ (list :promote
+ (upcase (or (car (rassq (aref promotion 0)
+
chessalgebraicfigurinepieces))
+ (aref promotion 0))))))))
(when changes
(if (and trust mate)
(nconc changes (list (if (stringequal mate "#")
:checkmate
:check))))
 (unless longstyle
 (nconc changes (list :san move)))
+ ;; If we know the notation type by now, remember the string so that
+ ;; we do not need to regenerate it later on.
+ (when type
+ (clchecktype type keyword)
+ (nconc changes (list type move)))
(conditioncase err
(apply 'chessplycreate position trust changes)