From: H.G. Muller Date: Mon, 9 Jul 2012 15:12:37 +0000 (+0200) Subject: Implement Dai Shogi X-Git-Tag: 0.18~88 X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=5c1fa8b0d0076c229f483e7c868bdaa6f1103389;p=hachu.git Implement Dai Shogi The board format was made variable, and the relevant parameters are set during Init() according to the current variant (now passed as parameter). LookUp() now searches the requested piece in multiple lists, depending on the current variant. E.g. for Dai it searches daiPieces, followed by chuPieces. The WB variant command is now interpreted, by comparing the mentioned variat to the list of variants. Support for plain Knight moves was added. The suppression of promotions after an initial deferral was made subject to chuFlag. --- diff --git a/hachu.c b/hachu.c index 8ca5cc7..40c31e5 100644 --- a/hachu.c +++ b/hachu.c @@ -8,11 +8,10 @@ // TODO: // in GenCapts we do not generate jumps of more than two squares yet -// Chu rules for Lion capture // promotions by pieces with Lion power stepping in & out the zone in same turn // promotion on capture -#define VERSION "0.0" +#define VERSION "0.1beta" //define PATH level==0 || level==1 && path[0] == 0x55893 #define PATH 0 @@ -34,10 +33,12 @@ } #endif -#define BW 24 -#define BH 12 -#define BSIZE BW*BH*2 -#define ZONE 4 +#define BW bWidth +#define BH bHeight +#define BHMAX 15 +#define BWMAX (2*BHMAX) +#define BSIZE BWMAX*BHMAX +#define ZONE zone #define ONE 0 @@ -85,13 +86,14 @@ typedef struct { int from, to, piece, victim, new, booty, epSquare, epVictim, ep2Square, ep2Victim, revMoveCount, savKeyL, savKeyH; } UndoInfo; +int bWidth, bHeight, bsize, zone, currentVariant; int stm, xstm, hashKeyH, hashKeyL, framePtr, msp, nonCapts, rootEval, retMSP, retFirst, pvPtr, level, cnt50, chuFlag=1; int nodes, startTime, tlim1, tlim2; Move retMove, moveStack[10000], path[100], repStack[300], pv[1000]; #define X 36 /* slider */ -#define J -1 /* jump */ -#define N -2 /* Knight */ +#define N -1 /* Knight */ +#define J -2 /* jump */ #define D -3 /* linear double move */ #define T -4 /* linear triple move */ #define L -5 /* true Lion move */ @@ -268,7 +270,7 @@ char daiArray[] = "LN:STICSGKGSCI:STNL/:RV.:CS.:FL.:BT:DE:BT.:FL.:CS.:RV/.:VO.:A "r:fd:sm:vmb:dh:dk:fk:dk:dhb:vm:sm:fdr/.:vo.:ab.:ew:ph:ln:kn:ew.:ab.:vo./:rv.:cs.:fl.:bt:de:bt.:fl.:cs.:rv/ln:sticsgkgsci:stnl"; typedef struct { - int boardWidth, boardFiles, zoneDepth, boardRanks; // board sizes + int boardWidth, boardFiles, boardRanks, zoneDepth; // board sizes char *name; // WinBoard name char *array; // initial position } VariantDesc; @@ -418,24 +420,37 @@ typedef struct { int squareKey[BSIZE]; -int rawBoard[BSIZE + 11*BW + 6]; +int rawBoard[BSIZE + 11*BHMAX + 6]; //int attacks[2*BSIZE]; // attack map int attackMaps[200*BSIZE], *attacks = attackMaps; char distance[2*BSIZE]; // distance table char promoBoard[BSIZE]; signed char PST[2*BSIZE]; -#define board (rawBoard + 6*BW + 3) +#define board (rawBoard + 6*BHMAX + 3) #define dist (distance + BSIZE) PieceDesc * -LookUp (char *name, PieceDesc *list) +ListLookUp (char *name, PieceDesc *list) { // find piece of given name in list of descriptors int i=0; while(list->name && strcmp(name, list->name)) i++, list++; return (list->name == NULL ? NULL : list); } +PieceDesc * +LookUp (char *name, int var) +{ // search piece of given name in all lists relevant for given variant + PieceDesc *desc; + switch(var) { + case 1: // Dai + desc = ListLookUp(name, daiPieces); + if(desc) return desc; + case 0: // Chu + return ListLookUp(name, chuPieces); + } +} + void SqueezeOut (int n) { // remove piece number n from the mentioned side's piece list (and adapt the reference to the displaced pieces!) @@ -528,8 +543,8 @@ AddPiece (int stm, PieceDesc *list) for(j=0; j<8; j++) p[i].range[j] = list->range[j^4*(WHITE-stm)]; switch(Range(p[i].range)) { case 1: p[i].pst = BH; break; - case 2: p[i].pst = BSIZE; break; - default: p[i].pst = BSIZE + BH; break; + case 2: p[i].pst = bsize; break; + default: p[i].pst = bsize + BH; break; } key = (stm == WHITE ? &list->whiteKey : &list->blackKey); if(!*key) *key = ~(myRandom()*myRandom()); @@ -544,7 +559,7 @@ AddPiece (int stm, PieceDesc *list) } void -SetUp(char *array, PieceDesc *list) +SetUp(char *array, int var) { int i, j, n, m, nr, color; char c, *q, name[3]; @@ -564,11 +579,11 @@ SetUp(char *array, PieceDesc *list) name[0] += 'A' - 'a'; if(name[1]) name[1] += 'A' - 'a'; } else color = WHITE; - p1 = LookUp(name, list); + p1 = LookUp(name, var); n = AddPiece(color, p1); p[n].pos = j; if(p1->promoted[0]) { - p2 = LookUp(p1->promoted, list); + p2 = LookUp(p1->promoted, var); m = AddPiece(color, p2); if(m <= n) n += 2; p[n].promo = m; @@ -595,10 +610,17 @@ int myRandom() } void -Init() +Init (int var) { int i, j, k; + currentVariant = var; + bWidth = variants[var].boardWidth; + bHeight = variants[var].boardRanks; + zone = variants[var].zoneDepth; + bsize = bWidth*bHeight; + chuFlag = (var == 0); + for(i= -1; i<9; i++) { // board steps in linear coordinates kStep[i] = STEP(direction[i&7].x, direction[i&7].y); // King nStep[i] = STEP(direction[(i&7)+8].x, direction[(i&7)+8].y); // Knight @@ -620,7 +642,7 @@ Init() } // fill distance table - for(i=0; i= S) { // in any case, do a jump of 2 NewNonCapture(x, x + 2*v, pFlag); - if(r < N) { // Lion power, also single step + if(r < J) { // Lion power, also single step if(!NewNonCapture(x, x + v, pFlag)) nullMove = x; if(r == L) { // true Lion, also Knight jump v = nStep[j]; @@ -806,6 +831,11 @@ MapOneColor (int start, int last, int *map) for(j=0; j<8; j++) { int x = p[i].pos, v = kStep[j], r = p[i].range[j]; if(r < 0) { // jumping piece, special treatment + if(r == N) { + x += nStep[j]; + if(board[x] != EMPTY && board[x] != EDGE) + map[2*x + start] += one[8]; + } else if(r >= S) { // in any case, do a jump of 2 if(board[x + 2*v] != EMPTY && board[x + 2*v] != EDGE) map[2*(x + 2*v) + start] += one[j]; @@ -850,7 +880,7 @@ void MapFromScratch (int *map) { int i; - for(i=0; i<2*BSIZE; i++) map[i] = 0; + for(i=0; i<2*bsize; i++) map[i] = 0; MapOneColor(0, last[BLACK], map); MapOneColor(1, last[WHITE], map); } @@ -1374,7 +1404,7 @@ if(flag & depth >= 0) printf("%2d:%d found %d/%d\n", depth, iterDep, curMove, ms repStack[level+200] = hashKeyH; path[level++] = move; -attacks += 2*BSIZE; +attacks += 2*bsize; MapFromScratch(attacks); // for as long as incremental update does not work. if(PATH) pmap(attacks, stm); if(chuFlag && p[tb.victim].value == 1000) { // verify legality of Lion capture in Chu Shogi @@ -1394,7 +1424,7 @@ if(PATH) pmap(attacks, stm); score = 0; #endif abortMove: -attacks -= 2*BSIZE; +attacks -= 2*bsize; level--; repetition: UnMake(&tb); @@ -1577,7 +1607,7 @@ UnMake2 (MOVE move) int Setup2 (char *fen) { - SetUp(chuArray, chuPieces); + SetUp(variants[currentVariant].array, currentVariant); sup0 = sup1 = sup2 = ABSENT; rootEval = cnt50 = hashKeyH = hashKeyL = 0; return WHITE; @@ -1676,7 +1706,7 @@ Highlight(char *coords) { int i, j, n, sqr, cnt=0; char b[BSIZE], buf[2000], *q; - for(i=0; i