emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 01/01: * chess-pos.el (chess-coord-to-index): Use chess-rf-to-ind


From: Mario Lang
Subject: [elpa] 01/01: * chess-pos.el (chess-coord-to-index): Use chess-rf-to-index. (ches-index-to-coord): Do not concat the result of calls to char-to-string, use string directly with the characters as arguments.
Date: Wed, 04 Jun 2014 09:23:16 +0000

mlang pushed a commit to branch externals/chess
in repository elpa.

commit 131a3802cf21b4b1354bb74b62c1caf88ac3c7bc
Author: Mario Lang <address@hidden>
Date:   Wed Jun 4 11:22:14 2014 +0200

    * chess-pos.el (chess-coord-to-index): Use chess-rf-to-index.
    (ches-index-to-coord): Do not concat the result of calls to char-to-string, 
use
    string directly with the characters as arguments.
---
 chess-pos.el |   28 +++++++++++++---------------
 1 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/chess-pos.el b/chess-pos.el
index e2cabeb..7ccb68f 100644
--- a/chess-pos.el
+++ b/chess-pos.el
@@ -294,29 +294,27 @@ color will do."
   (cl-check-type file (integer 0 7))
   (+ (* 8 rank) file))
 
-(defsubst chess-coord-to-index (coord)
-  "Convert a COORD string into an index value."
-  (cl-assert (stringp coord))
-  (cl-assert (= (length coord) 2))
-  (+ (* 8 (- 7 (- (aref coord 1) ?1)))
-     (- (aref coord 0) ?a)))
-
-(defsubst chess-index-to-coord (index)
-  "Convert the chess position INDEX into a coord string."
-  (cl-assert (and (>= index 0) (< index 64)))
-  (concat (char-to-string (+ (mod index 8) ?a))
-         (char-to-string (+ (- 7 (/ index 8)) ?1))))
-
 (defsubst chess-index-rank (index)
   "Return the rank component of the given INDEX."
-  (cl-assert (and (>= index 0) (< index 64)))
+  (cl-check-type index (integer 0 63))
   (/ index 8))
 
 (defsubst chess-index-file (index)
   "Return the file component of the given INDEX."
-  (cl-assert (and (>= index 0) (< index 64)))
+  (cl-check-type index (integer 0 63))
   (mod index 8))
 
+(defsubst chess-coord-to-index (coord)
+  "Convert a COORD string (such as \"e4\" into an index value."
+  (cl-assert (stringp coord))
+  (cl-assert (= (length coord) 2))
+  (chess-rf-to-index (- 7 (- (aref coord 1) ?1)) (- (aref coord 0) ?a)))
+
+(defsubst chess-index-to-coord (index)
+  "Convert the chess position INDEX into a coord string."
+  (cl-check-type index (integer 0 63))
+  (string (+ (chess-index-file index) ?a) (+ (- 7 (chess-index-rank index)) 
?1)))
+
 (defsubst chess-incr-index (index rank-move file-move)
   "Create a new INDEX from an old one, by adding RANK-MOVE and FILE-MOVE."
   (cl-assert (and (>= index 0) (< index 64)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]