X-Git-Url: http://winboard.nl/cgi-bin?p=uci2wb.git;a=blobdiff_plain;f=UCI2WB.c;h=3db7bbd2fa97608d88cc6b80cc96272c12c42ca2;hp=997423f764b0c2f19e22c1abcf1a4b5406a236ef;hb=a8c8e03626f0cd085656c31efc672689998d5fdb;hpb=8d74aed8f6fb583c14bf2f6622811221672b8d23 diff --git a/UCI2WB.c b/UCI2WB.c index 997423f..3db7bbd 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -30,8 +30,9 @@ #include // Set VARIANTS for in WinBoard variant feature. (With -s option this will always be reset to use "shogi".) -#define VARIANTS "normal,xiangqi" +#define VARIANTS ",normal,xiangqi" #define STDVARS "chess,chess960,crazyhouse,threecheck,giveaway,atomic,seirawan,shogi,xiangqi" +#define EGT ",gaviotatbpath,syzygypath,nalimovpath," #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 */ } @@ -41,20 +42,20 @@ #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], *variants, varOpt, searching; +char move[2000][10], iniPos[256], hashOpt[20], pause, pondering, 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 board[100]; // XQ board for UCCI +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; +int unit = 1, drawOffer, scores[99], mpvSP, maxDepth; volatile int logLen, sentLen; FILE *toE, *fromE, *fromF; int pid; #ifdef WIN32 -char *strcasestr (char *p, char *q) { char *r = p; while(*r) *r = tolower(*r), r++; return strstr(p, q); } +char *strcasestr (char *p, char *q) { while(*p) { char *r=p++, *s=q; while(tolower(*r++) == tolower(*s) && *s) s++; if(!*s) return p-1; } return NULL; } WinPipe(HANDLE *hRd, HANDLE *hWr) { @@ -156,7 +157,7 @@ StartSearch(char *ponder) if(inc && !*suffix) EPRINT((f, " %s %d %s %d", wInc, inc, bInc, inc)) if(depth > 0) EPRINT((f, " depth %d", depth)) if(*suffix) EPRINT((f, suffix, inc)) - EPRINT((f, "\n")) + EPRINT((f, "\n")); maxDepth = mpvSP = 0; } void @@ -255,7 +256,7 @@ GetChar() void * Engine2GUI() { - char line[1024], command[256]; + char line[1024], command[256]; static char egts[999]; if(fromF = fopen("DefectiveEngineOptions.ini", "r")) printf("# fake engine input\n"); while(1) { @@ -264,7 +265,7 @@ Engine2GUI() fflush(stdout); fflush(toE); while((line[i] = x = GetChar()) != EOF && line[i] != '\n') i++; line[++i] = 0; - if(x == EOF) exit(0); + if(x == EOF) 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")) { @@ -325,13 +326,17 @@ Engine2GUI() if(p = strstr(line+4, " time ")) sscanf(p+6, "%d", &t), t /= 10, statTime = t; if(p = strstr(line+4, " currmove ")) sscanf(p+10,"%s", currMove); if(p = strstr(line+4, " currmovenumber ")) sscanf(p+16,"%d", &currNr); - if(pv = strstr(line+4, " pv ")) // convert PV info to WB thinking output + if(pv = strstr(line+4, " pv ")) { // convert PV info to WB thinking output + if(d > maxDepth) maxDepth = d, mpvSP = 0; else if(d < maxDepth) continue; // ignore depth regressions + for(i=0; i= mpvSP) strncpy(pvs[mpvSP], pv+4, 998), scores[mpvSP++] = s, // emit as thinking output if not printf("%3d %6d %6d %10d %s", lastDepth=d, lastScore=s, t, n, Convert(pv+4)); + } else if(s == -100000) lastScore = s; // when checkmated score is valid even without PV (which might not come) } } else if(!strcmp(command, "option")) { // USI option: extract data fields char name[80], type[80], buf[1024], val[256], *q; - int min=0, max=1e9; + int min=0, max=1e9; *val = 0; if(p = strstr(line+6, " type ")) sscanf(p+1, "type %s", type), *p = '\n'; if(p = strstr(line+6, " min ")) sscanf(p+1, "min %d", &min), *p = '\n'; if(p = strstr(line+6, " max ")) sscanf(p+1, "max %d", &max), *p = '\n'; @@ -353,8 +358,13 @@ 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(strcasestr(EGT, buf)) { buf[strlen(buf)-5-2*(buf[3]=='v')] = 0; strcat(egts, buf); continue; } // collect EGT formats // pass on engine-defined option as WB option feature if(!strcmp(type, "filename")) type[4] = 0; + else if(sc == 'c' && !strcmp(type, "string")) { // in UCI try to guess which strings are file or directory names + if(strcasestr(name, "file")) strcpy(type, "file"); else + if(strcasestr(name, "path") || strcasestr(name, "directory") || strcasestr(name, "folder")) strcpy(type, "path"); + } sprintf(buf, "feature option=\"%s -%s", name, type); q = buf + strlen(buf); if( !strcmp(type, "file") || !strcmp(type, "string")) sprintf(q, " %s\"\n", val); @@ -387,6 +397,7 @@ Engine2GUI() else *p++ = *q++; // copy other variant names unmodified if(frc) sprintf(p, ",normal,fischerandom"), printf("feature oocastle=%d\n", frc<0); // unannounced FRC uses O-O castling if(*varList) printf("feature variants=\"%s\"\n", varList+1); // from UCI_Variant combo and/or UCI_Chess960 check options + if(*egts) { for(p=egts; *p = tolower(*p); p++); printf("feature egt=\"%s\"\n", egts+1); } printf("feature smp=1 memory=%d done=1\n", hasHash); if(unit == 2) { unit = 1; EPRINT((f, "# setoption usemillisec true\n")) } Sync(WAKEUP); // done with options @@ -415,7 +426,7 @@ Move4Engine(char *m) void GUI2Engine() { - char line[256], command[256], *p, *q, *r, mySide; + char line[256], command[256], *p, *q, *r, mySide, type[99]; while(1) { int i, x, difficult, think=0; @@ -426,7 +437,7 @@ GUI2Engine() // and set engine thinking (note USI swaps colors!) startTime = GetTickCount(); mySide = stm; // remember side we last played for if(computer == ANALYZE) { - EPRINT((f, "# go infinite")) + EPRINT((f, "# go infinite")); maxDepth = mpvSP = 0; if(sm & 1) { // some moves are disabled EPRINT((f, " searchmoves")) for(i=1; i 1 && !strcmp(argv[1], "debug")) { debug = 1; argc--; argv++; } - if(argc > 1 && !strcmp(argv[1], "-var")) { variants = argv[2]; argc-=2; argv+=2; } + if(argc > 1 && !strcmp(argv[1], "-var")) { strcpy(varList+1, argv[2]); *varList = ','; argc-=2; argv+=2; } if(argc > 1 && argv[1][0] == '-') { sc = argv[1][1]; argc--; argv++; } if(argc < 2) { printf("usage is: U%cI2WB [debug] [-s] []\n", sc-32); exit(-1); } if(argc > 2) dir = argv[2]; @@ -686,7 +706,7 @@ main(int argc, char **argv) else if(sc == 'n') sc = 'c'; // UCI for normal Chess // spawn engine proc - if(StartEngine(argv[1], dir) != NO_ERROR) { perror(argv[1]), exit(-1); } + if(StartEngine(binary = argv[1], dir) != NO_ERROR) { perror(argv[1]), exit(-1); } Sync(INIT);