From 5fbd58dc91d27467d3ccbea2d76ab70a5ff2b3f7 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Mon, 11 Feb 2008 01:47:00 +0100 Subject: [PATCH] Parametrize more hardcoded contants. --- gnushogi/commondsp.c | 16 ++++++++-------- gnushogi/cursesdsp.c | 46 +++++++++++++++++++++++++++------------------- gnushogi/eval.c | 6 +++--- gnushogi/genmove.c | 6 +++--- gnushogi/gnushogi.h | 17 +++++++---------- gnushogi/init.c | 4 ++-- gnushogi/rawdsp.c | 4 ++-- gnushogi/util.c | 8 ++++---- 8 files changed, 56 insertions(+), 51 deletions(-) diff --git a/gnushogi/commondsp.c b/gnushogi/commondsp.c index 50dc032..56afbe6 100644 --- a/gnushogi/commondsp.c +++ b/gnushogi/commondsp.c @@ -386,17 +386,17 @@ parser(char *f, int side, short *fpiece) if (f[1] == '*' || f[1] == '\'') { - c2 = '9' - f[2]; - r2 = 'i' - f[3]; + c2 = COL_NAME(f[2]); + r2 = ROW_NAME(f[3]); return ((NO_SQUARES + *fpiece) << 8) | locn(r2, c2); } else { - c1 = '9' - f[1]; - r1 = 'i' - f[2]; - c2 = '9' - f[3]; - r2 = 'i' - f[4]; + c1 = COL_NAME(f[1]); + r1 = ROW_NAME(f[2]); + c2 = COL_NAME(f[3]); + r2 = ROW_NAME(f[4]); p = (f[5] == '+') ? 0x80 : 0; return (locn(r1, c1) << 8) | locn(r2, c2) | p; @@ -716,7 +716,7 @@ SaveGame(void) for (i = NO_ROWS - 1; i > -1; i--) { - fprintf(fd, "%c ", 'i' - i); + fprintf(fd, "%c ", ROW_NAME(i)); for (c = 0; c < NO_COLS; c++) { @@ -751,7 +751,7 @@ SaveGame(void) } fputs(empty, fd); - fprintf(fd, " 9 8 7 6 5 4 3 2 1\n"); + fprintf(fd, " 9 8 7 6 5 4 3 2 1\n"); /* FIXME */ fputs(empty, fd); fprintf(fd, " p l n s g b r k\n"); diff --git a/gnushogi/cursesdsp.c b/gnushogi/cursesdsp.c index 407e6fa..fb0e9d4 100644 --- a/gnushogi/cursesdsp.c +++ b/gnushogi/cursesdsp.c @@ -45,8 +45,8 @@ int mycnt1, mycnt2; #define TAB (58) -#define VIR_C(s) ((flag.reverse) ? (8 - column(s)) : column(s)) -#define VIR_R(s) ((flag.reverse) ? (8 - row(s)) : row(s)) +#define VIR_C(s) ((flag.reverse) ? (NO_COLS - 1 - column(s)) : column(s)) +#define VIR_R(s) ((flag.reverse) ? (NO_ROWS - 1 - row(s)) : row(s)) unsigned short MV[MAXDEPTH]; int MSCORE; @@ -162,7 +162,7 @@ Curses_ShowPatternCount(short side, short n) { if (flag.post) { - gotoXY(TAB + 10 + 3 * side, 20); + gotoXY(TAB + 10 + 3 * side, 20); /* CHECKME */ if (n >= 0) printw("%3d", n); @@ -175,9 +175,9 @@ Curses_ShowPatternCount(short side, short n) void ShowPlayers(void) { - gotoXY(5, ((flag.reverse) ? 23 : 2)); + gotoXY(5, ((flag.reverse) ? (5 + 2*NO_ROWS) : 2)); printw("%s", (computer == white) ? CP[218] : CP[74]); - gotoXY(5, ((flag.reverse) ? 2 : 23)); + gotoXY(5, ((flag.reverse) ? 2 : (5 + 2*NO_ROWS))); printw("%s", (computer == black) ? CP[218] : CP[74]); } @@ -498,8 +498,8 @@ Curses_EditBoard(void) } else { - c = '9' - s[1]; - r = 'i' - s[2]; + c = COL_NAME(s[1]); + r = ROW_NAME(s[2]); } if ((c >= 0) && (c < NO_COLS) && (r >= 0) && (r < NO_ROWS)) @@ -598,7 +598,7 @@ Curses_SearchStartStuff(short side) signal(SIGINT, Curses_TerminateSearch); signal(SIGQUIT, Curses_TerminateSearch); - for (i = 4; i < 14; i++) + for (i = 4; i < 14; i++) /* CHECKME */ { gotoXY(TAB, i); ClearEoln(); @@ -745,7 +745,7 @@ DrawPiece(short sq) y = pxx[(int)piece]; } - gotoXY(8 + 5 * VIR_C(sq), 4 + 2 * (8 - VIR_R(sq))); + gotoXY(8 + 5 * VIR_C(sq), 4 + 2 * ((NO_ROWS - 1) - VIR_R(sq))); printw("%c%c%c%c", l, p, y, r); } @@ -761,7 +761,7 @@ Curses_ShowPostnValue(short sq) { short score; - gotoXY(4 + 5 * VIR_C(sq), 5 + 2 * (7 - VIR_R(sq))); + gotoXY(4 + 5 * VIR_C(sq), 5 + 2 * (7 - VIR_R(sq))); /* CHECKME */ score = ScorePosition(color[sq]); if (color[sq] != neutral) @@ -807,6 +807,7 @@ void Curses_UpdateDisplay(short f, short t, short redraw, short isspec) { short i, sq, z; + int j; if (redraw) { @@ -816,31 +817,38 @@ Curses_UpdateDisplay(short f, short t, short redraw, short isspec) i = 2; gotoXY(3, ++i); - printw(" +----+----+----+----+----+----+----+----+----+"); + printw(" +"); + for (j=0; j 26) && (t > 26)) + if ((!InBlackCamp(f)) && (!InBlackCamp(t))) return false; } @@ -1107,7 +1107,7 @@ LinkPreventCheckDrops(short side, short xside, short ply) if (board[square = PieceList[side][0]] != king) return; - for (piece = lance; piece <= rook; piece++) + for (piece = lance; piece <= rook; piece++) /* FIXME */ { if (piece == lance || piece == bishop || piece == rook) { diff --git a/gnushogi/gnushogi.h b/gnushogi/gnushogi.h index 0200d67..71a4e3f 100644 --- a/gnushogi/gnushogi.h +++ b/gnushogi/gnushogi.h @@ -155,10 +155,12 @@ extern void movealgbr(short m, char *s); #define NO_PIECES 15 #define MAX_CAPTURED 19 #define NO_PTYPE_PIECES 15 -#define NO_SQUARES 81 -#define NO_SQUARES_1 80 #define NO_COLS 9 #define NO_ROWS 9 +#define NO_SQUARES (NO_COLS*NO_ROWS) + +#define ROW_NAME(n) ('a' + NO_ROWS - 1 - n) +#define COL_NAME(n) ('1' + NO_COLS - 1 - n) #if defined HASHFILE || defined CACHE # define PTBLBDSIZE (NO_SQUARES + NO_PIECES) @@ -851,14 +853,9 @@ extern struct hashentry *ttable[2]; extern short rpthash[2][256]; extern char *DRAW; -/* - * FIXME: these should be more generic instead of using the - * magic number 9. - */ - -#define row(a) ((a) / 9) -#define column(a) ((a) % 9) -#define locn(a, b) (((a) * 9) + b) +#define row(a) ((a) / NO_COLS) +#define column(a) ((a) % NO_COLS) +#define locn(a, b) (((a) * NO_COLS) + b) /* init external functions */ extern void InitConst(char *lang); /* init.c */ diff --git a/gnushogi/init.c b/gnushogi/init.c index ffef1f4..4756d39 100644 --- a/gnushogi/init.c +++ b/gnushogi/init.c @@ -400,7 +400,7 @@ const small_short direc[NO_PTYPE_PIECES][8] = small_short diagonal(short d) { - return (abs(d) == 10 || abs(d) == 12); + return (abs(d) == (NO_COLS+1) || abs(d) == (NO_COLS+3)); } @@ -512,7 +512,7 @@ Initialize_moves(void) short dest[8][9]; short sorted[9]; short steps[8]; - short fpo = 23, tpo = 120; + short fpo = inunmap[0], tpo = 1 + inunmap[NO_SQUARES-1]; for (ptyp = 0; ptyp < NO_PTYPE_PIECES; ptyp++) { diff --git a/gnushogi/rawdsp.c b/gnushogi/rawdsp.c index 0aeeb35..130773e 100644 --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@ -378,8 +378,8 @@ Raw_EditBoard(void) } else { - c = '9' - s[1]; - r = 'i' - s[2]; + c = COL_NAME(s[1]); + r = ROW_NAME(s[2]); } if ((c >= 0) && (c < NO_COLS) && (r >= 0) && (r < NO_ROWS)) diff --git a/gnushogi/util.c b/gnushogi/util.c index 2d17037..c831c6c 100644 --- a/gnushogi/util.c +++ b/gnushogi/util.c @@ -81,10 +81,10 @@ parse(FILE * fd, unsigned short *mv, short side, char *opening) return 0; } - c1 = '9' - s[0]; - r1 = 'i' - s[1]; - c2 = '9' - s[2]; - r2 = 'i' - s[3]; + c1 = COL_NAME(s[0]); + r1 = ROW_NAME(s[1]); + c2 = COL_NAME(s[2]); + r2 = ROW_NAME(s[3]); *mv = (locn(r1, c1) << 8) | locn(r2, c2); if (c == '?') -- 1.7.0.4