char *array, fenArray[4000], *reason;\r
int bWidth, bHeight, bsize, zone, currentVariant, chuFlag, tenFlag, chessFlag, repDraws;\r
int stm, xstm, hashKeyH, hashKeyL, framePtr, msp, nonCapts, rootEval, retMSP, retFirst, retDep, pvPtr, level, cnt50, mobilityScore;\r
-int nodes, startTime, tlim1, tlim2, tlim3, repCnt, comp, abortFlag;\r
+int nodes, startTime, lastRootMove, lastRootIter, tlim1, tlim2, tlim3, repCnt, comp, abortFlag;\r
Move ponderMove;\r
Move retMove, moveStack[10000], path[100], repStack[300], pv[1000], repeatMove[300], killer[100][2];\r
\r
} // next move\r
cutoff:\r
if(!level) { // root node\r
+ lastRootIter = GetTickCount() - startTime;\r
if(postThinking > 0) {\r
int i; // WB thinking output\r
- printf("%d %d %d %d", iterDep, bestScore, (GetTickCount() - startTime)/10, nodes);\r
+ printf("%d %d %d %d", iterDep, bestScore, lastRootIter/10, nodes);\r
if(ponderMove) printf(" (%s)", MoveToText(ponderMove, 0));\r
for(i=0; pv[i]; i++) printf(" %s", MoveToText(pv[i], 0));\r
if(iterDep == 1) printf(" { root eval = %4.2f dif = %4.2f; abs = %4.2f}", curEval/100., difEval/100., PSTest()/100.);\r
}\r
\r
\r
-void\r
-PonderUntilInput (int stm)\r
-{\r
-MapFromScratch(attacks);\r
- repCnt = 0; abortFlag = -1;\r
- Search(-INF-1, INF+1, rootEval, maxDepth, sup1, sup2);\r
-}\r
- \r
int TakeBack(int n)\r
{ // reset the game and then replay it to the desired point\r
int last, stm;\r
if(!strcmp(command, "put")) { ReadSquare(inBuf+4, &lastPut); continue; } // ditto\r
if(!strcmp(command, ".")) { inBuf[0] = 0; return; } // ignore for now\r
if(!strcmp(command, "lift")) { inBuf[0] = 0; Highlight(inBuf+5); return; } // treat here\r
+ if(!root && !strcmp(command, "usermove")) {\r
+ abortFlag = !!strcmp(inBuf+9, ponderMoveText);\r
+ if(!abortFlag) { // ponder hit, continue as time-based search\r
+ SetSearchTimes(10*timeLeft + GetTickCount() - startTime); // add time we already have been pondering to total\r
+ if(lastRootIter > tlim1) abortFlag = 2; // abort instantly if we are in iteration we should not have started\r
+ inBuf[0] = 0; ponderMove = INVALID;\r
+ return;\r
+ }\r
+ }\r
abortFlag = 1;\r
return;\r
}\r
*inBuf = 0;\r
\r
if(listEnd == 0) ListMoves(); // always maintain a list of legal moves in root position\r
-\r
- abortFlag = 0;\r
- if(stm == engineSide) { // if it is the engine's turn to move, set it thinking, and let it move\r
- \r
+ abortFlag = -(ponder && WHITE+BLACK-stm == engineSide && moveNr); // pondering and opponent on move\r
+ if(stm == engineSide || abortFlag && ponderMove) { // if it is the engine's turn to move, set it thinking, and let it move\r
+ if(abortFlag) {\r
+ stm = MakeMove2(stm, ponderMove); // for pondering, play speculative move\r
+ gameMove[moveNr++] = ponderMove; // remember in game\r
+ sprintf(ponderMoveText, "%s\n", MoveToText(ponderMove, 0)); // for detecting ponder hits\r
+ } else SetSearchTimes(10*timeLeft); // for thinking, schedule end time\r
pboard(board);\r
- SetSearchTimes(10*timeLeft);\r
score = SearchBestMove(&move, &ponderMove);\r
-\r
+ if(abortFlag == 1) { // ponder search was interrupted (and no hit)\r
+ UnMake2(INVALID); moveNr--; stm ^= WHITE; // take ponder move back if we made one\r
+ abortFlag = 0;\r
+ } else\r
if(move == INVALID) { // game apparently ended\r
int kcapt = 0, xstm = stm ^ WHITE, king, k = p[king=royal[xstm]].pos;\r
if( k != ABSENT) { // test if King capture possible\r
gameMove[moveNr++] = move; // remember game\r
printf("move %s\n", MoveToText(move, 1));\r
listEnd = 0;\r
- continue;\r
+ continue; // go check if we should ponder\r
}\r
- }\r
-\r
- fflush(stdout); // make sure everything is printed before we do something that might take time\r
-\r
- // now it is not our turn (anymore)\r
- if(engineSide == ANALYZE) { // in analysis, we always ponder the position\r
- PonderUntilInput(stm);\r
} else\r
- if(engineSide != NONE && ponder == ON && moveNr != 0) { // ponder while waiting for input\r
- if(ponderMove == INVALID) { // if we have no move to ponder on, ponder the position\r
- PonderUntilInput(stm);\r
- } else {\r
- int newStm = MakeMove2(stm, ponderMove);\r
- PonderUntilInput(newStm);\r
- UnMake2(ponderMove);\r
- }\r
+ if(engineSide == ANALYZE || abortFlag) { // in analysis, we always ponder the position\r
+ Move dummy;\r
+ *ponderMoveText = 0; // forces miss on any move\r
+ abortFlag = -1; // set pondering\r
+ SearchBestMove(&dummy, &dummy);\r
+ abortFlag = 0; //\r
}\r
\r
fflush(stdout); // make sure everything is printed before we do something that might take time\r