From 3ec8885c5e09e26dc907693ff02adc6c46d7dc73 Mon Sep 17 00:00:00 2001
From: H.G.Muller <hgm@hgm-xboard.(none)>
Date: Sat, 8 Dec 2018 17:26:01 +0100
Subject: [PATCH] Do not queue ignored commands

Commands that will be ignored (such as 'xboard') are now recognized
with the easy commands, as it makes little sense to send them to the
engine thread just to be ignored. The 'accepted' and 'rejected' commands
are now also recognized and treated this way. In addition, commands are
now only echoed when they are queued, in debug mode: as the GUI thread
can only block on reading from the GUI we can be sure that all commands are
read as soon as they arrive, and echoing them just clutters the debug logs.
---
 UCI2WB.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/UCI2WB.c b/UCI2WB.c
index 1632b81..ad897f5 100644
--- a/UCI2WB.c
+++ b/UCI2WB.c
@@ -453,7 +453,6 @@ GUI2Engine()
 	fflush(toE); fflush(stdout);
 	if(!ReadLine(stdin, line)) printf("# EOF\n"), sprintf(line, "quit -1\n");
 	sscanf(line, "%s", command);
-	DPRINT("# %s searching=%d\n", command, searching);
 	if(!strcmp(command, "usermove")) { difficult--; break; } // for efficiency during game play, moves, time & otim are tried first
 	else if(!strcmp(command, "time"))   sscanf(line+4, "%d", &myTime),  myTime  = (10*myTime)/unit;
 	else if(!strcmp(command, "otim"))   sscanf(line+4, "%d", &hisTime), hisTime = (10*hisTime)/unit;
@@ -468,6 +467,10 @@ GUI2Engine()
 	    suspended = 1 + (searching == 1); // remember if we were pondering, and stop search ignoring bestmove
 	    StopSearch(1);
 	}
+	else if(!strcmp(command, "xboard")) ;
+	else if(!strcmp(command, "accepted")) ;
+	else if(!strcmp(command, "rejected")) ;
+	else if(!strcmp(command, "computer")) comp = 1;
 	else { //convert easy & hard to "option" after treating their effect on the adapter
 	  if(!strcmp(command, "easy")) {
 	    if(*canPonder) ponder = 0, sprintf(command, "option"), sprintf(line, "option %s=0\n", canPonder); else continue;
@@ -509,6 +512,7 @@ GUI2Engine()
 	    suspended = 0;  *qEnd++ = '\n'; Sync(WAKEUP); // causes search to start in normal way if on move or analyzing
 	} else
       {
+	DPRINT("# queue '%s', searching=%d\n", command, searching);
 	if(searching == 3) { // command arrived during thinking; order abort for 'instant commands'
 	    if(!strcmp(command, "?") || !strcmp(command, "quit") ||
 	       !strcmp(command, "force") || !strcmp(command, "result")) StopSearch(0);
@@ -596,7 +600,6 @@ DoCommand ()
 	    inex = 1; line[strlen(line)-1] = sm = 0; // strip LF and clear sm flag
 	    for(i=1; i<nr; i++) { if(!strcmp(line+8, moveMap[i]) || all) on[i] = in; sm |= on[i]+1; } // sm: 2 = enabled, 1 = disabled
 	}
-	else if(!strcmp(command, "xboard")) ;
 	else if(!strcmp(command, "analyze"))computer = ANALYZE, collect = 1, sm = 0, Analyze("true");
 	else if(!strcmp(command, "exit"))   computer = NONE, Analyze("false");
 	else if(!strcmp(command, "force"))  computer = NONE;
@@ -612,7 +615,6 @@ DoCommand ()
 	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, "name"))   { if(namOpt) EPRINT((f, "# setoption name UCI_Opponent value none none %s %s", comp ? "computer" : "human", line+5)) }
-	else if(!strcmp(command, "computer")) comp = 1;
 	else if(!strcmp(command, "result")) {
 	    if(sc == 's') EPRINT((f, "# gameover %s\n", line[8] == '/' ? "draw" : (line[7] == '0') == mySide ? "win" : "lose"))
 	    computer = NONE;
-- 
1.7.0.4