Fix use of (COL|ROW)_NAME macros to compute numbers from names.
authorYann Dirson <ydirson@free.fr>
Sat, 15 Feb 2014 21:28:09 +0000 (22:28 +0100)
committerYann Dirson <ydirson@free.fr>
Sat, 15 Feb 2014 21:28:09 +0000 (22:28 +0100)
The formula is reversible for the somewhat-standard default position
notation, but that does not mean we should write silly things.  As a
proof, if that was needed, the formula necessary to support the xboard
protocol is not reversible.

NEWS
gnushogi/commondsp.c
gnushogi/cursesdsp.c
gnushogi/gnushogi.h
gnushogi/rawdsp.c
gnushogi/util.c

diff --git a/NEWS b/NEWS
index 312e854..d709703 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Changes in version 1.4.2 (unreleased):
 
 * XShogi is no longer included in the GNU Shogi source, it is
   available as a separate source archive.
+* Minor code cleanups.
 
 Changes in version 1.4.1 (01/2014):
 
index 49b3805..32785f5 100644 (file)
@@ -377,17 +377,17 @@ parser(char *f, int side, short *fpiece)
 
     if (f[1] == '*' || f[1] == '\'')
     {
-        c2 = COL_NAME(f[2]);
-        r2 = ROW_NAME(f[3]);
+        c2 = COL_NUM(f[2]);
+        r2 = ROW_NUM(f[3]);
 
         return ((NO_SQUARES + *fpiece) << 8) | locn(r2, c2);
     }
     else
     {
-        c1 = COL_NAME(f[1]);
-        r1 = ROW_NAME(f[2]);
-        c2 = COL_NAME(f[3]);
-        r2 = ROW_NAME(f[4]);
+        c1 = COL_NUM(f[1]);
+        r1 = ROW_NUM(f[2]);
+        c2 = COL_NUM(f[3]);
+        r2 = ROW_NUM(f[4]);
         p = (f[5] == '+') ? 0x80 : 0;
 
         return (locn(r1, c1) << 8) | locn(r2, c2) | p;
index ee492b2..3e85a94 100644 (file)
@@ -514,8 +514,8 @@ Curses_EditBoard(void)
         }
         else
         {
-            c = COL_NAME(s[1]);
-            r = ROW_NAME(s[2]);
+            c = COL_NUM(s[1]);
+            r = ROW_NUM(s[2]);
         }
 
         if ((c >= 0) && (c < NO_COLS) && (r >= 0) && (r < NO_ROWS))
index 7cd5a49..48408d7 100644 (file)
@@ -182,6 +182,8 @@ extern void movealgbr(short m, char *s);
 
 #define ROW_NAME(n) ('a' + NO_ROWS - 1 - n)
 #define COL_NAME(n) ('1' + NO_COLS - 1 - n)
+#define ROW_NUM(c) ('a' + NO_ROWS - 1 - c)
+#define COL_NUM(c) ('1' + NO_COLS - 1 - c)
 
 #if defined HASHFILE || defined CACHE
 #  define PTBLBDSIZE (NO_SQUARES + NO_PIECES)
index b0e4084..d4ac301 100644 (file)
@@ -385,8 +385,8 @@ Raw_EditBoard(void)
         }
         else
         {
-            c = COL_NAME(s[1]);
-            r = ROW_NAME(s[2]);
+            c = COL_NUM(s[1]);
+            r = ROW_NUM(s[2]);
         }
 
         if ((c >= 0) && (c < NO_COLS) && (r >= 0) && (r < NO_ROWS))
index 0d1611e..0c7911d 100644 (file)
@@ -85,10 +85,10 @@ parse(FILE * fd, unsigned short *mv, short side, char *opening)
         return 0;
     }
 
-    c1 = COL_NAME(s[0]);
-    r1 = ROW_NAME(s[1]);
-    c2 = COL_NAME(s[2]);
-    r2 = ROW_NAME(s[3]);
+    c1 = COL_NUM(s[0]);
+    r1 = ROW_NUM(s[1]);
+    c2 = COL_NUM(s[2]);
+    r2 = ROW_NUM(s[3]);
     *mv = (locn(r1, c1) << 8) | locn(r2, c2);
 
     if (c == '?')