From 7fb95d5105ce2608c5a378a99e5f6076fc0e6f12 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Tue, 28 Oct 2014 00:21:20 +0100 Subject: [PATCH] Implement UCCI draw offers The XBoard "offer draw" command is recognized, and leads to sending of a 'draw' keyword with the 'go'. The other way a 'draw' in 'bestmove' will lead to sending of an "offer draw" command. --- UCI2WB.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/UCI2WB.c b/UCI2WB.c index 8b8b460..eeb93c3 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -36,7 +36,7 @@ int statDepth, statScore, statNodes, statTime, currNr, size, collect, nr, sm, in char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20]; char 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; +int unit = 1, drawOffer; FILE *toE, *fromE, *fromF; int pid; @@ -129,12 +129,14 @@ Play(int nr) void StartSearch(char *ponder) { // send the 'go' command to engine. Suffix by ponder. + char *draw = "draw "; int x = (ponder[0] != 0); // during ponder stm is the opponent int black = (stm == BLACK ^ x ^ sc == 's'); // set if our color is what the engine calls black int nr = moveNr + x; // we ponder for one move ahead! - if(sc == 'x') black = 1; // in UCCI 'black' refers to us and 'white' to opponent - fprintf(toE, "\ngo%s %stime %d %stime %d", ponder, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime); - DPRINT( "\n# go%s %stime %d %stime %d", ponder, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime); + if(sc == 'x') black = 1; else draw = ""; // in UCCI 'black' refers to us and 'white' to opponent + drawOffer = 0; + fprintf(toE, "\ngo%s %s%stime %d %stime %d", ponder, draw, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime); + DPRINT( "\n# go%s %s%stime %d %stime %d", ponder, draw, bTime, black ? myTime : hisTime, wTime, !black ? myTime : hisTime); if(sTime > 0) { fprintf(toE, " movetime %d", sTime); DPRINT(" movetime %d", sTime); } else if(mps) { fprintf(toE, " movestogo %d", mps*(nr/(2*mps)+1)-nr/2); DPRINT(" movestogo %d", mps*(nr/(2*mps)+1)-nr/2); } if(inc && !suffix) { fprintf(toE, " %s %d %s %d", wInc, inc, bInc, inc); DPRINT(" %s %d %s %d", wInc, inc, bInc, inc); } @@ -237,6 +239,7 @@ Engine2GUI() if(!strcmp(command, "bestmove")) { if(pause) { pondering = pause = 0; Sync(WAKEUP); continue; } // bestmove was reply to ponder miss or analysis result; ignore. // move was a move to be played + if((p = strstr(line+8, " draw")) && p != line+8) { *p = '\n'; printf("offer draw\n"); computer = NONE; } // UCCI if(strstr(line+9, "resign")) { printf("resign\n"); computer = NONE; } if(strstr(line+9, "(none)") || strstr(line+9, "null") || strstr(line+9, "0000")) { printf("%s\n", lastScore < -99999 ? "resign" : "1/2-1/2 {stalemate}"); computer = NONE; } @@ -488,6 +491,7 @@ GUI2Engine() else if(!strcmp(command, "cores")&& !!*threadOpt) sscanf(line, "cores %d", &cores), fprintf(toE, "setoption %s%s %s%d\n", nameWord, threadOpt, valueWord, cores); else if(!strcmp(command, "sd")) sscanf(line, "sd %d", &depth); else if(!strcmp(command, "st")) sscanf(line, "st %d", &sTime), sTime = 1000*sTime - 30, inc = 0, sTime /= unit; + else if(!strcmp(command, "offer")) drawOffer = 1; else if(!strcmp(command, "quit")) fprintf(toE, "quit\n"), fflush(toE), exit(0); } } -- 1.7.0.4