- i = 0; while((x = getchar()) != EOF && (line[i] = x) != '\n') i++;\r
- line[++i] = 0; if(x == EOF) { printf("# EOF\n"); fprintf(toE, "quit\n"); exit(-1); }\r
- sscanf(line, "%s", command);\r
- if(!strcmp(command, "new")) {\r
- computer = BLACK; moveNr = 0; depth = -1; move[0][0] = 0;\r
- stm = WHITE; strcpy(iniPos, "position startpos"); frc &= ~1;\r
- if(memory != oldMem && hasHash) fprintf(toE, "setoption %s%s %s%d\n", nameWord, hashOpt, valueWord, memory);\r
- oldMem = memory;\r
- // we can set other options here\r
- if(sc == 'x') { if(newGame) fprintf(toE, "setoption newgame\n"); } else // optional in UCCI\r
- pause = 1; // wait for option settings to take effect\r
- fprintf(toE, "isready\n"); fflush(toE);\r
- Sync(PAUSE); // wait for readyok\r
- fprintf(toE, "u%cinewgame\n", sc); fflush(toE);\r
+ if(!ReadLine(stdin, line, 254)) printf("# EOF\n"), sprintf(line, "quit -1\n");\r
+ if(!sscanf(line, "%s", command)) return;\r
+ if(!strcmp(command, "usermove")) { difficult--; break; } // for efficiency during game play, moves, time & otim are tried first\r
+ else if(!strcmp(command, "time")) sscanf(line+4, "%d", &myTime), myTime = (10*myTime)/unit;\r
+ else if(!strcmp(command, "otim")) sscanf(line+4, "%d", &hisTime), hisTime = (10*hisTime)/unit;\r
+ else if(!strcmp(command, "draw")) drawOffer = 1; // backlogged anyway, so this can be done instantly\r
+ else if(!strcmp(command, "post")) post = 1;\r
+ else if(!strcmp(command, "nopost"))post = 0;\r
+ else if(!strcmp(command, ".")) {\r
+ printf("stat01: %d %d %d %d %d %s\n", statTime, statNodes, statDepth, nr-currNr, nr, currMove);\r
+ }\r
+ else if(!strcmp(command, "pause")) {\r
+ if(computer == stm) myTime -= GetTickCount() - startTime;\r
+ suspended = 1 + (searching == 1); // remember if we were pondering, and stop search ignoring bestmove\r
+ StopSearch(1);\r
+ }\r
+ else if(!strcmp(command, "xboard")) ;\r
+ else if(!strcmp(command, "random")) ;\r
+ else if(!strcmp(command, "accepted")) ;\r
+ else if(!strcmp(command, "rejected")) ;\r
+ else if(!strcmp(command, "book")) ;\r
+ else if(!strcmp(command, "ics")) ;\r
+ else if(!strcmp(command, "hint")) ;\r
+ else if(!strcmp(command, "computer")) comp = 1;\r
+ else { //convert easy & hard to "option" after treating their effect on the adapter\r
+ if(!strcmp(command, "easy")) {\r
+ if(*canPonder) ponder = 0, sprintf(command, "option"), sprintf(line, "option %s=0\n", canPonder); else continue;\r
+ }\r
+ else if(!strcmp(command, "hard")) {\r
+ if(*canPonder) ponder = 1, sprintf(command, "option"), sprintf(line, "option %s=1\n", canPonder); else continue;\r
+ }\r
+ if(!strcmp(command, "option")) {\r
+ if(sscanf(line+7, "UCI2WB debug output=%d", &debug) == 1) ; else\r
+ if(sscanf(line+7, "ponder always=%d", &ponderAlways) == 1) ; else\r
+ if(sscanf(line+7, "Floating Byoyomi=%d", &flob) == 1) ; else\r
+ if(sscanf(line+7, "Byoyomi=%d", &byo) == 1) ; else\r
+ difficult = 1;\r
+ }\r
+ else difficult = 1; // difficult command; terminate loop for easy ones\r