X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=hachu.c;h=176039f10eb1292fdb165bfb1747d89eebfb7728;hb=135d8ffb60839a6863d423a8c383b996ed0c937b;hp=3ea559922874c6c942e2faaf90a24cdf65837e7c;hpb=8ff569a627c4e9bae3f2dc54e3aa43d595002439;p=hachu.git diff --git a/hachu.c b/hachu.c index 3ea5599..176039f 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 @@ -46,7 +47,7 @@ #define EMPTY 0 #define EDGE (1<<11) #define TYPE (WHITE|BLACK|EDGE) -#define ABSENT 4095 +#define ABSENT 2047 #define INF 8000 #define NPIECES 2000 /* length of piece list */ @@ -78,19 +79,21 @@ typedef struct { char *name, *promoted; int value; signed char range[8]; + int whiteKey, blackKey; } PieceDesc; typedef struct { - int from, to, piece, victim, new, booty, epSquare, epVictim, ep2Square, ep2Victim, savKeyL, savKeyH; + int from, to, piece, victim, new, booty, epSquare, epVictim, ep2Square, ep2Victim, revMoveCount, savKeyL, savKeyH; } UndoInfo; -int stm, xstm, hashKeyH, hashKeyL, framePtr, msp, nonCapts, rootEval, retMSP, retFirst, level, chuFlag=1; +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]; +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 */ @@ -267,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; @@ -408,23 +411,44 @@ typedef struct { char age; } HashEntry; // hash-table entry + // Some global variables that control your engine's behavior + int ponder; + int randomize; + int postThinking; + int resign; // engine-defined option + int contemptFactor; // likewise + 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) -int LookUp(char *name, PieceDesc *list) +PieceDesc * +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 ? -1 : i); + 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 @@ -507,21 +531,24 @@ Compactify (int stm) } int -AddPiece (int stm, int n, PieceDesc *list) +AddPiece (int stm, PieceDesc *list) { - int i, j; + int i, j, *key; for(i=stm+2; i<=last[stm]; i += 2) { - if(p[i].value < 10*list[n].value || p[i].value == 10*list[n].value && (p[i].promo < 0)) break; + if(p[i].value < 10*list->value || p[i].value == 10*list->value && (p[i].promo < 0)) break; } last[stm] += 2; for(j=last[stm]; j>i; j-= 2) p[j] = p[j-2]; - p[i].value = 10*list[n].value; - for(j=0; j<8; j++) p[i].range[j] = list[n].range[j^4*(WHITE-stm)]; + p[i].value = 10*list->value; + 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()); + p[i].pieceKey = *key; p[i].promoFlag = 0; for(j=stm+2; j<= last[stm]; j+=2) { if(p[j].promo >= i) p[j].promo += 2; @@ -532,10 +559,11 @@ AddPiece (int stm, int n, PieceDesc *list) } void -SetUp(char *array, PieceDesc *list) +SetUp(char *array, int var) { - int i, j, k, k2, n, m, nr, color; + int i, j, n, m, nr, color; char c, *q, name[3]; + PieceDesc *p1, *p2; last[WHITE] = 1; last[BLACK] = 0; for(i=0; ; i++) { //printf("next rank: %s\n", array); @@ -551,17 +579,17 @@ SetUp(char *array, PieceDesc *list) name[0] += 'A' - 'a'; if(name[1]) name[1] += 'A' - 'a'; } else color = WHITE; - k = LookUp(name, list); - n = AddPiece(color, k, list); + p1 = LookUp(name, var); + n = AddPiece(color, p1); p[n].pos = j; - if(list[k].promoted[0]) { - k2 = LookUp(list[k].promoted, list); - m = AddPiece(color, k2, list); + if(p1->promoted[0]) { + p2 = LookUp(p1->promoted, var); + m = AddPiece(color, p2); if(m <= n) n += 2; p[n].promo = m; - p[n].promoFlag = IsUpwardCompatible(list[k2].range, list[k].range) * DONT_DEFER + CAN_PROMOTE; - if(Forward(list[k].range)) p[n].promoFlag |= LAST_RANK; // Pieces that only move forward can't defer on last rank - if(!strcmp(list[k].name, "N")) p[n].promoFlag |= CANT_DEFER; // Knights can't defer on last 2 ranks + p[n].promoFlag = IsUpwardCompatible(p2->range, p1->range) * DONT_DEFER + CAN_PROMOTE; + if(Forward(p1->range)) p[n].promoFlag |= LAST_RANK; // Pieces that only move forward can't defer on last rank + if(!strcmp(p1->name, "N")) p[n].promoFlag |= CANT_DEFER; // Knights can't defer on last 2 ranks p[n].promoFlag &= n&1 ? P_WHITE : P_BLACK; p[m].promo = -1; p[m].pos = ABSENT; @@ -582,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 @@ -607,7 +642,7 @@ Init() } // fill distance table - for(i=0; i= -3) { // in any case, do a jump of 2 - if(board[x + 2*v] == EMPTY) - ADDMOVE(x, x+2*v); - if(r < -1) { // Lion power, also single step - if(board[x + v] == EMPTY) - ADDMOVE(x, x+v); - if(r == -3) { // true Lion, also Knight jump - v = nStep[j]; - if(board[x + v] == EMPTY) - ADDMOVE(x, x+v); - } - } - } - continue; - } - y = x; - while(r-- > 0) { - if(board[y+=v] == GUARD) break; // off board - if((board[y] + i & 1) == 0) break; // same color - } - } -} -#endif - int GenNonCapts (int promoSuppress) { @@ -756,13 +721,16 @@ GenNonCapts (int promoSuppress) for(i=stm+2; i<=last[stm]; i+=2) { int x = p[i].pos, pFlag = p[i].promoFlag; if(x == ABSENT) continue; - if(x == promoSuppress) pFlag = 0; + if(x == promoSuppress && chuFlag) pFlag = 0; for(j=0; j<8; j++) { int y, v = kStep[j], r = p[i].range[j]; if(r < 0) { // jumping piece, special treatment + if(r == N) { // pure Knightm do off-ray jump + NewNonCapture(x, x + nStep[j], pFlag); + } else if(r >= 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]; @@ -794,6 +762,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]; @@ -838,15 +811,15 @@ 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); } void Connect (int sqr, int piece, int dir) -{ - int x, step = kStep[dir], r1 = p[piece].range[dir], r2 = p[piece].range[dir+1], piece1, piece2; +{ // scan to both sides along ray to elongate attacks from there, and remove our own attacks on there, if needed + int x, step = kStep[dir], r1 = p[piece].range[dir], r2 = p[piece].range[dir+4], piece1, piece2; int d1, d2, r, y, c; if((attacks[2*sqr] + attacks[2*sqr+1]) & attackMask[dir]) { // there are incoming attack(s) from 'behind' @@ -865,15 +838,17 @@ Connect (int sqr, int piece, int dir) attacks[2*y + (piece1 & WHITE)] += one[dir]; // count attack UPDATE_MOBILITY(piece1, d2); } else UPDATE_MOBILITY(piece1, r1 - d1); // does not connect, but could still gain mobility - if(d1 + d2 <= (r2 = p[piece2].range[dir])) { // 2 hits 1 + if(d1 + d2 <= (r2 = p[piece2].range[dir+4])) { // 2 hits 1 attacks[2*x + (piece2 & WHITE)] += one[dir+4]; // count attack UPDATE_MOBILITY(piece2, d1); } else UPDATE_MOBILITY(piece2, r2 - d2); // does not connect, but could still gain mobility + // if r1 or r2<0, moves typically jump, and thus cannot be unblocked. Exceptions are FF and BS distant moves. + // test for d1+d2 > 2 && rN == F && d== 3 or rN == S } else { // we were only attacked from behind r = (r2 = p[piece1].range[dir]) - d1; - if(r < 0 || c > one[dir+1]) { // Oops! This was not our attacker, or not the only one. There must be a jump attack from even further behind! + if(r < 0 || c > one[dir+4]) { // Oops! This was not our attacker, or not the only one. There must be a jump attack from even further behind! // for now, forget jumpers } y = sqr; @@ -889,7 +864,7 @@ Connect (int sqr, int piece, int dir) } // we hit nothing with the extended move of the attacker behind us. UPDATE_MOBILITY(piece1, r2 - d1); - r = r1 - r2; // extra squares covered by mover + r = r1 - r2 + d1; // extra squares covered by mover while(r-- > 0) if(board[y+=step] != EMPTY) { d2 = dist[y-sqr]; piece2 = board[y]; @@ -899,6 +874,7 @@ Connect (int sqr, int piece, int dir) return; } } + // if r2<0 we should again test for F and S moves } else // no incoming attack from behind if(c = (attacks[2*sqr] + attacks[2*sqr+1]) & attackMask[dir+4]) { // but incoming attack(s) from 'ahead' @@ -923,7 +899,7 @@ Connect (int sqr, int piece, int dir) } // we hit nothing with the extended move of the attacker behind us. UPDATE_MOBILITY(piece2, r2 - d1); - r = r2 - r1; // extra squares covered by mover + r = r2 - r1 + d2; // extra squares covered by mover while(r-- > 0) if(board[x-=step] != EMPTY) { d1 = dist[x-sqr]; piece1 = board[x]; @@ -952,25 +928,64 @@ Connect (int sqr, int piece, int dir) } } +inline int +Hit (int r, int d) +{ // test if move with range r reaches over (un-obstructed) distance d + if(r < 0) switch(r) { + case J: return (d == 2); + case D: + case L: return (d <= 2); + case T: + case F: return (d <= 3); + case S: return 1; + default: return 0; + } else return (d <= r); + return 0; // not reached +} + void -Disconnect (int sqr, int dir) +Disconnect (int sqr, int piece, int dir) { - int x = sqr, step = kStep[dir], piece1, piece2, y; + int x = sqr, step = kStep[dir], piece1, piece2, d1, d2, r1, r2, y; while( board[x+=step] == EMPTY ); - if(board[x] != EDGE) { // x has hit a piece - piece1 = board[x]; + piece1 = board[x]; + if(piece1 != EDGE) { // x has hit a piece + d1 = dist[x-sqr]; + r1 = p[piece1].range[dir+4]; y = sqr; while( board[y-=step] == EMPTY ); - if(board[y] != EDGE) { // both ends of the ray hit a piece - piece2 = board[y]; - + piece2 = board[y]; + if(piece2 != EDGE) { // both ends of the ray hit a piece + d2 = dist[y-sqr]; + r2 = p[piece2].range[dir]; + if(r1 >= d1) { // piece1 hits us + attacks[2*sqr + (piece1 & WHITE)] += one[dir+4]; + if(r1 >= d1 + d2) // was hitting piece2 before, now blocked + attacks[2*y + (piece1 & WHITE)] -= one[dir+4]; + } + if(r2 >= d2) { // piece2 hits us + attacks[2*sqr + (piece2 & WHITE)] += one[dir]; + if(r2 >= d1 + d2) // was hitting piece1 before, now blocked + attacks[2*x + (piece2 & WHITE)] -= one[dir]; + } + if( Hit(p[piece].range[dir], d1) ) + attacks[2*sqr + stm] += one[dir]; + if( Hit(p[piece].range[dir+4], d2) ) + attacks[2*sqr + stm] += one[dir+4]; return; } } else { x = sqr; while( board[x-=step] == EMPTY ); - if(board[x] == EDGE) return; // ray empty on both sides + piece1 = board[x]; + if(piece1 == EDGE) return; // ray empty on both sides + d1 = dist[x-sqr]; + r1 = p[piece1].range[dir]; + dir += 4; } - // we only get here if one side hits a - + // we only get here if one side looks to the board edge + if(r1 >= d1) // piece1 hits us + attacks[2*sqr + (piece1 & WHITE)] += one[dir^4]; + if( Hit(p[piece].range[dir], d1) ) + attacks[2*sqr + stm] += one[dir]; } void @@ -978,7 +993,7 @@ Occupy (int sqr) { // determines attacks on square and blocking when a piece lands on an empty square int i; for(i=0; i<4; i++) { - Disconnect(sqr, i); + Disconnect(sqr, board[sqr], i); } } @@ -999,6 +1014,7 @@ MakeMove(Move m, UndoInfo *u) u->piece = board[u->from]; board[u->from] = EMPTY; u->booty = 0; + u->revMoveCount = cnt50++; u->savKeyL = hashKeyL; u->savKeyH = hashKeyH; @@ -1010,6 +1026,7 @@ MakeMove(Move m, UndoInfo *u) p[u->piece].pos = ABSENT; u->new = p[u->piece].promo; u->booty = p[u->new].value - p[u->piece].value; + cnt50 = 0; // promotion irreversible } } else u->new = u->piece; @@ -1035,12 +1052,13 @@ MakeMove(Move m, UndoInfo *u) hashKeyL ^= p[u->ep2Victim].pieceKey * squareKey[u->ep2Square]; hashKeyH ^= p[u->ep2Victim].pieceKey * squareKey[u->ep2Square+BH]; if(p[u->piece].value != 1000 && p[u->epVictim].value == 1000) deferred |= PROMOTE; // flag non-Lion x Lion + cnt50 = 0; // double capture irreversible } else u->epVictim = EMPTY; u->victim = board[u->to]; p[u->victim].pos = ABSENT; u->booty += p[u->victim].value + PST[p[u->victim].pst + u->to]; -// if(p[u->victim].value == 1000 && p[u->piece].value != 1000) deferred |= PROMOTE; // flag non-Lion x Lion + if(u->victim != EMPTY) cnt50 = 0; // capture irreversible p[u->new].pos = u->to; board[u->to] = u->new; @@ -1072,6 +1090,7 @@ UnMake(UndoInfo *u) p[u->piece].pos = u->from; // this can be the same as above board[u->from] = u->piece; + cnt50 = u->revMoveCount; hashKeyL = u->savKeyL; hashKeyH = u->savKeyH; } @@ -1190,6 +1209,7 @@ int Search (int alpha, int beta, int difEval, int depth, int oldPromo, int promoSuppress) { int i, j, k, firstMove, oldMSP = msp, curMove, sorted, bad, phase, king, iterDep, replyDep, nextVictim, to, defer, dubious, bestMoveNr; + int myPV = pvPtr; int score, bestScore, curEval, iterAlpha; Move move, nullMove; UndoInfo tb; @@ -1212,6 +1232,9 @@ if(PATH) printf("search(%d) %d-%d eval=%d, stm=%d\n",depth,alpha,beta,difEval,st alpha -= (alpha < curEval); beta -= (beta <= curEval); + nodes++; + pv[pvPtr++] = 0; // start empty PV, directly behind PV of parent + firstMove = curMove = sorted = msp += 20; // leave 20 empty slots in front of move list phase = 0; iterDep=1; replyDep = (depth < 1 ? depth : 1) - 1; do { @@ -1276,6 +1299,11 @@ if(flag && depth>= 0) printf("phase=%d: first/curr/last = %d / %d / %d\n", phase break; case 7: // bad captures case 8: // PV null move + phase = 9; + if(nullMove != ABSENT) { + moveStack[msp++] = nullMove + (nullMove << SQLEN) | DEFER; // kludge: setting DEFER guarantees != 0, and has no effect + } +printf("# %d. sqr = %08x null = %08x\n", msp, nullMove, moveStack[msp-1]); case 9: goto cutoff; } @@ -1295,11 +1323,19 @@ if(flag & depth >= 0) printf("%2d:%d extract %d/%d\n", depth, iterDep, curMove, if(move == 0) continue; // skip invalidated move } if(flag & depth >= 0) printf("%2d:%d found %d/%d\n", depth, iterDep, curMove, msp); + // RECURSION stm ^= WHITE; - defer = MakeMove(moveStack[curMove], &tb); -path[level++] = moveStack[curMove]; -attacks += 2*BSIZE; + defer = MakeMove(move, &tb); + + for(i=2; i<=cnt50; i+=2) if(repStack[level-i+200] == hashKeyH) { + moveStack[curMove] = 0; // erase forbidden move + score = -INF; goto repetition; + } + repStack[level+200] = hashKeyH; + +path[level++] = move; +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 @@ -1311,7 +1347,7 @@ if(PATH) pmap(attacks, stm); if(promoSuppress & PROMOTE) score = -INF; // non-Lion captures Lion after opponent did same defer |= PROMOTE; // if we started, flag he cannot do it in reply } - if(score == -INF) { moveStack[curMove] = 0; goto abortMove; } + if(score == -INF) { moveStack[curMove] = 0; goto abortMove; } // zap illegal moves } #if 1 score = -Search(-beta, -iterAlpha, -difEval - tb.booty, replyDep, promoSuppress & ~PROMOTE, defer); @@ -1319,14 +1355,14 @@ if(PATH) pmap(attacks, stm); score = 0; #endif abortMove: - - -attacks -= 2*BSIZE; +attacks -= 2*bsize; level--; + repetition: UnMake(&tb); xstm = stm; stm ^= WHITE; #if 1 if(PATH) printf("%d:%2d:%d %3d %6x %-10s %6d %6d\n", level, depth, iterDep, curMove, moveStack[curMove], MoveToText(moveStack[curMove], 0), score, bestScore); + // ALPHA-BETA STUFF if(score > bestScore) { bestScore = score; bestMoveNr = curMove; @@ -1347,6 +1383,10 @@ if(PATH) printf("%d:%2d:%d %3d %6x %-10s %6d %6d\n", level, depth, iterDep, curM // update killer goto cutoff; } + { int i=pvPtr; + for(pvPtr = myPV+1; pv[pvPtr++] = pv[i++]; ); // copy daughter PV + pv[myPV] = move; // behind our move (pvPtr left at end of copy) + } } } @@ -1354,13 +1394,20 @@ if(PATH) printf("%d:%2d:%d %3d %6x %-10s %6d %6d\n", level, depth, iterDep, curM } // next move cutoff: if(!level) { // root node + if(postThinking > 0) { + int i; // WB thinking output + printf("%d %d %d %d", iterDep, bestScore, (GetTickCount() - startTime)/10, nodes); + for(i=0; pv[i]; i++) printf(" %s", MoveToText(pv[i], 0)); + printf("\n"); fflush(stdout); + } if(GetTickCount() - startTime > tlim1) break; // do not start iteration we can (most likely) not finish } replyDep = iterDep; } while(++iterDep <= depth); // next depth retMSP = msp; retFirst = firstMove; - msp = oldMSP; + msp = oldMSP; // pop move list + pvPtr = myPV; // pop PV retMove = bestMoveNr ? moveStack[bestMoveNr] : 0; if(flag && depth >= 0) printf("return %d: %d %d\n", depth, bestScore, curEval); return bestScore + (bestScore < curEval); @@ -1468,26 +1515,32 @@ int lastLift, lastPut; int MakeMove2 (int stm, MOVE move) { + int i; sup0 = sup1; sup1 = sup2; sup2 = MakeMove(move, &undoInfo); rootEval = -rootEval - undoInfo.booty; + for(i=0; i<200; i++) repStack[i] = repStack[i+1]; + repStack[199] = hashKeyH; +printf("# makemove %08x %c%d %c%d\n", move, sup1%BW+'a', sup1/BW, sup2%BW+'a', sup2/BW); return stm ^ WHITE; } void UnMake2 (MOVE move) { + int i; rootEval = -rootEval - undoInfo.booty; UnMake(&undoInfo); + for(i=200; i>0; i--) repStack[i] = repStack[i-1]; sup2 = sup1; sup1 = sup0; } int Setup2 (char *fen) { - SetUp(chuArray, chuPieces); + SetUp(variants[currentVariant].array, currentVariant); sup0 = sup1 = sup2 = ABSENT; - rootEval = 0; + rootEval = cnt50 = hashKeyH = hashKeyL = 0; return WHITE; } @@ -1501,6 +1554,7 @@ MoveToText (MOVE move, int multiLine) { static char buf[50]; int f = move>>SQLEN & SQUARE, g = f, t = move & SQUARE; + if(f == t) { sprintf(buf, "@@@@"); return buf; } // null-move notation in WB protocol buf[0] = '\0'; if(t >= SPECIAL) { // kludgy! Print as side effect non-standard WB command to remove victims from double-capture (breaks hint command!) int e = f + epList[t - SPECIAL]; @@ -1533,6 +1587,7 @@ MOVE ParseMove (char *moveText) { int i, j, f, t, t2, e, ret, deferred=0; + char c = moveText[0]; moveText += ReadSquare(moveText, &f); moveText += ReadSquare(moveText, &t); t2 = t; if(*moveText == ',') { @@ -1549,9 +1604,14 @@ ParseMove (char *moveText) } ret = f<> SQLEN & SQUARE)) break; // any null move matches @@@@ if((moveStack[i] & (PROMOTE | DEFER-1)) == ret) break; if((moveStack[i] & DEFER-1) == ret) deferred = i; // promoted version of entered non-promotion is legal } @@ -1577,11 +1637,13 @@ Highlight(char *coords) { int i, j, n, sqr, cnt=0; char b[BSIZE], buf[2000], *q; - for(i=0; i>SQLEN & SQUARE)) { @@ -1630,10 +1692,10 @@ SearchBestMove (int stm, int timeLeft, int mps, int timeControl, int inc, int ti { int score, targetTime, movesLeft = 50; if(mps) movesLeft = mps - (moveNr>>1)%mps; - targetTime = timeLeft*10 / (movesLeft + 1) + 1000 * inc; + targetTime = timeLeft*10 / (movesLeft + 2) + 1000 * inc; if(timePerMove > 0) targetTime = timeLeft * 5; startTime = GetTickCount(); - tlim1 = 0.3*targetTime; + tlim1 = 0.2*targetTime; tlim2 = 1.9*targetTime; nodes = 0; MapFromScratch(attacks); @@ -1648,13 +1710,6 @@ PonderUntilInput (int stm) { } - // Some global variables that control your engine's behavior - int ponder; - int randomize; - int postThinking; - int resign; // engine-defined option - int contemptFactor; // likewise - int TakeBack(int n) { // reset the game and then replay it to the desired point int last, stm; @@ -1682,8 +1737,8 @@ printf("# setup done");fflush(stdout); int i, score; char inBuf[8000], command[80]; - Init(); - SetUp(chuArray, chuPieces); + Init(0); // Chu + SetUp(chuArray, 0); // pplist(); // pboard(board); // pbytes(promoBoard); @@ -1753,8 +1808,8 @@ printf("in: %s\n", command); } if(!strcmp(command, "protover")){ printf("feature ping=1 setboard=1 colors=0 usermove=1 memory=1 debug=1 sigint=0 sigterm=0\n"); - printf("feature variants=\"chu,12x12+0_fairy\"\n"); - printf("feature highlight=1\n"); + printf("feature variants=\"chu,dai,12x12+0_fairy\"\n"); + printf("feature myname=\"HaChu " VERSION "\" highlight=1\n"); printf("feature option=\"Resign -check 0\"\n"); // example of an engine-defined option printf("feature option=\"Contempt -spin 0 -200 200\"\n"); // and another one printf("feature done=1\n"); @@ -1765,6 +1820,15 @@ printf("in: %s\n", command); if(sscanf(inBuf+7, "Contempt=%d", &contemptFactor) == 1) continue; continue; } + if(!strcmp(command, "variant")) { + for(i=0; i<2; i++) { + sscanf(inBuf+8, "%s", command); + if(!strcmp(variants[i].name, command)) { + Init(i); stm = Setup2(NULL); break; + } + } + continue; + } if(!strcmp(command, "sd")) { sscanf(inBuf, "sd %d", &maxDepth); continue; } if(!strcmp(command, "st")) { sscanf(inBuf, "st %d", &timePerMove); continue; } if(!strcmp(command, "memory")) { SetMemorySize(atoi(inBuf+7)); continue; } @@ -1784,7 +1848,6 @@ printf("in: %s\n", command); if(!strcmp(command, "lift")) { Highlight(inBuf+5); continue; } if(!strcmp(command, "put")) { ReadSquare(inBuf+4, &lastPut); continue; } if(!strcmp(command, "book")) { continue; } - if(!strcmp(command, "variant")) { continue; } // non-standard commands if(!strcmp(command, "p")) { pboard(board); continue; } if(!strcmp(command, "w")) { pmap(attacks, WHITE); continue; } @@ -1796,6 +1859,7 @@ printf("in: %s\n", command); if(!strcmp(command, "ics")) { continue; } if(!strcmp(command, "accepted")){ continue; } if(!strcmp(command, "rejected")){ continue; } + if(!strcmp(command, "result")) { continue; } if(!strcmp(command, "hover")) { continue; } if(!strcmp(command, "")) { continue; } if(!strcmp(command, "usermove")){