X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=hachu.c;h=a81f25fcca8a9494ed18ffaaad11a49b7cf1f0c8;hb=0eecd39628e105c45f9baf11bcb785315517404b;hp=59fbacf509586fe170a8770e9acc40da4f9d8631;hpb=62077784733af1f94035193b31f3e3379b8a4340;p=hachu.git diff --git a/hachu.c b/hachu.c index 59fbacf..a81f25f 100644 --- a/hachu.c +++ b/hachu.c @@ -11,16 +11,21 @@ // promotions by pieces with Lion power stepping in & out the zone in same turn // promotion on capture -#define VERSION "0.1beta" +#define VERSION "0.7beta" #define PATH level==0 || path[0] == 0xc4028 && (level==1 /*|| path[1] == 0x75967 && (level == 2 || path[2] == 0x3400b && (level == 3))*/) //define PATH 0 +#define HASH +#define KILLERS +#define NULLMOVE + #include #include #include #include #include +#include #ifdef WIN32 # include @@ -40,7 +45,7 @@ #define BSIZE BWMAX*BHMAX #define ZONE zone -#define ONE (currentVariant == V_SHO || currentVariant == V_CHESS) +#define ONE (currentVariant == V_SHO || currentVariant == V_CHESS || currentVariant == V_SHATRANJ || currentVariant == V_MAKRUK) #define BLACK 0 #define WHITE 1 @@ -79,6 +84,21 @@ void pboard(int *b); void pbytes(unsigned char *b); typedef struct { + int lock[5]; + int move[5]; + short int score[5]; + char depth[5]; + char flag[5]; + char age[4]; +} HashBucket; + +HashBucket *hashTable; +int hashMask; + +#define H_UPPER 2 +#define H_LOWER 1 + +typedef struct { char *name, *promoted; int value; signed char range[8]; @@ -91,11 +111,13 @@ typedef struct { char fireMask; } UndoInfo; -char *array, *reason; -int bWidth, bHeight, bsize, zone, currentVariant; -int stm, xstm, hashKeyH, hashKeyL, framePtr, msp, nonCapts, rootEval, retMSP, retFirst, retDep, pvPtr, level, cnt50, chuFlag=1, tenFlag, mobilityScore; +char *array, fenArray[4000], *reason; +int bWidth, bHeight, bsize, zone, currentVariant, chuFlag, tenFlag, chessFlag, repDraws; +int stm, xstm, hashKeyH, hashKeyL, framePtr, msp, nonCapts, rootEval, retMSP, retFirst, retDep, pvPtr, level, cnt50, mobilityScore; int nodes, startTime, tlim1, tlim2, repCnt, comp; -Move retMove, moveStack[10000], path[100], repStack[300], pv[1000], repeatMove[300]; +Move retMove, moveStack[10000], path[100], repStack[300], pv[1000], repeatMove[300], killer[100][2]; + + int maxDepth; // used by search #define X 36 /* slider */ #define R 37 /* jump capture */ @@ -324,6 +346,26 @@ PieceDesc chessPieces[] = { { NULL } // sentinel }; +PieceDesc shatranjPieces[] = { + {"FK", "", 15, { 0,1,0,1,0,1,0,1 } }, + {"R", "", 50, { X,0,X,0,X,0,X,0 } }, + {"B", "", 9, { 0,J,0,J,0,J,0,J } }, + {"N", "", 30, { N,N,N,N,N,N,N,N } }, + {"K", "", 28, { 1,1,1,1,1,1,1,1 } }, + {"P", "FK", 8, { M,C,0,0,0,0,0,C } }, + { NULL } // sentinel +}; + +PieceDesc makrukPieces[] = { + {"SM","", 15, { 0,1,0,1,0,1,0,1 } }, + {"R", "", 50, { X,0,X,0,X,0,X,0 } }, + {"S", "", 20, { 1,1,0,1,0,1,0,1 } }, // silver + {"N", "", 30, { N,N,N,N,N,N,N,N } }, + {"K", "", 28, { 1,1,1,1,1,1,1,1 } }, + {"P", "SM", 8, { M,C,0,0,0,0,0,C } }, + { NULL } // sentinel +}; + char chuArray[] = "L:FLCSGK:DEGSC:FLL/:RV.B.:BT:KN:PH:BT.B.:RV/:SM:VMR:DH:DK:LN:FK:DK:DHR:VM:SM/PPPPPPPPPPPP/...:GB....:GB..." "/............/............/" "...:gb....:gb.../pppppppppppp/:sm:vmr:dh:dk:fk:ln:dk:dhr:vm:sm/:rv.b.:bt:ph:kn:bt.b.:rv/l:flcsg:dekgsc:fll"; @@ -337,6 +379,8 @@ char tenArray[] = "LN:FLICSGK:DEGSCI:FLNL/:RV.:CS:CS.:BT:KN:LN:FK:PH:BT.:CS:CS.: ":ss:vsb:dh:dk:wb:fi:fe:lh:fi:wb:dk:dhb:vs:ss/:rv.:cs:cs.:bt:ph:fk:ln:kn:bt.:cs:cs.:rv/ln:flicsg:dekgsci:flnl"; char shoArray[] = "LNSGKGSNL/.B..:DE..R./PPPPPPPPP/........./........./........./ppppppppp/.r..:de..b./lnsgkgsnl"; char chessArray[] = "RNBQKBNR/PPPPPPPP/......../......../......../......../pppppppp/rnbqkbnr"; +char shatArray[]= "RNBK:FKBNR/PPPPPPPP/......../......../......../......../pppppppp/rnbk:fkbnr"; +char thaiArray[]= "RNSK:SMSNR/......../PPPPPPPP/......../......../pppppppp/......../rnsk:smsnr"; typedef struct { int boardWidth, boardFiles, boardRanks, zoneDepth, varNr; // board sizes @@ -344,7 +388,7 @@ typedef struct { char *array; // initial position } VariantDesc; -typedef enum { V_CHESS, V_SHO, V_CHU, V_DAI, V_TENJIKU, V_DADA, V_MAKA, V_TAI, V_KYOKU } Variant; +typedef enum { V_CHESS, V_SHO, V_CHU, V_DAI, V_TENJIKU, V_DADA, V_MAKA, V_TAI, V_KYOKU, V_SHATRANJ, V_MAKRUK } Variant; VariantDesc variants[] = { { 16, 8, 8, 1, V_CHESS, "normal", chessArray }, // FIDE @@ -352,6 +396,9 @@ VariantDesc variants[] = { { 24, 12, 12, 4, V_CHU, "chu", chuArray }, // Chu { 30, 15, 15, 5, V_DAI, "dai", daiArray }, // Dai { 32, 16, 16, 5, V_TENJIKU, "tenjiku", tenArray }, // Tenjiku + { 16, 8, 8, 1, V_SHATRANJ,"shatranj",shatArray}, // Shatranj + { 16, 8, 8, 3, V_MAKRUK, "makruk", thaiArray}, // Makruk + // { 0, 0, 0, 0, 0 }, // sentinel { 34, 17, 17, 0, V_DADA, "dada", chuArray }, // Dai Dai { 38, 19, 19, 0, V_MAKA, "maka", chuArray }, // Maka Dai Dai @@ -532,6 +579,10 @@ LookUp (char *name, int var) return ListLookUp(name, chuPieces); case V_CHESS: // FIDE return ListLookUp(name, chessPieces); + case V_SHATRANJ: // Shatranj + return ListLookUp(name, shatranjPieces); + case V_MAKRUK: // Makruk + return ListLookUp(name, makrukPieces); } return NULL; } @@ -626,6 +677,7 @@ Compactify (int stm) } } for(i=stm+2; i= i) p[j].promo += 2; } if(royal[stm] >= i) royal[stm] += 2; - if(p[i].value == (currentVariant == V_SHO ? 410 : 280) ) royal[stm] = i; + if(p[i].value == (currentVariant == V_SHO ? 410 : 280) ) royal[stm] = i, p[i].pst = 0; p[i].qval = (currentVariant == V_TENJIKU ? list->ranking : 0); // jump-capture hierarchy return i; } @@ -667,14 +719,14 @@ void SetUp(char *array, int var) { int i, j, n, m, nr, color; - char c, *q, name[3]; + char c, *q, name[3], prince = 0; PieceDesc *p1, *p2; last[WHITE] = 1; last[BLACK] = 0; - if(var == V_CHESS) // add dummy Crown Princes - p[AddPiece(WHITE, LookUp("CP", V_CHU))].pos = p[AddPiece(BLACK, LookUp("CP", V_CHU))].pos = ABSENT; for(i=0; ; i++) { //printf("next rank: %s\n", array); for(j = BW*i; ; j++) { + int pflag=0; + if(*array == '+') pflag++, array++; c = name[0] = *array++; if(!c) goto eos; if(c == '.') continue; @@ -686,10 +738,14 @@ SetUp(char *array, int var) name[0] += 'A' - 'a'; if(name[1]) name[1] += 'A' - 'a'; } else color = WHITE; + if(!strcmp(name, "CP")) prince |= color+1; // remember if we added Crown Prince p1 = LookUp(name, var); + if(!p1) printf("tellusererror Unknown piece '%s' in setup\n", name), exit(-1); + if(pflag && p1->promoted) p1 = LookUp(p1->promoted, var); // use promoted piece instead n = AddPiece(color, p1); p[n].pos = j; - if(p1->promoted[0]) { + if(p1->promoted[0] && !pflag) { + if(!strcmp(p1->promoted, "CP")) prince |= color+1; // remember if we added Crown Prince p2 = LookUp(p1->promoted, var); m = AddPiece(color, p2); if(m <= n) n += 2; @@ -705,6 +761,9 @@ SetUp(char *array, int var) } } eos: + // add dummy Crown Princes if not yet added + if(!(prince & WHITE+1)) p[AddPiece(WHITE, LookUp("CP", V_CHU))].pos = ABSENT; + if(!(prince & BLACK+1)) p[AddPiece(BLACK, LookUp("CP", V_CHU))].pos = ABSENT; for(i=0; i<8; i++) fireFlags[i] = 0; for(i=2, n=1; i<10; i++) if(p[i].value == 10*FVAL) { int x = p[i].pos; // mark all burn zones @@ -738,6 +797,8 @@ Init (int var) bsize = bWidth*bHeight; chuFlag = (currentVariant == V_CHU); tenFlag = (currentVariant == V_TENJIKU); + chessFlag = (currentVariant == V_CHESS); + repDraws = (currentVariant == V_CHESS || currentVariant == V_SHATRANJ || currentVariant == V_MAKRUK); for(i= -1; i<9; i++) { // board steps in linear coordinates kStep[i] = STEP(direction[i&7].x, direction[i&7].y); // King @@ -789,7 +850,8 @@ Init (int var) // piece-square tables for(i=0; i= S && p[attacker].range[i] != J) { // has Knight jump in our direction + if(p[attacker].range[i] <= L && p[attacker].range[i] >= S || p[attacker].range[i] == N) { // has Knight jump in our direction NewCapture(x, sqr + victimValue, p[attacker].promoFlag); // plain jump (as in N) if(p[attacker].range[i] < N) { // Lion power; generate double captures over two possible intermediates int v = kStep[i]; // leftish path @@ -1500,6 +1576,9 @@ Search (int alpha, int beta, int difEval, int depth, int oldPromo, int promoSupp int score, bestScore, curEval, iterAlpha; Move move, nullMove; UndoInfo tb; +#ifdef HASH + Move hashMove; int index, nr, hit; +#endif if(PATH) /*pboard(board),pmap(attacks, BLACK),*/printf("search(%d) {%d,%d} eval=%d, stm=%d\n",depth,alpha,beta,difEval,stm),fflush(stdout); xstm = stm ^ WHITE; //printf("map made\n");fflush(stdout); @@ -1522,9 +1601,27 @@ if(PATH) /*pboard(board),pmap(attacks, BLACK),*/printf("search(%d) {%d,%d} eval= 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 - tb.fireMask = phase = 0; iterDep=1; replyDep = (depth < 1 ? depth : 1) - 1; - do { + + firstMove = curMove = sorted = msp += 50; // leave 50 empty slots in front of move list + iterDep = 0; tb.fireMask = phase = 0; + +#ifdef HASH + index = hashKeyL & hashMask; nr = hashKeyL >> 30; hit = -1; + if(hashTable[index].lock[nr] == hashKeyH) hit = nr; else + if(hashTable[index].lock[4] == hashKeyH) hit = 4; + if(hit >= 0) { + bestScore = hashTable[index].score[hit]; + if((bestScore <= alpha || hashTable[index].flag[hit] & H_LOWER) && + (bestScore >= beta || hashTable[index].flag[hit] & H_UPPER) ) { + iterDep = hashTable[index].depth[hit]; + } + } else { // decide on replacement + if(depth >= hashTable[index].depth[nr]) hit = nr; else hit = 4; + } +#endif + + replyDep = (depth < 1 ? depth : iterDep < 1 ? 1 : iterDep); + while(++iterDep <= depth) { if(flag && depth>= 0) printf("iter %d:%d\n", depth,iterDep),fflush(stdout); iterAlpha = alpha; bestScore = -INF; bestMoveNr = 0; resDep = 60; for(curMove = firstMove; ; curMove++) { // loop over moves @@ -1537,10 +1634,10 @@ if(flag && depth>= 0) printf("phase=%d: first/curr/last = %d / %d / %d\n", phase bestScore = curEval; resDep = QSdepth; if(bestScore >= beta || depth < -1) goto cutoff; } -#if 0 - if(curEval >= beta) { +#ifdef NULLMOVE + else if(curEval >= beta) { stm ^= WHITE; - score = -Search(-beta, -iterAlpha, difEval, depth-3, promoSuppress & SQUARE, ABSENT); + score = -Search(-beta, 1-beta, -difEval, depth > 3 ? depth-3 : 0, promoSuppress & SQUARE, ABSENT); stm ^= WHITE; if(score >= beta) { msp = oldMSP; retDep += 3; return score + (score < curEval); } } @@ -1549,6 +1646,12 @@ if(flag && depth>= 0) printf("phase=%d: first/curr/last = %d / %d / %d\n", phase //if(PATH) printf("mask=%x\n",tb.fireMask),pbytes(fireBoard); phase = 1; case 1: // hash move +#ifdef HASH + if(hashMove) { + moveStack[sorted = msp++] = hashMove; + goto extractMove; + } +#endif phase = 2; case 2: // capture-gen init nextVictim = xstm; @@ -1593,6 +1696,14 @@ if(PATH) printf("%d:%2d:%2d msp=%d\n",level,depth,iterDep,msp); case 6: // non-captures nonCapts = msp; nullMove = GenNonCapts(oldPromo); +#ifdef KILLERS + { // swap killers to front + Move h = killer[level][0]; int j = curMove; + for(i=curMove; i= 0) printf("%2d:%d extract %d/%d\n", depth, iterDep, curMove, msp); - if(curMove < sorted) { + if(curMove > sorted) { move = moveStack[sorted=j=curMove]; for(i=curMove+1; i move) move = moveStack[j=i]; // search move with highest priority @@ -1629,6 +1740,7 @@ if(flag & depth >= 0) printf("%2d:%d found %d/%d %08x %s\n", depth, iterDep, cur if(flag & depth >= 0) printf("%2d:%d made %d/%d %s\n", depth, iterDep, curMove, msp, MoveToText(moveStack[curMove], 0)); for(i=2; i<=cnt50; i+=2) if(repStack[level-i+200] == hashKeyH) { + if(repDraws) { score = 0; goto repetition; } moveStack[curMove] = 0; // erase forbidden move if(!level) repeatMove[repCnt++] = move & 0xFFFFFF; // remember outlawed move score = -INF; moveStack[curMove] = 0; goto repetition; @@ -1650,7 +1762,11 @@ MapFromScratch(attacks); // for as long as incremental update does not work. 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; } // zap illegal moves + if(score == -INF) { + if(level == 1) repeatMove[repCnt++] = move & 0xFFFFFF | (p[tb.piece].value == 10*LVAL ? 3<<24 : 1 << 24); + moveStack[curMove] = 0; // zap illegal moves + goto abortMove; + } } #if 1 score = -Search(-beta, -iterAlpha, -difEval - tb.booty, replyDep, promoSuppress & ~PROMOTE, defer); @@ -1683,7 +1799,12 @@ if(PATH) printf("%d:%2d:%d %3d %6x %-10s %6d %6d\n", level, depth, iterDep, curM } bestMoveNr = firstMove; if(score >= beta) { // beta cutoff - // update killer +#ifdef KILLERS + if(iterDep == depth && move != killer[level][0]) { + // update killer + killer[level][1] = killer[level][0]; killer[level][0] = move; + } +#endif resDep = retDep; goto cutoff; } @@ -1703,12 +1824,24 @@ if(PATH) printf("%d:%2d:%d %3d %6x %-10s %6d %6d\n", level, depth, iterDep, curM 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(iterDep == 1) printf(" { root eval = %4.2f dif = %4.2f; abs = %4.2f}", curEval/100., difEval/100., PSTest()/100.); + 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 +#ifdef HASH + // hash store + hashTable[index].lock[hit] = hashKeyH; + hashTable[index].depth[hit] = iterDep; + hashTable[index].flag[hit] = (bestScore < beta) * H_UPPER; + if(bestScore > alpha) { + hashTable[index].flag[hit] |= H_LOWER; + hashTable[index].move[hit] = bestMoveNr ? moveStack[bestMoveNr] : 0; + } else hashTable[index].move[hit] = 0; +#endif + } // next depth retMSP = msp; retFirst = firstMove; msp = oldMSP; // pop move list @@ -1790,14 +1923,12 @@ pmoves(int start, int end) #define INVALID 0 // some parameter of your engine - #define MAXMOVES 500 /* maximum game length */ - #define MAXPLY 60 /* maximum search depth */ + #define MAXMOVES 2000 /* maximum game length */ + #define MAXPLY 20 /* maximum search depth */ #define OFF 0 #define ON 1 -#define DEFAULT_FEN "" - typedef Move MOVE; int moveNr; // part of game state; incremented by MakeMove @@ -1842,18 +1973,74 @@ UnMake2 (MOVE move) sup2 = sup1; sup1 = sup0; } +char fenNames[] = "RV....DKDEFL..DHGB......SMLNKN..FK....BT..VM..PH...."; // pairs of char +char fenPromo[] = "WLDHSMSECPB R HFDE....WHFB..LNG ..DKVMFS..FO..FK...."; // pairs of char + +char * +Convert (char *fen) +{ + char *p = fenArray, *q, *rows[36], tmp[4000]; + int n=0; + printf("# convert FEN '%s'\n", fen); + q = strchr(fen, ' '); if(q) *q = 0; q = fen; + do { rows[n++] = q; q = strchr(q, '/'); if(!q) break; *q++ = 0; } while(1); + *tmp = 0; + while(--n >= 0) { strcat(tmp, rows[n]); if(n) strcat(tmp, "/"); } + fen = tmp; + printf("# flipped FEN '%s'\n", fen); + while(*fen) { + if(*fen == ' ') { *p = 0; break; } + if(n=atoi(fen)) fen++; // digits read + if(n > 9) fen++; // double digit + while(n-- > 0) *p++ = '.'; // expand to empty squares + if(isalpha(*fen)) { + char *table = fenNames; + n = *fen > 'Z' ? 'a' - 'A' : 0; + if((currentVariant == V_CHESS || currentVariant == V_SHATRANJ || currentVariant == V_MAKRUK) && *fen - n == 'N' // In Chess N is Knight, not Lion + || table[2* (*fen - 'A' - n)] == '.') *p++ = *fen; else { + *p++ = ':'; + *p++ = table[2* (*fen - 'A' - n)] + n; + *p++ = table[2* (*fen - 'A' - n)+1] + n; + } + } else *p++ = *fen; + fen++; + } + printf("# converted FEN '%s'\n", fenArray); + return fenArray; +} + int Setup2 (char *fen) { + int stm = WHITE; + if(fen) { + char *q = strchr(fen, '\n'); + if(q) *q = 0; + if(q = strchr(fen, ' ')) stm = (q[1] == 'b' ? BLACK : WHITE); // fen contains color field + if(strchr(fen, '.') || strchr(fen, ':')) array = fen; else array = Convert(fen); + } SetUp(array, currentVariant); sup0 = sup1 = sup2 = ABSENT; - rootEval = cnt50 = hashKeyH = hashKeyL = 0; - return WHITE; + rootEval = cnt50 = hashKeyH = hashKeyL = moveNr = 0; + return stm; } void SetMemorySize (int n) { +#ifdef HASH + static HashBucket *realHash; + static int oldSize; + int m = 1; + intptr_t l; + if(n != oldSize) { + if(oldSize) free(realHash); + while(m*sizeof(HashBucket) <= n*512) m <<= 1; + m *= 1024; hashMask = m - 1; + realHash = calloc(m + 1, sizeof(HashBucket)); + l = (intptr_t) realHash; hashTable = (HashBucket*) (l & ~63); // align with cache line + } +#endif } char * @@ -1861,6 +2048,7 @@ MoveToText (MOVE move, int multiLine) { static char buf[50]; int f = move>>SQLEN & SQUARE, g = f, t = move & SQUARE; + char *promoChar = ""; 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!) @@ -1876,7 +2064,8 @@ MoveToText (MOVE move, int multiLine) } t = g + toList[t - SPECIAL]; } - sprintf(buf+strlen(buf), "%c%d%c%d%s", f%BW+'a', f/BW+ONE, t%BW+'a', t/BW+ONE, move & PROMOTE ? "+" : ""); + if(move & PROMOTE) promoChar = currentVariant == V_MAKRUK ? "m" : repDraws ? "q" : "+"; + sprintf(buf+strlen(buf), "%c%d%c%d%s", f%BW+'a', f/BW+ONE, t%BW+'a', t/BW+ONE, promoChar); return buf; } @@ -1890,6 +2079,21 @@ ReadSquare (char *p, int *sqr) return 2 + (r + ONE > 9); } +int listStart, listEnd; +char boardCopy[BSIZE]; + +void +ListMoves () +{ // create move list on move stack + int i; + for(i=0; i< BSIZE; i++) boardCopy[i] = !!board[i]; +MapFromScratch(attacks); + postThinking--; repCnt = 0; tlim1 = tlim2 = 1e8; msp = 0; + Search(-INF-1, INF+1, 0, 1, sup1 & ~PROMOTE, sup2); + postThinking++; + listStart = retFirst; listEnd = retMSP; +} + MOVE ParseMove (char *moveText) { @@ -1910,19 +2114,17 @@ ParseMove (char *moveText) t2 = SPECIAL + 8*i + j; } 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 } - if(i>=retMSP) { // no exact match +printf("# moveNr = %d in {%d,%d}\n", i, listStart, listEnd); + if(i>=listEnd) { // no exact match if(deferred) { // but maybe non-sensical deferral int flags = p[board[f]].promoFlag; printf("# deferral of %d\n", deferred); @@ -1933,18 +2135,19 @@ printf("# deferral of %d\n", deferred); if(!(flags & promoBoard[f])) moveStack[i] |= DEFER; // came from outside zone, so essential deferral } } - if(i >= retMSP) { - for(i=retFirst; i= listEnd) { + for(i=listStart; i= retMSP ? INVALID : moveStack[i]); + return (i >= listEnd ? INVALID : moveStack[i]); } void @@ -1954,32 +2157,25 @@ Highlight(char *coords) char b[BSIZE], buf[2000], *q; for(i=0; i>SQLEN & SQUARE)) { int t = moveStack[i] & SQUARE; if(t >= SPECIAL) continue; - b[t] = (board[t] == EMPTY ? 'Y' : 'R'); cnt++; + b[t] = (!boardCopy[t] ? 'Y' : 'R'); cnt++; } } if(!cnt) { // no moves from given square if(sqr != lastPut) return; // refrain from sending empty FEN // we lifted a piece for second leg of move - for(i=retFirst; i>SQLEN & SQUARE)) { int e, t = moveStack[i] & SQUARE; if(t < SPECIAL) continue; // only special moves e = lastLift + epList[t - SPECIAL]; // decode t = lastLift + toList[t - SPECIAL]; if(e != sqr) continue; - b[t] = (board[t] == EMPTY ? 'Y' : 'R'); cnt++; + b[t] = (!boardCopy[t] ? 'Y' : 'R'); cnt++; } } if(!cnt) return; @@ -2007,9 +2203,10 @@ flag=0; int SearchBestMove (int stm, int timeLeft, int mps, int timeControl, int inc, int timePerMove, MOVE *move, MOVE *ponderMove) { - int score, targetTime, movesLeft = 50; + int score, targetTime, movesLeft = BW*BH/4 + 20; if(mps) movesLeft = mps - (moveNr>>1)%mps; targetTime = timeLeft*10 / (movesLeft + 2) + 1000 * inc; + if(moveNr < 30) targetTime *= 0.5 + moveNr/60.; // speedup in opening if(timePerMove > 0) targetTime = timeLeft * 5; startTime = GetTickCount(); tlim1 = 0.2*targetTime; @@ -2017,7 +2214,7 @@ SearchBestMove (int stm, int timeLeft, int mps, int timeControl, int inc, int ti nodes = 0; MapFromScratch(attacks); retMove = INVALID; repCnt = 0; - score = Search(-INF-1, INF+1, rootEval, 20, sup1, sup2); + score = Search(-INF-1, INF+1, rootEval, maxDepth, sup1, sup2); *move = retMove; *ponderMove = INVALID; return score; @@ -2031,7 +2228,7 @@ PonderUntilInput (int stm) int TakeBack(int n) { // reset the game and then replay it to the desired point int last, stm; - stm = Setup2(NULL); + Init(currentVariant); stm = Setup2(NULL); printf("# setup done");fflush(stdout); last = moveNr - n; if(last < 0) last = 0; for(moveNr=0; moveNr