Allow faking of options the engine fails to announce
[uci2wb.git] / UCI2WB.c
index cf50631..e0570a2 100644 (file)
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -34,7 +34,7 @@ char move[2000][10], checkOptions[8192], iniPos[256], hashOpt[20], pause, ponder
 int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, oldMem=0, cores, moveNr, lastDepth, lastScore, startTime, debug;\r
 int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500]; char currMove[20], moveMap[500][10]; // for analyze mode\r
 \r
-FILE *toE, *fromE;\r
+FILE *toE, *fromE, *fromF;\r
 int pid;\r
 \r
 #ifdef WIN32\r
@@ -151,20 +151,32 @@ Move4GUI(char *m)
     }\r
 }\r
 \r
+int\r
+GetChar()\r
+{\r
+    int c;\r
+    if(fromF) {\r
+       if((c = fgetc(fromF)) != EOF) return c;\r
+       fclose(fromF); fromF = 0; printf("# end fake\n");\r
+    }\r
+    return fgetc(fromE);\r
+}\r
+\r
 void *\r
 Engine2GUI()\r
 {\r
     char line[1024], command[256];\r
 \r
+    if(fromF = fopen("DefectiveEngineOptions.ini", "r")) printf("# fake engine input\n");\r
     while(1) {\r
        int i=0, x; char *p, dummy;\r
 \r
        fflush(stdout); fflush(toE);\r
-       while((line[i] = x = fgetc(fromE)) != EOF && line[i] != '\n') i++;\r
+       while((line[i] = x = GetChar()) != EOF && line[i] != '\n') i++;\r
        line[++i] = 0;\r
        if(x == EOF) exit(0);\r
        DPRINT("# engine said: %s", line), fflush(stdout);\r
-       sscanf(line, "%s", command);\r
+       if(sscanf(line, "%s", command) != 1) continue;\r
        if(!strcmp(command, "bestmove")) {\r
            if(pause) { pondering = pause = 0; Sync(WAKEUP); continue; } // bestmove was reply to ponder miss or analysis result; ignore.\r
            // move was a move to be played\r