void\r
StartSearch(char *ponder)\r
{ // send the 'go' command to engine. Suffix by ponder.\r
- int nr = moveNr + (ponder[0] != 0); // we ponder for one move ahead!\r
- fprintf(toE, "\ngo btime %d wtime %d", stm == BLACK ^ sc=='s' ? myTime : hisTime, stm == WHITE ^ sc=='s' ? myTime : hisTime);\r
- DPRINT( "\n# go btime %d wtime %d", stm == BLACK ^ sc=='s' ? myTime : hisTime, stm == WHITE ^ sc=='s' ? myTime : hisTime);\r
+ int x = (ponder[0] != 0);\r
+ int nr = moveNr + x; // we ponder for one move ahead!\r
+ fprintf(toE, "\ngo btime %d wtime %d", stm == BLACK ^ x ^ sc=='s' ? myTime : hisTime, stm == WHITE ^ x ^ sc=='s' ? myTime : hisTime);\r
+ DPRINT( "\n# go btime %d wtime %d", stm == BLACK ^ x ^ sc=='s' ? myTime : hisTime, stm == WHITE ^ x ^ sc=='s' ? myTime : hisTime);\r
if(sTime > 0) { fprintf(toE, " movetime %d", sTime); DPRINT(" movetime %d", sTime); } else\r
if(mps) { fprintf(toE, " movestogo %d", mps*(nr/(2*mps)+1)-nr/2); DPRINT(" movestogo %d", mps*(nr/(2*mps)+1)-nr/2); }\r
if(inc && !suffix) { fprintf(toE, " winc %d binc %d", inc, inc); DPRINT(" winc %d binc %d", inc, inc); }\r
for(j=0; j<moveNr; j++) { fprintf(toE, " %s", move[j]); DPRINT(" %s", move[j]); }\r
}\r
\r
+void\r
+StartPonder()\r
+{\r
+ if(!move[moveNr][0]) return; // no ponder move\r
+ LoadPos(moveNr+1);\r
+ pondering = 1; lastDepth = 1;\r
+ StartSearch(" ponder");\r
+}\r
+\r
char *Convert(char *pv)\r
{ // convert Shogi coordinates to WB\r
char *p, *q, c;\r
sscanf(line, "bestmove %s", move[moveNr++]);\r
myTime -= (GetTickCount() - startTime)*1.02 + inc; // update own clock, so we can give correct wtime, btime with ponder\r
if(mps && ((moveNr+1)/2) % mps == 0) myTime += tc; if(sTime) myTime = sTime; // new session or move starts\r
+ stm = WHITE+BLACK - stm;\r
// first start a new ponder search, if pondering is on and we have a move to ponder on\r
if(p = strstr(line+9, "ponder")) {\r
+ sscanf(p+7, "%s", move[moveNr]);\r
if(computer != NONE && ponder) {\r
- sscanf(p+7, "%s", move[moveNr]);\r
DPRINT("# ponder on %s\n", move[moveNr]);\r
- LoadPos(moveNr+1); // load position\r
- // and set engine pondering\r
- pondering = 1; lastDepth = 1;\r
- StartSearch(" ponder");\r
+ StartPonder();\r
}\r
p[-1] = '\n'; *p = 0; // strip off ponder move\r
- }\r
+ } else move[moveNr][0] = 0;\r
Move4GUI(line+9);\r
printf("move %s\n", line+9); // send move to GUI\r
- if(lastScore == 100001 && iniPos[0] != 'f') { printf("%s {mate}\n", stm == WHITE ? "1-0" : "0-1"); computer = NONE; }\r
- stm = WHITE+BLACK - stm;\r
+ if(lastScore == 100001 && iniPos[0] != 'f') { printf("%s {mate}\n", stm == BLACK ? "1-0" : "0-1"); computer = NONE; }\r
}\r
else if(!strcmp(command, "info")) {\r
int d=0, s=0, t=0, n=0;\r
line[++i] = 0; if(x == EOF) { printf("# EOF\n"); exit(-1); }\r
sscanf(line, "%s", command);\r
if(!strcmp(command, "new")) {\r
- computer = BLACK; moveNr = 0; depth = -1;\r
+ computer = BLACK; moveNr = 0; depth = -1; move[0][0] = 0;\r
stm = WHITE; strcpy(iniPos, "position startpos");\r
if(memory != oldMem && hasHash) fprintf(toE, "setoption name %s value %d\n", hashOpt, memory);\r
oldMem = memory;\r
suspended = 1 + pondering, StopPonder(1); // remember if we were pondering, and stop search ignoring bestmove\r
}\r
else if(!strcmp(command, "resume")) {\r
- if(suspended == 2) { // restart interrupted ponder search\r
- LoadPos(moveNr+1);\r
- pondering = 1; lastDepth = 1;\r
- StartSearch(" ponder");\r
- }\r
+ if(suspended == 2) StartPonder(); // restart interrupted ponder search\r
suspended = 0; // causes thinking to start in normal way if on move or analyzing\r
}\r
else if(!strcmp(command, "xboard")) ;\r
else if(!strcmp(command, "otim")) sscanf(line+4, "%d", &hisTime), hisTime *= 10;\r
else if(!strcmp(command, "post")) post = 1;\r
else if(!strcmp(command, "nopost")) post = 0;\r
- else if(!strcmp(command, "easy")) ponder = 0;\r
- else if(!strcmp(command, "hard")) ponder = 1;\r
+ else if(!strcmp(command, "easy")) ponder = 0, StopPonder(pondering);\r
+ else if(!strcmp(command, "hard")) ponder = 1, StartPonder();\r
else if(!strcmp(command, "ping")) pause = 1, fprintf(toE, "isready\n"), fflush(toE), Sync(PAUSE), printf("pong %s", line+5);\r
else if(!strcmp(command, "memory")) sscanf(line, "memory %d", &memory);\r
else if(!strcmp(command, "cores")) sscanf(line, "cores %d", &cores);\r