X-Git-Url: http://winboard.nl/cgi-bin?p=uci2wb.git;a=blobdiff_plain;f=UCI2WB.c;h=b9df43c4c1e53bfc99c1ed79af265c4f22f4f919;hp=05600eee4f31f51589c585b51c749ae74aa17539;hb=9e92f9f1e4e601912bd40334c9f89677b9b65f23;hpb=4c43c5722cf24b0cd44a9fe1f1eb6ad6c501d345 diff --git a/UCI2WB.c b/UCI2WB.c index 05600ee..b9df43c 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -32,7 +32,7 @@ // Set VARIANTS for in WinBoard variant feature. (With -s option this will always be reset to use "shogi".) #define VARIANTS ",normal,xiangqi" #define STDVARS "chess,chess960,crazyhouse,3check,giveaway,suicide,losers,atomic,seirawan,shogi,xiangqi" -#define EGT ",gaviotaTbPath,syzygyPath,nalimovPath,robbotripleBaseDirectory,robbototalBaseDirectory," +#define EGT ",gaviotaTbPath,syzygyPath,nalimovPath,robbotripleBaseDirectory,robbototalBaseDirectory,bitbases path," #define DPRINT if(debug) printf #define EPRINT(X) { char f[999]; sprintf X; DPRINT("%s", f); fprintf(toE, "%s", f + 2*(*f == '#')); /* strip optional # prefix */ } @@ -42,13 +42,13 @@ #define NONE 2 #define ANALYZE 3 -char move[2000][10], iniPos[256], hashOpt[20], pause, pondering, suspended, ponder, post, hasHash, c, sc='c', suffix[81], varOpt, searching, *binary; +char move[2000][10], iniPos[256], hashOpt[20], pause, 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 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; +int unit = 1, drawOffer, scores[99], mpvSP, maxDepth, ponderAlways; volatile int logLen, sentLen; FILE *toE, *fromE, *fromF; @@ -185,11 +185,11 @@ LoadPos(int moveNr) } void -StartPonder() +StartPonder(int moveNr) { if(!move[moveNr][0]) return; // no ponder move LoadPos(moveNr+1); - pondering = 1; lastDepth = 1; + searching = 1; lastDepth = 1; StartSearch(" ponder"); } @@ -202,11 +202,11 @@ Analyze(char *val) int Release() { // send setoption commands backlogged during thinking to engine, aborting ponder or analysis search if necessary - int len = logLen - sentLen, analyse = searching; + int len = logLen - sentLen, analyse = (searching == 2); if(len <= 0) return 0; - StopPonder(pondering | searching); pondering = searching = 0; // force new search if settings change during analysis (multi-PV!) + 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(); // (re)start ponder search + if(ponder && computer == 1 - stm) StartPonder(moveNr); // (re)start ponder search return analyse; // return 1 if analysis search should be restarted } @@ -243,34 +243,29 @@ Move4GUI(char *m) } int -GetChar() +ReadLine (FILE *f, char *line) { - int c; - if(fromF) { - if((c = fgetc(fromF)) != EOF) return c; - fclose(fromF); fromF = 0; printf("# end fake\n"); - } - return fgetc(fromE); + int x, i = 0; + while((x = fgetc(f)) != EOF && (line[i] = x) != '\n') i++; line[++i] = 0; + return (x != EOF); } -void * -Engine2GUI() +void +HandleEngineOutput() { char line[1024], command[256]; static char egts[999]; - if(fromF = fopen("DefectiveEngineOptions.ini", "r")) printf("# fake engine input\n"); while(1) { int i=0, x; char *p, dummy, len; fflush(stdout); fflush(toE); - while((line[i] = x = GetChar()) != EOF && line[i] != '\n') i++; - line[++i] = 0; - if(x == EOF) printf("tellusererror UCI2WB: %s died on me\n", binary), exit(0); + if(fromF && !ReadLine(fromF, line)) fromF = 0, printf("# end fake\n"); + if(!fromF && !ReadLine(fromE, line)) printf("tellusererror UCI2WB: %s died on me\n", binary), exit(0); DPRINT("# engine said: %s", line), fflush(stdout); if(sscanf(line, "%s", command) != 1) continue; if(!strcmp(command, "bestmove")) { - if(pause == 1) { pondering = pause = 0; Sync(WAKEUP); continue; } // bestmove was reply to ponder miss or analysis result; ignore. - else if(pondering) { pondering = 0; printf("%d 0 0 0 UCI violation! Engine moves during ponder\n", lastDepth+1); continue; } // ignore ponder search + if(pause == 1) { searching = pause = 0; Sync(WAKEUP); continue; } // bestmove was reply to ponder miss or analysis result; ignore. + else if(searching == 1) { searching = 0; printf("%d 0 0 0 UCI violation! Engine moves during ponder\n", lastDepth+1); continue; } // ignore ponder search // move was a move to be played if(p = strstr(line+8, " draw")) *p = 0, printf("offer draw\n"); // UCCI if(strstr(line+9, "resign")) { printf("resign\n"); computer = NONE; } @@ -287,7 +282,7 @@ Engine2GUI() sscanf(p+7, "%s", move[moveNr]); if(computer != NONE && ponder) { DPRINT("# ponder on %s\n", move[moveNr]); - StartPonder(); + StartPonder(moveNr); } p[-1] = '\n'; *p = 0; // strip off ponder move } else move[moveNr][0] = 0; @@ -302,7 +297,15 @@ Engine2GUI() char *pv, varName[80]; if(sscanf(line+5, "string times @ %c", &dummy) == 1) { printf("# %s", line+12); continue; } if(sscanf(line+5, "string variant %s", varName) == 1) { - if(!strstr(STDVARS, varName) && (p = strstr(line+18, " startpos "))) printf("setup (-) 8x8+0_fairy %s", p+10); + if(!strstr(STDVARS, varName)) { + int files = 8, ranks = 8, hand = 0; char parent[80]; + if(p = strstr(line+18, " files ")) sscanf(p+7, "%d", &files); + if(p = strstr(line+18, " ranks ")) sscanf(p+7, "%d", &ranks); + if(p = strstr(line+18, " pocket ")) sscanf(p+8, "%d", &hand); + if(p = strstr(line+18, " template ")) sscanf(p+10, "%s", parent); else strcpy(parent, "fairy"); + if(p = strstr(line+18, " startpos ")) + printf("setup (-) %dx%d+%d_%s %s", files, ranks, hand, parent, p+10); + } continue; } if(collect && (pv = strstr(line+5, "currmove "))) { @@ -361,7 +364,7 @@ Engine2GUI() if(!strcasecmp(name, "newgame") && !strcmp(type, "button")) { newGame++; continue; } if(!strcasecmp(name, "usemillisec")) { unit = (!strcmp(val, "false") ? 2 : 1); continue; } sprintf(buf, ",%s,", name); if(p = strcasestr(EGT, buf)) { // collect EGT formats - strcpy(buf, p); for(p=buf; *++p >='a';){} *p = 0; strcat(egts, buf); continue; // clip at first non-lower-case + strcpy(buf, p); for(p=buf; *++p >='a';){} if(*p == ' ') strcpy(buf, ",scorpio"); *p = 0; strcat(egts, buf); continue; // clip at first non-lower-case } // pass on engine-defined option as WB option feature if(!strcmp(type, "filename")) type[4] = 0; @@ -408,6 +411,13 @@ Engine2GUI() } } +void * +Engine2GUI() +{ + if(fromF = fopen("DefectiveEngineOptions.ini", "r")) printf("# fake engine input\n"); + HandleEngineOutput(); +} + void Move4Engine(char *m) { @@ -426,13 +436,14 @@ Move4Engine(char *m) } } +int DoCommand (); +char mySide; +char queue[10000], *qStart, *qEnd; + void -GUI2Engine() +LaunchSearch() { - char line[256], command[256], *p, *q, *r, mySide, type[99]; - - while(1) { - int i, x, difficult, think=0; + int i; if((computer == stm || computer == ANALYZE && !searching) && !suspended) { DPRINT("# start search\n"); @@ -445,16 +456,24 @@ GUI2Engine() EPRINT((f, " searchmoves")) for(i=1; i 0) EPRINT((f, "# setoption name UCI_Chess960 value true\n")) } } else if(!strcmp(command, "undo") && (i=1) || !strcmp(command, "remove") && (i=2)) { - if(pondering || computer == ANALYZE) StopPonder(1), searching = 0; + if(searching) StopPonder(1), searching = 0; moveNr = moveNr > i ? moveNr - i : 0; collect = (computer == ANALYZE); sm = 0; } else if(!strcmp(command, ".")) { printf("stat01: %d %d %d %d 100 %s\n", statTime, statNodes, statDepth, 100-currNr, currMove); - goto nomove; + return 1; } else if(!strcmp(command+2, "clude") && collect > 2) { // include or exclude int all = !strcmp(line+8, "all"), in = command[1] == 'n'; inex = 1; line[strlen(line)-1] = sm = 0; // strip LF and clear sm flag for(i=1; i