void SetMemorySize(int n); // if n is different from last time, resize all tables to make memory usage below n MB\r
char *MoveToText(MOVE move, int m); // converts the move from your internal format to text like e2e2, e1g1, a7a8q.\r
MOVE ParseMove(char *moveText); // converts a long-algebraic text move to your internal move format\r
- int SearchBestMove(int stm, int timeLeft, int mps, int timeControl, int inc, int timePerMove, MOVE *move, MOVE *ponderMove);\r
+ int SearchBestMove(MOVE *move, MOVE *ponderMove);\r
void PonderUntilInput(int stm); // Search current position for stm, deepening forever until there is input.\r
\r
UndoInfo undoInfo;\r
printf("highlight %s\n", buf);\r
}\r
\r
-int\r
-SearchBestMove (int stm, int timeLeft, int mps, int timeControl, int inc, int timePerMove, MOVE *move, MOVE *ponderMove)\r
+int timeLeft; // timeleft on engine's clock\r
+int mps, timeControl, inc, timePerMove; // time-control parameters, to be used by Search\r
+char inBuf[8000], command[80], ponderMoveText[20];\r
+\r
+void\r
+SetSearchTimes (int timeLeft)\r
{\r
- int score, targetTime, movesLeft = BW*BH/4 + 20;\r
+ int targetTime, movesLeft = BW*BH/4 + 20;\r
if(mps) movesLeft = mps - (moveNr>>1)%mps;\r
- targetTime = timeLeft*10 / (movesLeft + 2) + 1000 * inc;\r
+ targetTime = (timeLeft - 1000*inc) / (movesLeft + 2) + 1000 * inc;\r
if(moveNr < 30) targetTime *= 0.5 + moveNr/60.; // speedup in opening\r
- if(timePerMove > 0) targetTime = timeLeft * 5;\r
- startTime = GetTickCount();\r
+ if(timePerMove > 0) targetTime = 0.5*timeLeft, movesLeft = 1;\r
tlim1 = 0.2*targetTime;\r
tlim2 = 1.9*targetTime;\r
+}\r
+\r
+int\r
+SearchBestMove (MOVE *move, MOVE *ponderMove)\r
+{\r
+ int score;\r
+ startTime = GetTickCount();\r
nodes = 0;\r
MapFromScratch(attacks);\r
retMove = INVALID; repCnt = 0;\r
score = Search(-INF-1, INF+1, rootEval, maxDepth, sup1, sup2);\r
*move = retMove;\r
- *ponderMove = INVALID;\r
+ *ponderMove = pv[1];\r
return score;\r
}\r
\r
+\r
void\r
PonderUntilInput (int stm)\r
{\r
}\r
-\r
+ \r
int TakeBack(int n)\r
{ // reset the game and then replay it to the desired point\r
int last, stm;\r
else printf("0-1%s\n", tail);\r
}\r
\r
+ void GetLine(int root)\r
+ {\r
+ int i, c;\r
+ while(1) {\r
+ // wait for input, and read it until we have collected a complete line\r
+ for(i = 0; (inBuf[i] = c = getchar()) != '\n'; i++) if(c == EOF || i>7997) exit(0);\r
+ inBuf[i+1] = 0;\r
+\r
+ // extract the first word\r
+ sscanf(inBuf, "%s", command);\r
+ if(!strcmp(command, "otim")) { continue; } // do not start pondering after receiving time commands, as move will follow immediately\r
+ if(!strcmp(command, "time")) { sscanf(inBuf, "time %d", &timeLeft); continue; }\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
+ return;\r
+ }\r
+ }\r
+\r
main()\r
{\r
int engineSide=NONE; // side played by engine\r
- int timeLeft; // timeleft on engine's clock\r
- int mps, timeControl, inc, timePerMove; // time-control parameters, to be used by Search\r
- MOVE move, ponderMove;\r
+ MOVE move;\r
int i, score, curVarNr;\r
- char inBuf[8000], command[80];\r
\r
Init(V_CHU); // Chu\r
\r
if(stm == engineSide) { // if it is the engine's turn to move, set it thinking, and let it move\r
\r
pboard(board);\r
- score = SearchBestMove(stm, timeLeft, mps, timeControl, inc, timePerMove, &move, &ponderMove);\r
+ score = SearchBestMove(&move, &ponderMove);\r
\r
if(move == INVALID) { // game apparently ended\r
int kcapt = 0, xstm = stm ^ WHITE, king, k = p[king=royal[xstm]].pos;\r
}\r
}\r
\r
- noPonder:\r
- // wait for input, and read it until we have collected a complete line\r
- for(i = 0; (inBuf[i] = getchar()) != '\n'; i++);\r
- inBuf[i+1] = 0;\r
-\r
- // extract the first word\r
- sscanf(inBuf, "%s", command);\r
-printf("in: %s\n", command);\r
+ fflush(stdout); // make sure everything is printed before we do something that might take time\r
+ if(!*inBuf) GetLine(1); // takes care of time and otim commands\r
\r
// recognize the command,and execute it\r
if(!strcmp(command, "quit")) { break; } // breaks out of infinite loop\r
if(!strcmp(command, "force")) { engineSide = NONE; continue; }\r
if(!strcmp(command, "analyze")) { engineSide = ANALYZE; continue; }\r
if(!strcmp(command, "exit")) { engineSide = NONE; continue; }\r
- if(!strcmp(command, "otim")) { goto noPonder; } // do not start pondering after receiving time commands, as move will follow immediately\r
- if(!strcmp(command, "time")) { sscanf(inBuf, "time %d", &timeLeft); goto noPonder; }\r
if(!strcmp(command, "level")) {\r
int min, sec=0;\r
sscanf(inBuf, "level %d %d %d", &mps, &min, &inc) == 3 || // if this does not work, it must be min:sec format\r
if(!strcmp(command, "nopost")) { postThinking = OFF;continue; }\r
if(!strcmp(command, "random")) { randomize = ON; continue; }\r
if(!strcmp(command, "hint")) { if(ponderMove != INVALID) printf("Hint: %s\n", MoveToText(ponderMove, 0)); continue; }\r
- if(!strcmp(command, "lift")) { Highlight(inBuf+5); continue; }\r
- if(!strcmp(command, "put")) { ReadSquare(inBuf+4, &lastPut); continue; }\r
if(!strcmp(command, "book")) { continue; }\r
// non-standard commands\r
if(!strcmp(command, "p")) { pboard(board); continue; }\r