Process CECP egtpath command
[uci2wb.git] / UCI2WB.c
index 9b5e70c..cbc11f7 100644 (file)
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -30,7 +30,7 @@
 #include <string.h>\r
 \r
 // Set VARIANTS for in WinBoard variant feature. (With -s option this will always be reset to use "shogi".)\r
-#define VARIANTS "normal,xiangqi"\r
+#define VARIANTS ",normal,xiangqi"\r
 #define STDVARS "chess,chess960,crazyhouse,threecheck,giveaway,atomic,seirawan,shogi,xiangqi"\r
 \r
 #define DPRINT if(debug) printf\r
@@ -41,7 +41,7 @@
 #define NONE  2\r
 #define ANALYZE 3\r
 \r
-char move[2000][10], iniPos[256], hashOpt[20], pause, pondering, suspended, ponder, post, hasHash, c, sc='c', suffix[81], *variants, varOpt, searching;\r
+char move[2000][10], iniPos[256], hashOpt[20], pause, pondering, suspended, ponder, post, hasHash, c, sc='c', suffix[81], varOpt, searching, *binary;\r
 int mps, tc, inc, sTime, depth, myTime, hisTime, stm, computer = NONE, memory, oldMem=0, cores, moveNr, lastDepth, lastScore, startTime, debug, flob;\r
 int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, inex, on[500], frc, byo = -1, namOpt, comp;\r
 char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20], varList[8000], anaOpt[20], backLog[10000], checkOptions[8192] = "Ponder";\r
@@ -264,7 +264,7 @@ Engine2GUI()
        fflush(stdout); fflush(toE);\r
        while((line[i] = x = GetChar()) != EOF && line[i] != '\n') i++;\r
        line[++i] = 0;\r
-       if(x == EOF) exit(0);\r
+       if(x == EOF) printf("tellusererror UCI2WB: %s died on me\n", binary), exit(0);\r
        DPRINT("# engine said: %s", line), fflush(stdout);\r
        if(sscanf(line, "%s", command) != 1) continue;\r
        if(!strcmp(command, "bestmove")) {\r
@@ -327,6 +327,7 @@ Engine2GUI()
                if(p = strstr(line+4, " currmovenumber ")) sscanf(p+16,"%d", &currNr);\r
                if(pv = strstr(line+4, " pv ")) // convert PV info to WB thinking output\r
                    printf("%3d  %6d %6d %10d %s", lastDepth=d, lastScore=s, t, n, Convert(pv+4));\r
+               else if(s == -100000) lastScore = s; // when checkmated score is valid even without PV (which might not come)\r
            }\r
        }\r
        else if(!strcmp(command, "option")) { // USI option: extract data fields\r
@@ -415,7 +416,7 @@ Move4Engine(char *m)
 void\r
 GUI2Engine()\r
 {\r
-    char line[256], command[256], *p, *q, *r, mySide;\r
+    char line[256], command[256], *p, *q, *r, mySide, type[99];\r
 \r
     while(1) {\r
        int i, x, difficult, think=0;\r
@@ -525,8 +526,8 @@ GUI2Engine()
            tc = (60*tc + sec)*1000; inc *= 1000; sTime = 0; tc /= unit; inc /= unit;\r
        }\r
        else if(!strcmp(command, "protover")) {\r
-           if(!variants) variants = sc=='s' ? "shogi,5x5+5_shogi" : VARIANTS;\r
-           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);\r
+           if(!varList[0]) strcpy(varList, sc=='s' ? ",shogi,5x5+5_shogi" : VARIANTS);\r
+           printf("feature setboard=1 usermove=1 debug=1 ping=1 name=1 reuse=0 exclude=1 pause=1 sigint=0 sigterm=0 done=0\n");\r
            printf("feature option=\"UCI2WB debug output -check %d\"\n", debug);\r
            if(sc == 's') printf("feature option=\"Floating Byoyomi -check %d\"\nfeature option=\"Byoyomi -spin %d -1 1000\"\n", flob, byo);\r
            EPRINT((f, sc == 'x' ? "# ucci\n" : "u%ci\n", sc)) fflush(toE); // prompt UCI engine for options\r
@@ -577,6 +578,7 @@ GUI2Engine()
        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); }\r
        else if(!strcmp(command, "memory")) sscanf(line, "memory %d", &memory);\r
        else if(!strcmp(command, "cores")&& !!*threadOpt) { sscanf(line, "cores %d", &cores); EPRINT((f, "# setoption %s%s %s%d\n", nameWord, threadOpt, valueWord, cores)) }\r
+       else if(!strcmp(command, "egtpath")){ sscanf(line, "egtpath %s %[^\n]", type, command); EPRINT((f, "# setoption name %sPath value %s\n", type,command)); }\r
        else if(!strcmp(command, "sd"))     sscanf(line, "sd %d", &depth);\r
        else if(!strcmp(command, "st"))     sscanf(line, "st %d", &sTime), sTime = 1000*sTime - 30, inc = 0, sTime /= unit;\r
        else if(!strcmp(command, "name"))   { if(namOpt) EPRINT((f, "# setoption name UCI_Opponent value none none %s %s", comp ? "computer" : "human", line+5)) }\r
@@ -680,7 +682,7 @@ main(int argc, char **argv)
 \r
        if(argc == 2 && !strcmp(argv[1], "-v")) { printf("UCI2WB " VERSION " by H.G.Muller\n"); exit(0); }\r
        if(argc > 1 && !strcmp(argv[1], "debug")) { debug = 1; argc--; argv++; }\r
-       if(argc > 1 && !strcmp(argv[1], "-var")) { variants = argv[2]; argc-=2; argv+=2; }\r
+       if(argc > 1 && !strcmp(argv[1], "-var")) { strcpy(varList+1, argv[2]); *varList = ','; argc-=2; argv+=2; }\r
        if(argc > 1 && argv[1][0] == '-') { sc = argv[1][1]; argc--; argv++; }\r
        if(argc < 2) { printf("usage is: U%cI2WB [debug] [-s] <engine.exe> [<engine directory>]\n", sc-32); exit(-1); }\r
        if(argc > 2) dir = argv[2];\r
@@ -691,7 +693,7 @@ main(int argc, char **argv)
        else if(sc == 'n') sc = 'c'; // UCI for normal Chess\r
 \r
        // spawn engine proc\r
-       if(StartEngine(argv[1], dir) != NO_ERROR) { perror(argv[1]), exit(-1); }\r
+       if(StartEngine(binary = argv[1], dir) != NO_ERROR) { perror(argv[1]), exit(-1); }\r
 \r
        Sync(INIT);\r
 \r