X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=hachu.c;h=609f05e1480805aa73226e3087dd28016bae0b0e;hb=4ff6161c41af266165541bbc8b370c578b25342e;hp=ff5cc8f28dfc7d56817257ee7803dda00986cbb2;hpb=023af02b0b3c0643b612183f8670807b081125f4;p=hachu.git diff --git a/hachu.c b/hachu.c index ff5cc8f..609f05e 100644 --- a/hachu.c +++ b/hachu.c @@ -16,9 +16,9 @@ #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 +#define XHASH +#define XKILLERS +#define XNULLMOVE #include #include @@ -131,7 +131,7 @@ typedef struct { 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, tlim3, repCnt, comp, abortFlag; +int nodes, startTime, lastRootMove, lastRootIter, tlim1, tlim2, tlim3, repCnt, comp, abortFlag; Move ponderMove; Move retMove, moveStack[10000], path[100], repStack[300], pv[1000], repeatMove[300], killer[100][2]; @@ -1500,6 +1500,7 @@ GenCapts(int sqr, int victimValue) NewCapture(x, SPECIAL + 8*(i-1&7) + (i+1&7) + victimValue - SORTKEY(attacker), p[attacker].promoFlag); v = kStep[i+1]; if((board[x+v] & TYPE) == xstm && board[x+v] > board[sqr]) + NewCapture(x, SPECIAL + 8*(i+1&7) + (i-1&7) + victimValue - SORTKEY(attacker), p[attacker].promoFlag); } } else { // primary victim on first ring @@ -1640,9 +1641,10 @@ if(PATH) /*pboard(board),pmap(attacks, BLACK),*/printf("search(%d) {%d,%d} eval= } #endif - replyDep = (depth < 1 ? depth : iterDep < 1 ? 1 : iterDep); - while(++iterDep <= depth) { + replyDep = (depth < 1 ? depth-1 : iterDep); + while(++iterDep <= depth || iterDep == 1) { if(flag && depth>= 0) printf("iter %d:%d\n", depth,iterDep),fflush(stdout); + oldBest = bestScore; iterAlpha = alpha; bestScore = -INF; bestMoveNr = 0; resDep = 60; for(curMove = firstMove; ; curMove++) { // loop over moves if(flag && depth>= 0) printf("phase=%d: first/curr/last = %d / %d / %d\n", phase, firstMove, curMove, msp);fflush(stdout); @@ -1845,15 +1847,18 @@ if(PATH) printf("%d:%2d:%d %3d %6x %-10s %6d %6d\n", level, depth, iterDep, curM } // next move cutoff: if(!level) { // root node + lastRootIter = GetTickCount() - startTime; if(postThinking > 0) { int i; // WB thinking output - printf("%d %d %d %d", iterDep, bestScore, (GetTickCount() - startTime)/10, nodes); + printf("%d %d %d %d", iterDep, bestScore, lastRootIter/10, nodes); + if(ponderMove) printf(" (%s)", MoveToText(ponderMove, 0)); for(i=0; pv[i]; i++) printf(" %s", MoveToText(pv[i], 0)); 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 +printf("# s=%d t=%d 1=%d 3=%d f=%d\n",startTime,GetTickCount(),tlim1,tlim3,abortFlag); + if(!(abortFlag & 1) && GetTickCount() - startTime > tlim1) break; // do not start iteration we can (most likely) not finish } replyDep = iterDep; #ifdef HASH @@ -2261,6 +2266,9 @@ MapFromScratch(attacks); void PonderUntilInput (int stm) { +MapFromScratch(attacks); + repCnt = 0; abortFlag = -1; + Search(-INF-1, INF+1, rootEval, maxDepth, sup1, sup2); } int TakeBack(int n) @@ -2292,11 +2300,22 @@ printf("# setup done");fflush(stdout); // extract the first word sscanf(inBuf, "%s", command); +printf("# in (mode = %d,%d): %s\n", root, abortFlag, command); if(!strcmp(command, "otim")) { continue; } // do not start pondering after receiving time commands, as move will follow immediately if(!strcmp(command, "time")) { sscanf(inBuf, "time %d", &timeLeft); continue; } if(!strcmp(command, "put")) { ReadSquare(inBuf+4, &lastPut); continue; } // ditto if(!strcmp(command, ".")) { inBuf[0] = 0; return; } // ignore for now if(!strcmp(command, "lift")) { inBuf[0] = 0; Highlight(inBuf+5); return; } // treat here + if(!root && !strcmp(command, "usermove")) { + abortFlag = !!strcmp(inBuf+9, ponderMoveText); + if(!abortFlag) { // ponder hit, continue as time-based search + SetSearchTimes(10*timeLeft + GetTickCount() - startTime); // add time we already have been pondering to total + if(lastRootIter > tlim1) abortFlag = 2; // abort instantly if we are in iteration we should not have started + inBuf[0] = 0; ponderMove = INVALID; + return; + } + } + abortFlag = 1; return; } } @@ -2304,7 +2323,11 @@ printf("# setup done");fflush(stdout); void TerminationCheck() { + if(abortFlag < 0) { // check for input + if(InputWaiting()) GetLine(0); // read & examine input command + } else { // check for time if(GetTickCount() - startTime > tlim3) abortFlag = 2; + } } main() @@ -2314,10 +2337,12 @@ printf("# setup done");fflush(stdout); int i, score, curVarNr; Init(V_CHU); // Chu + listEnd = 1; while(1) { // infinite loop fflush(stdout); // make sure everything is printed before we do something that might take time + *inBuf = 0; if(listEnd == 0) ListMoves(); // always maintain a list of legal moves in root position @@ -2325,6 +2350,7 @@ printf("# setup done");fflush(stdout); if(stm == engineSide) { // if it is the engine's turn to move, set it thinking, and let it move pboard(board); + SetSearchTimes(10*timeLeft); score = SearchBestMove(&move, &ponderMove); if(move == INVALID) { // game apparently ended @@ -2346,9 +2372,10 @@ pboard(board); PrintResult(stm, score); } else { stm = MakeMove2(stm, move); // assumes MakeMove returns new side to move - gameMove[moveNr++] = move; // remember game + gameMove[moveNr++] = move; // remember game printf("move %s\n", MoveToText(move, 1)); listEnd = 0; + continue; } } @@ -2439,6 +2466,7 @@ pboard(board); } continue; } + ponderMove = INVALID; // the following commands change the position, invalidating ponder move listEnd = 0; if(!strcmp(command, "new")) { engineSide = BLACK; Init(V_CHESS); stm = Setup2(NULL); maxDepth = MAXPLY; randomize = OFF; curVarNr = comp = 0;