Send game result to USI engines
[uci2wb.git] / UCI2WB.c
index c3129f5..62e17e4 100644 (file)
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -251,6 +251,7 @@ Engine2GUI()
            // move was a move to be played\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, "win")) { printf("%s {claim}\n", stm== WHITE ? "1-0" :"0-1"); computer = NONE; } // USI\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
            sscanf(line, "bestmove %s", move[moveNr++]);\r
@@ -378,7 +379,7 @@ Move4Engine(char *m)
 void\r
 GUI2Engine()\r
 {\r
-    char line[256], command[256], *p, *q, *r;\r
+    char line[256], command[256], *p, *q, *r, mySide;\r
 \r
     while(1) {\r
        int i, x;\r
@@ -387,7 +388,7 @@ GUI2Engine()
            DPRINT("# start search\n");\r
            LoadPos(moveNr); fflush(stdout); // load position\r
            // and set engine thinking (note USI swaps colors!)\r
-           startTime = GetTickCount();\r
+           startTime = GetTickCount(); mySide = stm; // remember side we last played for\r
            if(computer == ANALYZE) {\r
                fprintf(toE, "\ngo infinite"); DPRINT("\n# go infinite");\r
                if(sm & 1) { // some moves are disabled\r
@@ -516,6 +517,7 @@ GUI2Engine()
        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, "offer"))  drawOffer = 1;\r
+       else if(!strcmp(command, "result")) { if(sc == 's') fprintf(toE, "gameover %s\n", line[8] == '/' ? "draw" : (line[7] == '0') == mySide ? "win" : "lose"); }\r
        else if(!strcmp(command, "quit"))   fprintf(toE, "quit\n"), fflush(toE), exit(0);\r
     }\r
 }\r