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