X-Git-Url: http://winboard.nl/cgi-bin?p=uci2wb.git;a=blobdiff_plain;f=UCI2WB.c;fp=UCI2WB.c;h=536eb44198a9557ec1f1bedb933f6623337d3d33;hp=135b3a7601f76b0b9f98d10d724542bc9ac172dc;hb=56ec3542fa3d48cab43219310e235951a0978599;hpb=33b016e152d6f441cc4b2d7c5cb8ad440f480bc6 diff --git a/UCI2WB.c b/UCI2WB.c index 135b3a7..536eb44 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -45,11 +45,10 @@ char move[2000][10], iniPos[256], hashOpt[20], suspended, ponder, post, hasHash, c, sc='c', suffix[81], varOpt, searching, *binary; int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, oldMem=0, cores, moveNr, lastDepth, lastScore, startTime, debug, flob; int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500], frc, byo = -1, namOpt, comp; -char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20], varList[8000], anaOpt[20], backLog[10000], checkOptions[8192] = "Ponder"; +char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20], varList[8000], anaOpt[20], checkOptions[8192] = "Ponder"; char pvs[99][999], board[100]; // XQ board for UCCI char *nameWord = "name ", *valueWord = "value ", *wTime = "w", *bTime = "b", *wInc = "winc", *bInc = "binc", newGame; // keywords that differ in UCCI int unit = 1, drawOffer, scores[99], mpvSP, maxDepth, ponderAlways; -volatile int logLen, sentLen; FILE *toE, *fromE, *fromF; int pid; @@ -197,17 +196,6 @@ Analyze(char *val) if(*anaOpt) EPRINT((f, "# setoption %s%s %s%s\n", nameWord, anaOpt, valueWord, val)); } -int -Release() -{ // send setoption commands backlogged during thinking to engine, aborting ponder or analysis search if necessary - int len = logLen - sentLen, analyse = (searching == 2); - if(len <= 0) return 0; - StopPonder(searching); searching = 0; // force new search if settings change during analysis (multi-PV!) - fwrite(backLog + sentLen, 1, len, toE); sentLen += len; DPRINT("# release %d\n", len); - if(ponder && computer == 1 - stm) StartPonder(moveNr); // (re)start ponder search - return analyse; // return 1 if analysis search should be restarted -} - char *Convert(char *pv) { // convert Shogi coordinates to WB char *p, *q, c; @@ -271,7 +259,6 @@ HandleEngineOutput() if(strstr(line+9, "(none)") || strstr(line+9, "null") || strstr(line+9, "0000")) { printf("%s\n", lastScore < -99999 ? "resign" : "1/2-1/2 {stalemate}"); computer = NONE; } sscanf(line, "bestmove %s", move[moveNr++]); - Release(); // send setoption commands that arrived during search myTime -= (GetTickCount() - startTime)*1.02 + inc; // update own clock, so we can give correct wtime, btime with ponder if(mps && ((moveNr+1)/2) % mps == 0) myTime += tc; if(sTime) myTime = sTime; // new session or move starts stm = WHITE+BLACK - stm; @@ -463,7 +450,7 @@ GUI2Engine() for(difficult=0; !difficult; ) { // read and handle commands that can (or must) be handled during thinking fflush(toE); fflush(stdout); if(!ReadLine(stdin, line)) printf("# EOF\n"), sprintf(line, "quit -1\n"); - sscanf(line, "%s", command); DPRINT("# '%s' searching=%d log=%d sent=%d\n", command, searching, logLen, sentLen); + sscanf(line, "%s", command); if(!strcmp(command, "usermove")) { difficult--; break; } // for efficiency during game play, moves, time & otim are tried first 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; @@ -481,21 +468,13 @@ GUI2Engine() } else if(!strcmp(command, "hard")) { if(*canPonder) ponder = 1, sprintf(command, "option"), sprintf(line, "option %s=1\n", canPonder); else continue; - } + } else if(!strcmp(command, "option")) { - char *p; - if(logLen == sentLen) logLen = 0, sentLen = 0; // engine is up to date; reset buffer if(sscanf(line+7, "UCI2WB debug output=%d", &debug) == 1) ; else if(sscanf(line+7, "ponder always=%d", &ponderAlways) == 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"); - snprintf(backLog+logLen, 9999-logLen, "setoption %s%s %s%s", nameWord, line+7, valueWord, p); - } else snprintf(backLog+logLen, 9999-logLen, "setoption %s%s\n", nameWord, line+7); - DPRINT("# backlog: %s", backLog+logLen); logLen += strlen(backLog+logLen); - if(searching < 3 && Release()) break; // break will restart analysis; pondering is restarted by Release itself + difficult = 1; } else difficult = 1; // difficult command; terminate loop for easy ones } @@ -560,6 +539,14 @@ DoCommand () HandleEngineOutput(); // wait for readyok EPRINT((f, "# u%cinewgame\n", sc)) fflush(toE); } + else if(!strcmp(command, "option")) { + char *p; + 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, "level")) { int sec = 0; sscanf(line, "level %d %d:%d %d", &mps, &tc, &sec, &inc) == 4 ||