From 7c5f6ecf842604527da7c24a7ed873ef04bd616a Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Mon, 11 Feb 2008 01:47:00 +0100 Subject: [PATCH] Initial attempt at minishogi. This preliminar minishogi takes the approach of conditional compilation, so I can focus on differences between shogi and minishogi. Those ifdef's are expected to progressively disappear as the support code is made generic enough to support the needs of both variants. --- TODO | 28 +++++++++ gnushogi/attacks.c | 4 + gnushogi/commondsp.c | 23 +++++++- gnushogi/cursesdsp.c | 7 ++ gnushogi/eval.c | 93 ++++++++++++++++++++++++++++-- gnushogi/genmove.c | 28 ++++++++-- gnushogi/globals.c | 24 +++++++- gnushogi/gnushogi.h | 36 +++++++++++- gnushogi/init.c | 155 +++++++++++++++++++++++++++++++++++++++++++------ 9 files changed, 360 insertions(+), 38 deletions(-) create mode 100644 TODO diff --git a/TODO b/TODO new file mode 100644 index 0000000..12b25b5 --- /dev/null +++ b/TODO @@ -0,0 +1,28 @@ +Generic cleanups + +- hunt for more hardcoded variant-specific constants + - position of captured pieces in curses mode + - compile with bound-checker +- add autosave mode to ease hunt for segfaults ? +- generate patterns.inc at build-time +- use 2D array for the board, get rid of the (i)nunmap stuff +- fixup build procedure to support parallel make runs +- investigate those preexisting "overflow in implicit constant + conversion" warnings + +Minishogi-related stuff + +- make minishogi a run-time option rather than a compile-time one +- minishogi patterns +- tune difficulty levels +- other tunings to investigate + * PromotionZoneDistanceBonus + * OPENING_HINT +- add minishogi stuff to the doc +- use valid minishogi moves in online help + +- segfault (on level 1) following 2e1d 1d4a + => field.piece can reach 14 in pattern.c::update_advance_bonus + => probably related to using patterns for standard shogi + => must break the circular pattern.o <-> pattern.inc dep to + be able to generated pattern.inc as needed diff --git a/gnushogi/attacks.c b/gnushogi/attacks.c index 76c52ad..6f54d57 100644 --- a/gnushogi/attacks.c +++ b/gnushogi/attacks.c @@ -118,6 +118,7 @@ SqAttacked(short square, short side, short *blockable) } while (u != square); +#ifndef MINISHOGI /* try a knight capture (using xside's knight moves) */ ptyp = ptype[side ^ 1][knight]; @@ -141,6 +142,7 @@ SqAttacked(short square, short side, short *blockable) #endif } while (u != square); +#endif /* MINISHOGI */ *blockable = true; @@ -216,6 +218,7 @@ SqAttacked(short square, short side, short *blockable) } while (u != square); +#ifndef MINISHOGI /* try a lance capture (using xside's lance moves) */ ptyp = ptype[side ^ 1][lance]; @@ -248,6 +251,7 @@ SqAttacked(short square, short side, short *blockable) } } while (u != square); +#endif /* MINISHOGI */ return false; } diff --git a/gnushogi/commondsp.c b/gnushogi/commondsp.c index 17a639a..8750fcd 100644 --- a/gnushogi/commondsp.c +++ b/gnushogi/commondsp.c @@ -542,10 +542,12 @@ GetGame(void) skipb(); Captured[side][pawn] = atoi(InPtr); skip(); +#ifndef MINISHOGI Captured[side][lance] = atoi(InPtr); skip(); Captured[side][knight] = atoi(InPtr); skip(); +#endif Captured[side][silver] = atoi(InPtr); skip(); Captured[side][gold] = atoi(InPtr); @@ -710,16 +712,24 @@ SaveGame(void) } fputs(empty, fd); - fprintf(fd, " 9 8 7 6 5 4 3 2 1\n"); /* FIXME */ +#ifndef MINISHOGI + fprintf(fd, " 9 8 7 6 5 4 3 2 1\n"); fputs(empty, fd); fprintf(fd, " p l n s g b r k\n"); +#else + fprintf(fd, " 5 4 3 2 1\n"); + fputs(empty, fd); + fprintf(fd, " p s g b r k\n"); +#endif for (side = 0; side <= 1; side++) { fprintf(fd, "%c", (side == black) ? 'B' : 'W'); fprintf(fd, " %2d", Captured[side][pawn]); +#ifndef MINISHOGI fprintf(fd, " %2d", Captured[side][lance]); fprintf(fd, " %2d", Captured[side][knight]); +#endif fprintf(fd, " %2d", Captured[side][silver]); fprintf(fd, " %2d", Captured[side][gold]); fprintf(fd, " %2d", Captured[side][bishop]); @@ -871,10 +881,12 @@ GetXGame(void) InPtr = fname; Captured[side][pawn] = atoi(InPtr); skip(); +#ifndef MINISHOGI Captured[side][lance] = atoi(InPtr); skip(); Captured[side][knight] = atoi(InPtr); skip(); +#endif Captured[side][silver] = atoi(InPtr); skip(); Captured[side][gold] = atoi(InPtr); @@ -955,10 +967,17 @@ SaveXGame(void) for (side = 0; side <= 1; side++) { - sprintf(fname, "%d %d %d %d %d %d %d %d\n", + sprintf(fname, +#ifndef MINISHOGI + "%d %d %d %d %d %d %d %d\n", +#else + "%d %d %d %d %d %d\n", +#endif Captured[side][pawn], +#ifndef MINISHOGI Captured[side][lance], Captured[side][knight], +#endif Captured[side][silver], Captured[side][gold], Captured[side][bishop], diff --git a/gnushogi/cursesdsp.c b/gnushogi/cursesdsp.c index b32181b..906e44d 100644 --- a/gnushogi/cursesdsp.c +++ b/gnushogi/cursesdsp.c @@ -854,10 +854,17 @@ Curses_UpdateDisplay(short f, short t, short redraw, short isspec) gotoXY(3, 4 + 2*NO_ROWS); printw(" "); +#ifndef MINISHOGI if (flag.reverse) printw(" 1 2 3 4 5 6 7 8 9"); else printw(" 9 8 7 6 5 4 3 2 1"); +#else + if (flag.reverse) + printw(" 1 2 3 4 5"); + else + printw(" 1 2 3 4 5"); +#endif for (sq = 0; sq < NO_SQUARES; sq++) DrawPiece(sq); diff --git a/gnushogi/eval.c b/gnushogi/eval.c index 2a33986..272db91 100644 --- a/gnushogi/eval.c +++ b/gnushogi/eval.c @@ -44,6 +44,7 @@ int PUTVAR = false; /* shall the current scoring be cached? */ /* Pieces and colors of initial board setup */ +#ifndef MINISHOGI const small_short Stboard[NO_SQUARES] = { lance, knight, silver, gold, king, gold, silver, knight, lance, @@ -79,8 +80,27 @@ const small_short Stcolor[NO_SQUARES] = white, white, white, white, white, white, white, white, white }; +#else +const small_short Stboard[NO_SQUARES] = +{ + king, gold, silver, bishop, rook, + pawn, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, pawn, + rook, bishop, silver, gold, king, +}; +const small_short Stcolor[NO_SQUARES] = +{ + black, black, black, black, black, + black, neutral, neutral, neutral, neutral, + neutral, neutral, neutral, neutral, neutral, + neutral, neutral, neutral, neutral, white, + white, white, white, white, white +}; +#endif + /* Actual pieces and colors */ small_short board[NO_SQUARES], color[NO_SQUARES]; @@ -95,15 +115,19 @@ static small_short ispvalue[NO_PIECES][MAIN_STAGES] = { 0, 35, 70, 99 }, /* main stage borders */ /* ------------------------------------------ */ { 7, 7, 8, 10 }, /* Pawn */ +#ifndef MINISHOGI { 20, 35, 45, 60 }, /* Lance */ { 20, 35, 45, 60 }, /* Knight */ +#endif { 35, 40, 60, 80 }, /* Silver */ { 35, 50, 65, 80 }, /* Gold */ { 90, 90, 90, 90 }, /* Bishop */ { 95, 95, 95, 95 }, /* Rook */ { 15, 25, 40, 65 }, /* promoted Pawn */ +#ifndef MINISHOGI { 25, 45, 55, 65 }, /* promoted Lance */ { 25, 45, 55, 65 }, /* promoted Knight */ +#endif { 35, 55, 75, 75 }, /* promoted Silver */ { 99, 99, 99, 99 }, /* promoted Bishop */ { 97, 97, 99, 99 }, /* promoted Rook */ @@ -192,8 +216,13 @@ static const short OwnKingDistanceBonus[10] = { 0, 5, 2, 1, 0, -1, -2, -3, -4, -5 }; /* distance to promotion zone */ +#ifndef MINISHOGI static const int PromotionZoneDistanceBonus[NO_ROWS] = { 0, 0, 0, 0, 2, 6, 6, 8, 8 }; +#else +static const int PromotionZoneDistanceBonus[NO_ROWS] = +{ 0, 0, 2, 6, 8 }; /* FIXME ? */ +#endif #define MAX_BMBLTY 20 #define MAX_RMBLTY 20 @@ -207,12 +236,22 @@ static const short BMBLTY[MAX_BMBLTY] = static const short RMBLTY[MAX_RMBLTY] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 14, 16, 16, 16, 16 }; +#ifndef MINISHOGI /* Lance mobility bonus indexed by # reachable squares */ static const short LMBLTY[MAX_LMBLTY] = { 0, 0, 0, 0, 4, 6, 8, 10 }; +#endif static const short MBLTY[NO_PIECES] = -{ 0, 2, 1, 10, 5, 5, 1, 1, 5, 5, 5, 5, 1, 1, 4 }; +{ 0, 2, +#ifndef MINISHOGI + 1, 10, +#endif + 5, 5, 1, 1, 5, +#ifndef MINISHOGI + 5, 5, +#endif + 5, 1, 1, 4 }; static const short KTHRT[36] = { 0, -8, -20, -36, -52, -68, -80, -80, -80, -80, -80, -80, @@ -255,17 +294,30 @@ static small_short Mpawn [2][NO_SQUARES]; static small_short Msilver[2][NO_SQUARES]; static small_short Mgold [2][NO_SQUARES]; static small_short Mking [2][NO_SQUARES]; +#ifndef MINISHOGI static small_short Mlance [2][NO_SQUARES]; static small_short Mknight[2][NO_SQUARES]; +#endif static small_short Mbishop[2][NO_SQUARES]; static small_short Mrook [2][NO_SQUARES]; -static Mpiece_array Mpawn, Mlance, Mknight, Msilver, Mgold, - Mbishop, Mrook, Mking; +static Mpiece_array Mpawn, +#ifndef MINISHOGI + Mlance, Mknight, +#endif + Msilver, Mgold, Mbishop, Mrook, Mking; Mpiece_array *Mpiece[NO_PIECES] = -{ NULL, &Mpawn, &Mlance, &Mknight, &Msilver, &Mgold, &Mbishop, &Mrook, - &Mgold, &Mgold, &Mgold, &Mgold, &Mbishop, &Mrook, &Mking }; +{ NULL, &Mpawn, +#ifndef MINISHOGI + &Mlance, &Mknight, +#endif + &Msilver, &Mgold, &Mbishop, &Mrook, + &Mgold, +#ifndef MINISHOGI + &Mgold, &Mgold, +#endif + &Mgold, &Mbishop, &Mrook, &Mking }; static short c1, c2; @@ -478,11 +530,13 @@ CheckTargetPiece(short sq, short side) add_target(sq, side, 11); break; +#ifndef MINISHOGI case knight: /* vertically ahead if advanced */ /* FIXME: gotta love them magic numbers... */ if ((sq != 1) && (sq != 7) && (sq != 73) && (sq != 79)) add_target(sq, side, 11); break; +#endif } } @@ -847,6 +901,7 @@ BRLscan(short sq, short *mob) /* it's the first piece in the current direction */ if (color[u] == c1) { +#ifndef MINISHOGI /* own intercepting piece in x-ray attack */ if (upiece == lance) { @@ -861,6 +916,7 @@ BRLscan(short sq, short *mob) } } else +#endif { /* bishop or rook x-ray */ if ((upiece == bishop) && (board[u] == pawn) @@ -868,17 +924,20 @@ BRLscan(short sq, short *mob) { s += (ds = -2*fv1[HCLSD]); } +#ifndef MINISHOGI else if ((upiece == rook) && (board[u] == lance) && (GameType[c1] == STATIC_ROOK) && (column(u) == csq)) { s += (ds = fv1[XRAY]); } +#endif } } else { /* enemy's intercepting piece in pin attack */ +#ifndef MINISHOGI if (upiece == lance) { /* lance pin attack */ @@ -892,6 +951,7 @@ BRLscan(short sq, short *mob) } } else +#endif { /* bishop or rook pin attack */ if (board[u] == pawn) @@ -958,11 +1018,13 @@ BRLscan(short sq, short *mob) } else { +#ifndef MINISHOGI if (upiece == lance) { s += (ds = fv1[XRAY] / 2); } else +#endif { s += (ds = fv1[XRAY]); } @@ -1348,7 +1410,7 @@ PawnValue(short sq, short side) } - +#ifndef MINISHOGI /* * Calculate the positional value for a lance on 'sq'. */ @@ -1412,6 +1474,7 @@ KnightValue(short sq, short side) return s; } +#endif @@ -1636,6 +1699,7 @@ PPawnValue(short sq, short side) +#ifndef MINISHOGI /* * Calculate the positional value for a promoted lance on 'sq'. */ @@ -1665,6 +1729,7 @@ PKnightValue(short sq, short side) return s; } +#endif @@ -1785,8 +1850,10 @@ PieceValue(short sq, short side) s += (ds = BMBLTY[mob] * fv1[MOBILITY] / 100); else if ((piece == rook) || (piece == prook)) s += (ds = RMBLTY[mob] * fv1[MOBILITY] / 100); +#ifndef MINISHOGI else s += (ds = LMBLTY[mob] * fv1[MOBILITY] / 100); +#endif } else { @@ -1878,6 +1945,7 @@ PieceValue(short sq, short side) s += PawnValue(sq, side); break; +#ifndef MINISHOGI case lance: s += LanceValue(sq, side); break; @@ -1885,6 +1953,7 @@ PieceValue(short sq, short side) case knight: s += KnightValue(sq, side); break; +#endif case silver: s += SilverValue(sq, side); @@ -1910,6 +1979,7 @@ PieceValue(short sq, short side) s += PPawnValue(sq, side); break; +#ifndef MINISHOGI case plance: s += PLanceValue(sq, side); break; @@ -1917,6 +1987,7 @@ PieceValue(short sq, short side) case pknight: s += PKnightValue(sq, side); break; +#endif case psilver: s += PSilverValue(sq, side); @@ -2064,7 +2135,7 @@ ScoreCaptures(void) if ((m = seed[c1])) { - for (piece = lance, n = 0; piece <= rook; piece++) + for (piece = pawn+1, n = 0; piece <= rook; piece++) { if (Captured[c1][piece]) n++; @@ -2087,9 +2158,11 @@ ScoreCaptures(void) ds = RMBLTY[MAX_RMBLTY - 1]; break; +#ifndef MINISHOGI case lance: ds = LMBLTY[MAX_LMBLTY - 1]; break; +#endif default: ds = MBLTY[piece]; @@ -2382,8 +2455,10 @@ DetermineGameType(short side_to_move) GuessGameType(side_to_move); array_zero(Mpawn, sizeof(Mpawn)); +#ifndef MINISHOGI array_zero(Mlance, sizeof(Mlance)); array_zero(Mknight, sizeof(Mknight)); +#endif array_zero(Msilver, sizeof(Msilver)); array_zero(Mgold, sizeof(Mgold)); array_zero(Mbishop, sizeof(Mbishop)); @@ -2491,6 +2566,7 @@ DetermineStage(short side) stage = 30; } +#ifndef MINISHOGI /* Update stage depending on board features and attack balance value */ if (abs(ds = (mtl[side] - mtl[xside])) @@ -2505,6 +2581,7 @@ DetermineStage(short side) stage += (ds = db1); } +#endif for (c1 = black, c2 = white; c1 <= white; c1++, c2--) { @@ -2577,8 +2654,10 @@ DetermineStage(short side) /* Determine stage dependant weights */ ADVNCM[pawn] = 1; /* advanced pawn bonus increment */ +#ifndef MINISHOGI ADVNCM[lance] = 1; ADVNCM[knight] = 1; +#endif ADVNCM[silver] = 1; /* advanced silver bonus increment */ ADVNCM[gold] = 1; /* advanced gold bonus increment */ ADVNCM[bishop] = 1; diff --git a/gnushogi/genmove.c b/gnushogi/genmove.c index 8eb0e3d..9034b65 100644 --- a/gnushogi/genmove.c +++ b/gnushogi/genmove.c @@ -326,8 +326,10 @@ PromotionPossible(short color, short f, short t, short p) switch (p) { case pawn: +#ifndef MINISHOGI case lance: case knight: +#endif case silver: case bishop: case rook: @@ -358,6 +360,7 @@ NonPromotionPossible(short color, short f, : (generate_move_flags ? ILLEGAL_TRAPPED : false)); } +#ifndef MINISHOGI case lance: if (color == black) { @@ -385,6 +388,7 @@ NonPromotionPossible(short color, short f, ? true : (generate_move_flags ? ILLEGAL_TRAPPED : false)); } +#endif } return true; @@ -533,7 +537,11 @@ field_bonus(short ply, short side, short piece, /* CHECKME: is this right? */ if (((rvupiece == rvuboard) && (upiece == pawn)) - || (upiece == bishop) || (upiece == knight)) + || (upiece == bishop) +#ifndef MINISHOGI + || (upiece == knight) +#endif + ) { s++; /* The opposing pawn (piece) */ @@ -772,7 +780,11 @@ LinkMove(short ply, short f, { #ifdef TESUJIBONUS /* Look at non-promoting silver or knight */ - if (piece == silver || piece == knight) + if (piece == silver +#ifndef MINISHOGI + || piece == knight +#endif + ) { local_flag |= tesuji; /* Non-promotion */ s++; @@ -908,6 +920,7 @@ DropPossible(short piece, short side, short sq) GenUnmakeMove(side, f, sq, tempb, tempc, false); } } +#ifndef MINISHOGI else if (piece == lance) { if ((side == black) && (r == 8)) @@ -922,6 +935,7 @@ DropPossible(short piece, short side, short sq) else if ((side == white) && (r <= 1)) possible = (generate_move_flags ? ILLEGAL_TRAPPED : false); } +#endif return possible; } @@ -1110,9 +1124,13 @@ LinkPreventCheckDrops(short side, short xside, short ply) if (board[square = PieceList[side][0]] != king) return; - for (piece = lance; piece <= rook; piece++) /* FIXME */ + for (piece = pawn+1; piece <= rook; piece++) { - if (piece == lance || piece == bishop || piece == rook) + if ( +#ifndef MINISHOGI + piece == lance || +#endif + piece == bishop || piece == rook) { /* check for threat of xside piece */ ptyp = ptype[side][piece]; @@ -1639,7 +1657,7 @@ IsCheckmate(short side, short in_check, short blockable) * Drops are restricted for pawns, lances, and knights. */ - if (piece > knight) + if (piece >= silver) break; } } diff --git a/gnushogi/globals.c b/gnushogi/globals.c index d44d720..5f35626 100644 --- a/gnushogi/globals.c +++ b/gnushogi/globals.c @@ -116,12 +116,28 @@ const short kingP[3] = { 4, 76, 0 }; const small_short relative_value[NO_PIECES] = -{ 0, 1, 3, 4, 7, 9, 10, 12, - 2, 5, 6, 8, 11, 13, 14 }; +{ 0, 1, +#ifndef MINISHOGI + 3, 4, +#endif + 7, 9, 10, 12, + 2, +#ifndef MINISHOGI + 5, 6, +#endif +8, 11, 13, 14 }; const long control[NO_PIECES] = -{ 0, ctlP, ctlL, ctlN, ctlS, ctlG, ctlB, ctlR, - ctlPp, ctlLp, ctlNp, ctlSp, ctlBp, ctlRp, ctlK }; +{ 0, ctlP, +#ifndef MINISHOGI + ctlL, ctlN, +#endif + ctlS, ctlG, ctlB, ctlR, + ctlPp, +#ifndef MINISHOGI + ctlLp, ctlNp, +#endif + ctlSp, ctlBp, ctlRp, ctlK }; short stage, stage2; short balance[2]; diff --git a/gnushogi/gnushogi.h b/gnushogi/gnushogi.h index 8a16fc7..677d22c 100644 --- a/gnushogi/gnushogi.h +++ b/gnushogi/gnushogi.h @@ -164,11 +164,19 @@ extern void movealgbr(short m, char *s); #define SEEK_SET 0 #define SEEK_END 2 +#ifdef MINISHOGI +#define NO_PIECES 11 +#define MAX_CAPTURED 19 +#define NO_PTYPE_PIECES 11 +#define NO_COLS 5 +#define NO_ROWS 5 +#else #define NO_PIECES 15 #define MAX_CAPTURED 19 #define NO_PTYPE_PIECES 15 #define NO_COLS 9 #define NO_ROWS 9 +#endif #define NO_SQUARES (NO_COLS*NO_ROWS) #define ROW_NAME(n) ('a' + NO_ROWS - 1 - n) @@ -220,12 +228,18 @@ extern void movealgbr(short m, char *s); /* board properties */ +#ifndef MINISHOGI #define InBlackCamp(sq) ((sq) < 27) #define InWhiteCamp(sq) ((sq) > 53) +#else +#define InBlackCamp(sq) ((sq) < 5) +#define InWhiteCamp(sq) ((sq) > 19) +#endif #define InPromotionZone(side, sq) \ (((side) == black) ? InWhiteCamp(sq) : InBlackCamp(sq)) /* constants */ +/* FIXME ? */ #define OPENING_HINT 0x141d /* P7g-7f (20->29) */ /* truth values */ @@ -246,15 +260,20 @@ extern void movealgbr(short m, char *s); enum { no_piece = 0, pawn, +#ifndef MINISHOGI lance, knight, +#endif + /* start of pieces that can be dropped at any square */ silver, gold, bishop, rook, ppawn, +#ifndef MINISHOGI plance, pknight, +#endif psilver, pbishop, prook, @@ -265,8 +284,10 @@ enum { enum { ptype_no_piece = 0, ptype_pawn = 0, +#ifndef MINISHOGI ptype_lance, ptype_knight, +#endif ptype_silver, ptype_gold, ptype_bishop, @@ -275,8 +296,10 @@ enum { ptype_prook, ptype_king, ptype_wpawn, +#ifndef MINISHOGI ptype_wlance, ptype_wknight, +#endif ptype_wsilver, ptype_wgold }; @@ -303,10 +326,17 @@ enum { #endif /* move symbols */ +#ifndef MINISHOGI #define pxx (" PLNSGBRPLNSBRK ") #define qxx (" plnsgbrplnsbrk ") #define rxx ("ihgfedcba") #define cxx ("987654321") +#else +#define pxx (" PSGBRPSBRK ") +#define qxx (" psgbrpsbrk ") +#define rxx ("edcba") +#define cxx ("54321") +#endif /***************** Table limits ********************************************/ @@ -352,7 +382,7 @@ enum { #define MAXDEPTH 40 /* max depth a search can be carried */ #define MINDEPTH 2 /* min search depth =1 (no hint), >1 hint */ #define MAXMOVES 300 /* max number of half moves in a game */ -#define CPSIZE 235 /* size of lang file max */ +#define CPSIZE 241 /* size of lang file max */ #if defined SMALL_MEMORY # if defined SAVE_SSCORE @@ -755,7 +785,11 @@ typedef unsigned char next_array[NO_SQUARES][NO_SQUARES]; typedef small_short distdata_array[NO_SQUARES][NO_SQUARES]; extern const small_short inunmap[NO_SQUARES]; +#ifndef MINISHOGI extern const small_short nunmap[(NO_COLS + 2)*(NO_ROWS + 4)]; +#else +extern const small_short nunmap[(NO_COLS + 2)*(NO_ROWS + 2)]; +#endif #if defined SAVE_NEXTPOS extern const small_short direc[NO_PTYPE_PIECES][8]; diff --git a/gnushogi/init.c b/gnushogi/init.c index 3ae048d..819e738 100644 --- a/gnushogi/init.c +++ b/gnushogi/init.c @@ -77,15 +77,32 @@ unsigned int ttbllimit; const small_short piece_of_ptype[NO_PTYPE_PIECES] = { - pawn, lance, knight, silver, gold, bishop, rook, pbishop, prook, king, - pawn, lance, knight, silver, gold + pawn, +#ifndef MINISHOGI + lance, knight, +#endif + silver, gold, bishop, rook, pbishop, prook, king, + pawn, +#ifndef MINISHOGI + lance, knight, +#endif + silver, gold }; +/* FIXME: all bishops and rooks are black ? */ const small_short side_of_ptype[NO_PTYPE_PIECES] = { - black, black, black, black, black, black, black, black, black, black, - white, white, white, white, white + black, +#ifndef MINISHOGI + black, black, +#endif + black, black, black, black, black, black, black, + white, +#ifndef MINISHOGI + white, white, +#endif + white, white }; #ifdef SAVE_NEXTPOS @@ -98,8 +115,16 @@ const small_short psweep[NO_PTYPE_PIECES] = const small_short sweep[NO_PIECES] = { - false, false, true, false, false, false, true, true, - false, false, false, false, true, true, false + false, false, +#ifndef MINISHOGI + true, false, +#endif + false, false, true, true, + false, +#ifndef MINISHOGI + false, false, +#endif + false, true, true, false }; @@ -136,6 +161,7 @@ ptype_distance(short ptyp, short f, short t) else return drow; +#ifndef MINISHOGI case lance: if ((dcol != 0) || (drow < 1)) return CANNOT_REACH; @@ -149,6 +175,7 @@ ptype_distance(short ptyp, short f, short t) return CANNOT_REACH; else return (drow / 2); +#endif case silver: if (drow > 0) @@ -175,8 +202,10 @@ ptype_distance(short ptyp, short f, short t) case gold: case ppawn: +#ifndef MINISHOGI case pknight: case plance: +#endif case psilver: if (abs(dcol) == 0) return (abs(drow)); @@ -328,38 +357,78 @@ Initialize_dist(void) const small_short ptype[2][NO_PIECES] = { { - ptype_no_piece, ptype_pawn, ptype_lance, ptype_knight, + ptype_no_piece, ptype_pawn, +#ifndef MINISHOGI + ptype_lance, ptype_knight, +#endif ptype_silver, ptype_gold, ptype_bishop, ptype_rook, - ptype_gold, ptype_gold, ptype_gold, ptype_gold, + ptype_gold, +#ifndef MINISHOGI + ptype_gold, ptype_gold, +#endif + ptype_gold, ptype_pbishop, ptype_prook, ptype_king }, { - ptype_no_piece, ptype_wpawn, ptype_wlance, ptype_wknight, + ptype_no_piece, ptype_wpawn, +#ifndef MINISHOGI + ptype_wlance, ptype_wknight, +#endif ptype_wsilver, ptype_wgold, ptype_bishop, ptype_rook, - ptype_wgold, ptype_wgold, ptype_wgold, ptype_wgold, + ptype_wgold, +#ifndef MINISHOGI + ptype_wgold, ptype_wgold, +#endif + ptype_wgold, ptype_pbishop, ptype_prook, ptype_king }, }; const small_short promoted[NO_PIECES] = { - no_piece, ppawn, plance, pknight, psilver, gold, pbishop, prook, - ppawn, plance, pknight, psilver, pbishop, prook, king + no_piece, ppawn, +#ifndef MINISHOGI + plance, pknight, +#endif + psilver, gold, pbishop, prook, + ppawn, +#ifndef MINISHOGI + plance, pknight, +#endif + psilver, pbishop, prook, king }; const small_short unpromoted[NO_PIECES] = { - no_piece, pawn, lance, knight, silver, gold, bishop, rook, - pawn, lance, knight, silver, bishop, rook, king + no_piece, pawn, +#ifndef MINISHOGI + lance, knight, +#endif + silver, gold, bishop, rook, + pawn, +#ifndef MINISHOGI + lance, knight, +#endif + silver, bishop, rook, king }; const small_short is_promoted[NO_PIECES] = { - false, false, false, false, false, false, false, false, - true, true, true, true, true, true, false + false, false, +#ifndef MINISHOGI + false, false, +#endif + false, false, false, false, + true, +#ifndef MINISHOGI + true, true, +#endif + true, true, true, false }; /* data used to generate nextpos/nextdir */ +#ifndef MINISHOGI +/* FIXME: use predefined constants ! */ #if !defined SAVE_NEXTPOS static #endif @@ -379,8 +448,27 @@ const small_short direc[NO_PTYPE_PIECES][8] = { -11, 0, 0, 0, 0, 0, 0, 0 }, /* 11 ptype_wlance */ { -21, -23, 0, 0, 0, 0, 0, 0 }, /* 12 ptype_wknight */ { -10, -11, -12, 12, 10, 0, 0, 0 }, /* 13 ptype_wsilver */ - { -10, -11, -12, 1, -1, 11, 0, 0 } -}; /* 14 ptype_wgold */ + { -10, -11, -12, 1, -1, 11, 0, 0 } /* 14 ptype_wgold */ +}; +#else +#if !defined SAVE_NEXTPOS +static +#endif +const small_short direc[NO_PTYPE_PIECES][8] = +{ + { 7, 0, 0, 0, 0, 0, 0, 0 }, /* 0 ptype_pawn */ + { 6, 7, 8, -8, -6, 0, 0, 0 }, /* 3 ptype_silver */ + { 6, 7, 8, -1, 1, -7, 0, 0 }, /* 4 ptype_gold */ + { 6, 8, -8, -6, 0, 0, 0, 0 }, /* 5 ptype_bishop */ + { 7, -1, 1, -7, 0, 0, 0, 0 }, /* 6 ptype_rook */ + { 6, 8, -8, -6, 7, -1, 1, -7 }, /* 7 ptype_pbishop */ + { 7, -1, 1, -7, 6, 8, -8, -6 }, /* 8 ptype_prook */ + { 6, 7, 8, -1, 1, -8, -7, -6 }, /* 9 ptype_king */ + { -7, 0, 0, 0, 0, 0, 0, 0 }, /* 10 ptype_wpawn */ + { -6, -7, -8, 8, 6, 0, 0, 0 }, /* 13 ptype_wsilver */ + { -6, -7, -8, 1, -1, 7, 0, 0 } /* 14 ptype_wgold */ +}; +#endif small_short diagonal(short d) @@ -389,12 +477,20 @@ small_short diagonal(short d) } +#ifndef MINISHOGI +/* FIXME */ static const small_short max_steps[NO_PTYPE_PIECES] = { 1, 8, 1, 1, 1, 8, 8, 8, 8, 1, 1, 8, 1, 1, 1 }; +#else +static const small_short max_steps[NO_PTYPE_PIECES] = +{ + 1, 1, 1, 4, 4, 4, 4, 1, 1, 1, 1 +}; +#endif - +#ifndef MINISHOGI const small_short nunmap[(NO_COLS + 2)*(NO_ROWS + 4)] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, @@ -425,8 +521,29 @@ const small_short inunmap[NO_SQUARES] = 100, 101, 102, 103, 104, 105, 106, 107, 108, 111, 112, 113, 114, 115, 116, 117, 118, 119 }; +#else +const small_short nunmap[(NO_COLS + 2)*(NO_ROWS + 2)] = +{ + -1, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, -1, + -1, 5, 6, 7, 8, 9, -1, + -1, 10, 11, 12, 13, 14, -1, + -1, 15, 16, 17, 18, 19, -1, + -1, 20, 21, 22, 23, 24, -1, + -1, -1, -1, -1, -1, -1, -1, +}; +const small_short inunmap[NO_SQUARES] = +{ + 8, 9, 10, 11, 12, + 15, 16, 17, 18, 19, + 22, 23, 24, 25, 26, + 29, 30, 31, 32, 33, + 36, 37, 38, 39, 40, +}; +#endif + int InitFlag = false; -- 1.7.0.4