From: H.G.Muller Date: Thu, 1 Dec 2016 13:41:05 +0000 (+0100) Subject: Process all innocent commands immediately (fixes pause/resume) X-Git-Tag: v4.0~47 X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=5e15f187c0e73082935dce3fef09a436e3467c35;p=uci2wb.git Process all innocent commands immediately (fixes pause/resume) To prevent that commands received during thinking will halt command processing,eclipsing later instant commands, all commands that merely alter a settings value in adapter or engine are now immediately executed. UCI engines should be able to handle 'setoption' commands even during thinking, so explicit or implicit (easy/hard) settings changes are immediately relayed to the engine as well. The 'pause' and 'resume' commands are now also treated immediately; waiting with that until the engine is done thinking subverted the intention of the 'pause' command. Commands that would never be sent when an engine is thinking are still left with the commands that require thinking to complete, as for those thisdoes not matter. --- diff --git a/UCI2WB.c b/UCI2WB.c index adfb3d6..5ebe5ef 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -405,7 +405,7 @@ GUI2Engine() char line[256], command[256], *p, *q, *r, mySide, searching = 0; while(1) { - int i, x, think=0; + int i, x, difficult, think=0; if((computer == stm || computer == ANALYZE && !searching) && !suspended) { DPRINT("# start search\n"); @@ -422,11 +422,44 @@ GUI2Engine() } else pause = think = 2, StartSearch(""); // request suspending of input processing while thinking } nomove: + for(difficult=0; !difficult; ) { // read and handle commands that can (or must) be handled during thinking fflush(toE); fflush(stdout); i = 0; while((x = getchar()) != EOF && (line[i] = x) != '\n') i++; line[++i] = 0; if(x == EOF) { printf("# EOF\n"); sprintf(line, "quit -1\n"); } sscanf(line, "%s", command); - if(!strcmp(command, "offer")) { drawOffer = 1; goto nomove; } // backlogged anyway, so this can be done instantly + if(!strcmp(command, "offer")) drawOffer = 1; // backlogged anyway, so this can be done instantly + else if(!strcmp(command, "post")) post = 1; + else if(!strcmp(command, "nopost"))post = 0; + else if(!strcmp(command, "option")) { + char name[80], *p; + if(searching) StopPonder(1), searching = 0; // force new search if settings change during analysis (multi-PV!) + if(sscanf(line+7, "UCI2WB debug output=%d", &debug) == 1) ; else + if(sscanf(line+7, "Floating Byoyomi=%d", &flob) == 1) ; else + if(sscanf(line+7, "Byoyomi=%d", &byo) == 1) ; else + if(p = strchr(line, '=')) { + *p++ = 0; + if(strstr(checkOptions, line+7)) sprintf(p, "%s\n", atoi(p) ? "true" : "false"); + EPRINT((f, "# setoption %s%s %s%s", nameWord, line+7, valueWord, p)) + } else EPRINT((f, "# setoption %s%s\n", nameWord, line+7)) + } + else if(!strcmp(command, "pause")) { + if(computer == stm) myTime -= GetTickCount() - startTime; + suspended = 1 + pondering; // remember if we were pondering, and stop search ignoring bestmove + StopPonder(pondering || computer == stm); + } + else if(!strcmp(command, "easy")) { + if(*canPonder) { ponder = 0; StopPonder(pondering); EPRINT((f, "# setoption %s%s %sfalse\n", nameWord, canPonder, valueWord)) } + } + else if(!strcmp(command, "hard")) { + if(*canPonder) { ponder = 1; EPRINT((f, "# setoption %s%s %strue\n", nameWord, canPonder, valueWord)) StartPonder(); } + } + else difficult = 1; // difficult command; terminate loop for easy ones + } // next command + + if(!strcmp(command, "resume")) { + if(suspended == 2) StartPonder(); // restart interrupted ponder search + suspended = think = 0; continue; // causes thinking to start in normal way if on move or analyzing + } if(think) { // command arrived during thinking; order abort for 'instant commands' if(!strcmp(command, "?") || !strcmp(command, "quit") || !strcmp(command, "force") || !strcmp(command, "result")) { EPRINT((f, "# stop\n")); fflush(toE); } @@ -468,18 +501,6 @@ GUI2Engine() sscanf(line, "level %d %d %d", &mps, &tc, &inc); tc = (60*tc + sec)*1000; inc *= 1000; sTime = 0; tc /= unit; inc /= unit; } - else if(!strcmp(command, "option")) { - char name[80], *p; - if(searching) StopPonder(1), searching = 0; // force new search if settings change during analysis (multi-PV!) - if(sscanf(line+7, "UCI2WB debug output=%d", &debug) == 1) ; else - if(sscanf(line+7, "Floating Byoyomi=%d", &flob) == 1) ; else - if(sscanf(line+7, "Byoyomi=%d", &byo) == 1) ; else - if(p = strchr(line, '=')) { - *p++ = 0; - if(strstr(checkOptions, line+7)) sprintf(p, "%s\n", atoi(p) ? "true" : "false"); - EPRINT((f, "# setoption %s%s %s%s", nameWord, line+7, valueWord, p)) - } else EPRINT((f, "# setoption %s%s\n", nameWord, line+7)) - } else if(!strcmp(command, "protover")) { if(!variants) variants = sc=='s' ? "shogi,5x5+5_shogi" : VARIANTS; printf("feature variants=\"%s\" setboard=1 usermove=1 debug=1 ping=1 name=1 reuse=0 exclude=1 pause=1 sigint=0 sigterm=0 done=0\n", variants); @@ -525,15 +546,6 @@ GUI2Engine() if(!(sm & 2)) goto nomove; // no moves enabled; continue current search if(computer == ANALYZE) StopPonder(1), searching = 0; // abort old analysis } - else if(!strcmp(command, "pause")) { - if(computer == stm) myTime -= GetTickCount() - startTime; - 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 - suspended = 0; // causes thinking to start in normal way if on move or analyzing - } else if(!strcmp(command, "xboard")) ; else if(!strcmp(command, "analyze"))computer = ANALYZE, collect = 1, sm = 0, Analyze("true"); else if(!strcmp(command, "exit")) computer = NONE, StopPonder(1), searching = 0, Analyze("false"); @@ -541,10 +553,6 @@ GUI2Engine() else if(!strcmp(command, "go")) computer = stm; else if(!strcmp(command, "time")) sscanf(line+4, "%d", &myTime), myTime = (10*myTime)/unit; else if(!strcmp(command, "otim")) sscanf(line+4, "%d", &hisTime), hisTime = (10*hisTime)/unit; - else if(!strcmp(command, "post")) post = 1; - else if(!strcmp(command, "nopost")) post = 0; - else if(!strcmp(command, "easy") && !!*canPonder) { ponder = 0; StopPonder(pondering); EPRINT((f, "# setoption %s%s %sfalse\n", nameWord, canPonder, valueWord)) } - else if(!strcmp(command, "hard") && !!*canPonder) { ponder = 1; EPRINT((f, "# setoption %s%s %strue\n", nameWord, canPonder, valueWord)) StartPonder(); } else if(!strcmp(command, "ping")) { /* static int done; if(!done) pause = 1, fprintf(toE, "isready\n"), fflush(toE), printf("# send isready\n"), fflush(stdout), Sync(PAUSE); done = 1;*/ printf("po%s", line+2); } else if(!strcmp(command, "memory")) sscanf(line, "memory %d", &memory); else if(!strcmp(command, "cores")&& !!*threadOpt) { sscanf(line, "cores %d", &cores); EPRINT((f, "# setoption %s%s %s%d\n", nameWord, threadOpt, valueWord, cores)) }