}\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
*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