From 5ea6210573f345d63d7aafeb125726d3dc9b2238 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Sat, 15 Feb 2014 22:28:09 +0100 Subject: [PATCH] Fix use of (COL|ROW)_NAME macros to compute numbers from names. 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 | 1 + gnushogi/commondsp.c | 12 ++++++------ gnushogi/cursesdsp.c | 4 ++-- gnushogi/gnushogi.h | 2 ++ gnushogi/rawdsp.c | 4 ++-- gnushogi/util.c | 8 ++++---- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index 312e854..d709703 100644 --- 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): diff --git a/gnushogi/commondsp.c b/gnushogi/commondsp.c index 49b3805..32785f5 100644 --- a/gnushogi/commondsp.c +++ b/gnushogi/commondsp.c @@ -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; diff --git a/gnushogi/cursesdsp.c b/gnushogi/cursesdsp.c index ee492b2..3e85a94 100644 --- a/gnushogi/cursesdsp.c +++ b/gnushogi/cursesdsp.c @@ -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)) diff --git a/gnushogi/gnushogi.h b/gnushogi/gnushogi.h index 7cd5a49..48408d7 100644 --- a/gnushogi/gnushogi.h +++ b/gnushogi/gnushogi.h @@ -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) diff --git a/gnushogi/rawdsp.c b/gnushogi/rawdsp.c index b0e4084..d4ac301 100644 --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@ -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)) diff --git a/gnushogi/util.c b/gnushogi/util.c index 0d1611e..0c7911d 100644 --- a/gnushogi/util.c +++ b/gnushogi/util.c @@ -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 == '?') -- 1.7.0.4