X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=UCI2WB.c;h=5ebe5eff8c127bb3aac42db20a535f401d49d79a;hb=5e15f187c0e73082935dce3fef09a436e3467c35;hp=7d915e821777765398d0e85b3c64214d3aa24e1a;hpb=1e8b2a6e137452edec15c70394d22bf864a5d54f;p=uci2wb.git diff --git a/UCI2WB.c b/UCI2WB.c index 7d915e8..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,13 +422,47 @@ 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, "quit") || !strcmp(command, "force") || !strcmp(command, "?")) { EPRINT((f, "# stop\n")); fflush(toE); } + if(!strcmp(command, "?") || !strcmp(command, "quit") || + !strcmp(command, "force") || !strcmp(command, "result")) { EPRINT((f, "# stop\n")); fflush(toE); } Sync(PAUSE); // block processing of input during thinking } if(!strcmp(command, "new")) { @@ -467,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); @@ -524,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"); @@ -540,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)) } @@ -551,7 +560,10 @@ GUI2Engine() else if(!strcmp(command, "st")) sscanf(line, "st %d", &sTime), sTime = 1000*sTime - 30, inc = 0, sTime /= unit; else if(!strcmp(command, "name")) { if(namOpt) EPRINT((f, "# setoption name UCI_Opponent value none none %s %s", comp ? "computer" : "human", line+5)) } else if(!strcmp(command, "computer")) comp = 1; - else if(!strcmp(command, "result")) { if(sc == 's') EPRINT((f, "# gameover %s\n", line[8] == '/' ? "draw" : (line[7] == '0') == mySide ? "win" : "lose")) } + else if(!strcmp(command, "result")) { + if(sc == 's') EPRINT((f, "# gameover %s\n", line[8] == '/' ? "draw" : (line[7] == '0') == mySide ? "win" : "lose")) + computer = NONE; + } else if(!strcmp(command, "quit")) { EPRINT((f, "# quit\n")) fflush(toE), exit(atoi(line+4)); } } }