X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=UCI2WB.c;h=725606198a78013786e23cacd21a3c9c8b4e7171;hb=6339bbabc92588399ae64225e62db0aa571aa921;hp=029b34b133e9abee2e1f3f6fe160d18469edaeb6;hpb=f9dc502ea66938564e9e6eabcc2aff4199f5dd83;p=uci2wb.git diff --git a/UCI2WB.c b/UCI2WB.c index 029b34b..7256061 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -32,9 +32,10 @@ char move[2000][10], checkOptions[8192], iniPos[256], hashOpt[20], pause, pondering, suspended, ponder, post, hasHash, c, sc='c', *suffix, *variants; int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, oldMem=0, cores, moveNr, lastDepth, lastScore, startTime, debug; -int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500]; char currMove[20], moveMap[500][10]; // for analyze mode +int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500]; +char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20]; -FILE *toE, *fromE; +FILE *toE, *fromE, *fromF; int pid; #ifdef WIN32 @@ -151,20 +152,32 @@ Move4GUI(char *m) } } +int +GetChar() +{ + int c; + if(fromF) { + if((c = fgetc(fromF)) != EOF) return c; + fclose(fromF); fromF = 0; printf("# end fake\n"); + } + return fgetc(fromE); +} + void * Engine2GUI() { char line[1024], command[256]; + if(fromF = fopen("DefectiveEngineOptions.ini", "r")) printf("# fake engine input\n"); while(1) { int i=0, x; char *p, dummy; fflush(stdout); fflush(toE); - while((line[i] = x = fgetc(fromE)) != EOF && line[i] != '\n') i++; + while((line[i] = x = GetChar()) != EOF && line[i] != '\n') i++; line[++i] = 0; if(x == EOF) exit(0); DPRINT("# engine said: %s", line), fflush(stdout); - sscanf(line, "%s", command); + if(sscanf(line, "%s", command) != 1) continue; if(!strcmp(command, "bestmove")) { if(pause) { pondering = pause = 0; Sync(WAKEUP); continue; } // bestmove was reply to ponder miss or analysis result; ignore. // move was a move to be played @@ -225,6 +238,7 @@ Engine2GUI() if(p = strstr(line+6, " max ")) sscanf(p+1, "max %d", &max), *p = '\n'; if(p = strstr(line+6, " default ")) sscanf(p+1, "default %[^\n]*", val), *p = '\n'; if(p = strstr(line+6, " name ")) sscanf(p+1, "name %[^\n]*", name); + if(!strcmp(name, "Ponder") || !strcmp(name, "USI_Ponder")) { strcpy(canPonder, name); continue; } if(!strcmp(name, "Hash") || !strcmp(name, "USI_Hash")) { memory = oldMem = atoi(val); hasHash = 1; strcpy(hashOpt, name); @@ -386,7 +400,8 @@ GUI2Engine() } else if(!strcmp(command, "pause")) { if(computer == stm) myTime -= GetTickCount() - startTime; - suspended = 1 + pondering, StopPonder(1); // remember if we were pondering, and stop search ignoring bestmove + suspended = 1 + pondering; // remember if we were pondering, and stop search ignoring bestmove + StopPonder(pondering || computer == stm); } else if(!strcmp(command, "resume")) { if(suspended == 2) StartPonder(); // restart interrupted ponder search @@ -401,8 +416,8 @@ GUI2Engine() else if(!strcmp(command, "otim")) sscanf(line+4, "%d", &hisTime), hisTime *= 10; else if(!strcmp(command, "post")) post = 1; else if(!strcmp(command, "nopost")) post = 0; - else if(!strcmp(command, "easy")) ponder = 0, StopPonder(pondering); - else if(!strcmp(command, "hard")) ponder = 1, StartPonder(); + else if(!strcmp(command, "easy") && !!*canPonder) ponder = 0, StopPonder(pondering), fprintf(toE, "setoption name %s value false\n", canPonder); + else if(!strcmp(command, "hard") && !!*canPonder) ponder = 1, fprintf(toE, "setoption name %s value true\n", canPonder), StartPonder(); else if(!strcmp(command, "ping")) pause = 1, fprintf(toE, "isready\n"), fflush(toE), Sync(PAUSE), printf("pong %s", line+5); else if(!strcmp(command, "memory")) sscanf(line, "memory %d", &memory); else if(!strcmp(command, "cores")) sscanf(line, "cores %d", &cores);