Add Linux manual page
[uci2wb.git] / UCI2WB.c
index 8dcc734..a6c229f 100644 (file)
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -1,6 +1,6 @@
 /************************* UCI2WB by H.G.Muller ****************************/\r
 \r
-#define VERSION "1.10"\r
+#define VERSION "2.0"\r
 \r
 #include <stdio.h>\r
 #include <stdlib.h>\r
@@ -129,14 +129,13 @@ Play(int nr)
 void\r
 StartSearch(char *ponder)\r
 {      // send the 'go' command to engine. Suffix by ponder.\r
-       char *draw = "draw ";\r
        int x = (ponder[0] != 0);                   // during ponder stm is the opponent\r
        int black = (stm == BLACK ^ x ^ sc == 's'); // set if our color is what the engine calls black\r
        int nr = moveNr + x;                        // we ponder for one move ahead!\r
-       if(sc == 'x') black = 1; else draw = "";    // in UCCI 'black' refers to us and 'white' to opponent\r
-       drawOffer = 0;\r
-       fprintf(toE, "\ngo%s %s%stime %d %stime %d", ponder, draw, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime);\r
-       DPRINT(    "\n# go%s %s%stime %d %stime %d", ponder, draw, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime);\r
+       if(sc == 'x') black = 1; else drawOffer = 0;// in UCCI 'black' refers to us and 'white' to opponent\r
+       if(!x && drawOffer) ponder = " draw", drawOffer = 0; //pass draw offer only when not pondering\r
+       fprintf(toE, "\ngo%s %stime %d %stime %d", ponder, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime);\r
+       DPRINT(    "\n# go%s %stime %d %stime %d", ponder, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime);\r
        if(sTime > 0) { fprintf(toE, " movetime %d", sTime); DPRINT(" movetime %d", sTime); } else\r
        if(mps) { fprintf(toE, " movestogo %d", mps*(nr/(2*mps)+1)-nr/2); DPRINT(" movestogo %d", mps*(nr/(2*mps)+1)-nr/2); }\r
        if(inc && !suffix) { fprintf(toE, " %s %d %s %d", wInc, inc, bInc, inc); DPRINT(" %s %d %s %d", wInc, inc, bInc, inc); }\r
@@ -149,7 +148,7 @@ void
 StopPonder(int pondering)\r
 {\r
        if(!pondering) return;\r
-       pause = 1;\r
+       pause = 2;\r
        fprintf(toE, "stop\n"); fflush(toE); DPRINT("# stop\n"); // note: 'pondering' remains set until engine acknowledges 'stop' with 'bestmove'\r
        Sync(PAUSE); // wait for engine to acknowledge 'stop' with 'bestmove'.\r
 }\r
@@ -238,8 +237,9 @@ Engine2GUI()
        if(sscanf(line, "%s", command) != 1) continue;\r
        if(!strcmp(command, "bestmove")) {\r
            if(pause) { pondering = pause = 0; Sync(WAKEUP); continue; } // bestmove was reply to ponder miss or analysis result; ignore.\r
+           else if(pondering) { pondering = 0; printf("%d 0 0 0 UCI violation! Engine moves during ponder\n", lastDepth+1); continue; } // ignore ponder search\r
            // move was a move to be played\r
-           if((p = strstr(line+8, " draw")) && p != line+8)   { *p = '\n'; printf("offer draw\n"); computer = NONE; } // UCCI\r
+           if(p = strstr(line+8, " draw")) *p = 0, printf("offer draw\n"); // UCCI\r
            if(strstr(line+9, "resign")) { printf("resign\n"); computer = NONE; }\r
            if(strstr(line+9, "(none)") || strstr(line+9, "null") ||\r
               strstr(line+9, "0000")) { printf("%s\n", lastScore < -99999 ? "resign" : "1/2-1/2 {stalemate}"); computer = NONE; }\r
@@ -383,7 +383,7 @@ GUI2Engine()
       nomove:\r
        fflush(toE); fflush(stdout);\r
        i = 0; while((x = getchar()) != EOF && (line[i] = x) != '\n') i++;\r
-       line[++i] = 0; if(x == EOF) { printf("# EOF\n"); exit(-1); }\r
+       line[++i] = 0; if(x == EOF) { printf("# EOF\n"); fprintf(toE, "quit\n"); exit(-1); }\r
        sscanf(line, "%s", command);\r
        if(!strcmp(command, "new")) {\r
            computer = BLACK; moveNr = 0; depth = -1; move[0][0] = 0;\r
@@ -404,8 +404,9 @@ GUI2Engine()
            // when pondering we either continue the ponder search as normal search, or abort it\r
            if(pondering || computer == ANALYZE) {\r
                if(pondering && !strcmp(command, move[moveNr])) { // ponder hit\r
+                   char *draw = drawOffer ? " draw" : ""; drawOffer = 0;\r
                    pondering = 0; moveNr++; startTime = GetTickCount(); // clock starts running now\r
-                   fprintf(toE, "ponderhit\n"); DPRINT("# ponderhit\n");\r
+                   fprintf(toE, "ponderhit%s\n", draw); DPRINT("# ponderhit%s\n", draw);\r
                    goto nomove;\r
                }\r
                StopPonder(1);\r
@@ -429,7 +430,7 @@ GUI2Engine()
        }\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 reuse=0 exclude=1 pause=1 done=0\n", variants);\r
+           printf("feature variants=\"%s\" setboard=1 usermove=1 debug=1 ping=1 reuse=0 exclude=1 pause=1 sigint=0 sigterm=0 done=0\n", variants);\r
            printf("feature option=\"UCI2WB debug output -check %d\"\n", debug);\r
            fprintf(toE, sc == 'x' ? "ucci\n" : "u%ci\n", sc); fflush(toE); // prompt UCI engine for options\r
            Sync(PAUSE); // wait for uciok\r
@@ -603,7 +604,7 @@ main(int argc, char **argv)
 #ifdef WIN32\r
        CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) Engine2GUI, (LPVOID) NULL, 0, &thread_id);\r
 #else\r
-        { pthread_t t; signal(SIGINT, SIG_IGN); pthread_create(&t, NULL, Engine2GUI, NULL); }\r
+        { pthread_t t; signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN); pthread_create(&t, NULL, Engine2GUI, NULL); }\r
 #endif\r
 \r
        // handle GUI->engine traffic in original thread\r