X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=UCI2WB.c;h=eeb93c3bbd2ca4370fc18d1589f91040de804f97;hb=7fb95d5105ce2608c5a378a99e5f6076fc0e6f12;hp=21aad7d29edbe4ddeaf53ad8af30a51d8232f6ea;hpb=792199f6616669de79a1b09644af1cea831be128;p=uci2wb.git diff --git a/UCI2WB.c b/UCI2WB.c index 21aad7d..eeb93c3 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -35,8 +35,8 @@ int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, o int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500]; char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20]; char board[100]; // XQ board for UCCI -char *nameWord = "name ", *valueWord = "value ", *wTime = "w", *bTime = "b", *wInc = "winc", *bInc = "binc"; // keywords that differ in UCCI -int unit = 1; +char *nameWord = "name ", *valueWord = "value ", *wTime = "w", *bTime = "b", *wInc = "winc", *bInc = "binc", newGame; // keywords that differ in UCCI +int unit = 1, drawOffer; FILE *toE, *fromE, *fromF; int pid; @@ -129,12 +129,14 @@ Play(int nr) void StartSearch(char *ponder) { // send the 'go' command to engine. Suffix by ponder. + char *draw = "draw "; int x = (ponder[0] != 0); // during ponder stm is the opponent int black = (stm == BLACK ^ x ^ sc == 's'); // set if our color is what the engine calls black int nr = moveNr + x; // we ponder for one move ahead! - if(sc == 'x') black = 1; // in UCCI 'black' refers to us and 'white' to opponent - fprintf(toE, "\ngo%s %stime %d %stime %d", ponder, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime); - DPRINT( "\n# go%s %stime %d %stime %d", ponder, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime); + if(sc == 'x') black = 1; else draw = ""; // in UCCI 'black' refers to us and 'white' to opponent + drawOffer = 0; + fprintf(toE, "\ngo%s %s%stime %d %stime %d", ponder, draw, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime); + DPRINT( "\n# go%s %s%stime %d %stime %d", ponder, draw, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime); if(sTime > 0) { fprintf(toE, " movetime %d", sTime); DPRINT(" movetime %d", sTime); } else if(mps) { fprintf(toE, " movestogo %d", mps*(nr/(2*mps)+1)-nr/2); DPRINT(" movestogo %d", mps*(nr/(2*mps)+1)-nr/2); } if(inc && !suffix) { fprintf(toE, " %s %d %s %d", wInc, inc, bInc, inc); DPRINT(" %s %d %s %d", wInc, inc, bInc, inc); } @@ -237,6 +239,7 @@ Engine2GUI() 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 + if((p = strstr(line+8, " draw")) && p != line+8) { *p = '\n'; printf("offer draw\n"); computer = NONE; } // UCCI if(strstr(line+9, "resign")) { printf("resign\n"); computer = NONE; } 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; } @@ -297,11 +300,13 @@ Engine2GUI() if(!(p = strstr(line+6, " name "))) p = line+1; sscanf(p+6, "%[^\n]", name); // 'name' is omitted in UCCI if(!strcmp(name, "Threads")) { strcpy(threadOpt, name); continue; } if(!strcmp(name, "Ponder") || !strcmp(name, "USI_Ponder")) { strcpy(canPonder, name); continue; } - if(!strcmp(name, "Hash") || !strcmp(name, "USI_Hash")) { + if(!strcmp(name, "Hash") || !strcmp(name, "USI_Hash") || !strcmp(name, "hashsize")) { memory = oldMem = atoi(val); hasHash = 1; strcpy(hashOpt, name); continue; } + if(!strcmp(name, "newgame") && !strcmp(type, "button")) { newGame++; continue; } + if(!strcmp(name, "usemillisec")) { unit = (!strcmp(val, "false") ? 2 : 1); continue; } // pass on engine-defined option as WB option feature if(!strcmp(type, "filename")) type[4] = 0; sprintf(buf, "feature option=\"%s -%s", name, type); q = buf + strlen(buf); @@ -329,6 +334,7 @@ Engine2GUI() else if(!strcmp(command, "readyok")) { pause = 0; Sync(WAKEUP); } // resume processing of GUI commands else if(sc == 'x'&& !strcmp(command, "ucciok") || sscanf(command, "u%ciok", &c)==1 && c==sc) { printf("feature smp=1 memory=%d done=1\n", hasHash); + if(unit == 2) unit = 1, fprintf(toE, "setoption usemillisec true\n"); Sync(WAKEUP); // done with options } } @@ -386,9 +392,10 @@ GUI2Engine() if(memory != oldMem && hasHash) fprintf(toE, "setoption name %s %s%d\n", hashOpt, valueWord, memory); oldMem = memory; // we can set other options here + if(sc == 'x') { if(newGame) fprintf(toE, "setoption newgame\n"); } else // optional in UCCI + fprintf(toE, "u%cinewgame\n", sc); fflush(toE); pause = 1; // wait for option settings to take effect fprintf(toE, "isready\n"); - fprintf(toE, "u%cinewgame\n", sc); fflush(toE); Sync(PAUSE); // wait for readyok } else if(!strcmp(command, "usermove")) { @@ -484,6 +491,7 @@ GUI2Engine() else if(!strcmp(command, "cores")&& !!*threadOpt) sscanf(line, "cores %d", &cores), fprintf(toE, "setoption %s%s %s%d\n", nameWord, threadOpt, valueWord, cores); else if(!strcmp(command, "sd")) sscanf(line, "sd %d", &depth); else if(!strcmp(command, "st")) sscanf(line, "st %d", &sTime), sTime = 1000*sTime - 30, inc = 0, sTime /= unit; + else if(!strcmp(command, "offer")) drawOffer = 1; else if(!strcmp(command, "quit")) fprintf(toE, "quit\n"), fflush(toE), exit(0); } }