From: H.G.Muller Date: Tue, 4 Mar 2014 07:46:44 +0000 (+0100) Subject: Implement periodic updates X-Git-Url: http://winboard.nl/cgi-bin?p=gnushogi.git;a=commitdiff_plain;h=a5dcd4c22b91b752f4d7c831318311f14125a29d Implement periodic updates The . command now causes printing of a stat01 command, without aborting the analysis in progress. To achieve this, InputCommand is called during search when polling reveals there is input. In this case it (currently) only processes the . command, returning a value that informs the caller the search should not be aborted. Other commands are backlogged, and will cause the usual search abort. When InputCommand is then again called from main it picks up the backlogged command in stead of reading one from input. --- diff --git a/gnushogi/commondsp.c b/gnushogi/commondsp.c index ba56401..e35698d 100644 --- a/gnushogi/commondsp.c +++ b/gnushogi/commondsp.c @@ -1493,8 +1493,8 @@ SetMachineTime(char *time) * the hint move, then set Sdepth to zero. */ -void -InputCommand(char *command) +int +InputCommand(char *command, int root) { #ifdef QUIETBACKGROUND short have_shown_prompt = false; @@ -1502,6 +1502,7 @@ InputCommand(char *command) short ok, done, is_move = false; unsigned short mv; char s[80], sx[80]; + static char backlog[80]; ok = flag.quit = done = false; player = opponent; @@ -1511,7 +1512,7 @@ InputCommand(char *command) ZeroTTable(); #endif - if ((hint > 0) && !flag.easy && !flag.force && !command) + if ((hint > 0) && !flag.easy && !flag.force && !command && !backlog[0] && root) { /* * A hint move for the player is available. Compute a move for the @@ -1575,7 +1576,7 @@ InputCommand(char *command) { player = opponent; - if (flag.analyze && !command) { + if (flag.analyze && !command && !backlog[0] && root) { SelectMove(opponent, BACKGROUND_MODE); } @@ -1592,12 +1593,15 @@ InputCommand(char *command) have_shown_prompt = false; #endif /* QUIETBACKGROUND */ + if (!command && backlog[0]) command = backlog; /* pick up backlogged command */ + if (command == NULL) { int eof = dsp->GetString(sx); if (eof) dsp->ExitShogi(); } else { strcpy(sx, command); + backlog[0]= '\0'; /* make sure no backlog is left */ done = true; } @@ -1605,6 +1609,12 @@ InputCommand(char *command) if (sscanf(sx, "%s", s) < 1) continue; + if (!root && strcmp(s, ".")) + { /* during search most commands can only be done after abort */ + strcpy(backlog, sx); /* backlog the command */ + return true; /* and order search abort */ + } + if (strcmp(s, "bd") == 0) /* bd -- display board */ { /* FIXME: Hack alert! */ @@ -1670,7 +1680,13 @@ InputCommand(char *command) printf("debug=1 setboard=0 sigint=0 done=1\n"); } else if (strcmp(s, ".") == 0) - { // ignore for now + { // periodic update request of analysis info: send stat01 info + ElapsedTime(2); + algbr((short)(currentMove >> 8), (short)(currentMove & 0xFF), 0); + printf("stat01: %4ld %8ld %2d %2d %2d %s\n", + et, NodeCnt, Sdepth, movesLeft, TrPnt[2]-TrPnt[1], mvstr[0]); + fflush(stdout); + if (!root) return false; /* signal no abort needed */ } else if (strcmp(s, "exit") == 0) { @@ -2032,4 +2048,6 @@ InputCommand(char *command) ++mycnt2, s, TimeControl.clock[player] * 10); } } + + return true; } diff --git a/gnushogi/gnushogi.h b/gnushogi/gnushogi.h index 0e3e0de..dd5c21e 100644 --- a/gnushogi/gnushogi.h +++ b/gnushogi/gnushogi.h @@ -1042,7 +1042,7 @@ extern void UpdateWeights(short side); extern int InitMain(void); extern void ExitMain(void); extern void Initialize(void); -extern void InputCommand(char *command); +extern int InputCommand(char *command, int root); extern void ExitShogi(void); extern void ClearScreen(void); extern void SetTimeControl(void); @@ -1116,6 +1116,7 @@ typedef enum extern int VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv); extern unsigned short TTage; +extern short movesLeft, currentMove; /* display driver framework */ diff --git a/gnushogi/main.c b/gnushogi/main.c index d9fae21..8164d42 100644 --- a/gnushogi/main.c +++ b/gnushogi/main.c @@ -380,7 +380,7 @@ main (int argc, char **argv) if (flag.bothsides && !flag.mate) SelectMove(opponent, FOREGROUND_MODE); else - InputCommand(NULL); + InputCommand(NULL, true); if (opponent == white) { diff --git a/gnushogi/rawdsp.c b/gnushogi/rawdsp.c index 033d93b..ee40dcf 100644 --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@ -980,7 +980,7 @@ Raw_PollForInput(void) Raw_ExitShogi(); } #endif - if (cnt) { /* if anything to read, or error occured */ + if (cnt && InputCommand(NULL, false)) { /* if anything to read, or error occured */ if (!flag.timeout) flag.back = true; /* previous: flag.timeout = true; */ flag.bothsides = false; diff --git a/gnushogi/search.c b/gnushogi/search.c index 1c4bbf7..7272095 100644 --- a/gnushogi/search.c +++ b/gnushogi/search.c @@ -44,6 +44,7 @@ short PVari; /* Is this the PV */ #endif short zwndw; +short movesLeft, currentMove; @@ -872,6 +873,8 @@ search(short side, #endif /* QUIETBACKGROUND */ dsp->ShowCurrentMove(pnt, node->f, node->t); } + movesLeft = TrPnt[2] - pnt; /* to report with XBoard periodic updates */ + currentMove = node->f << 8 | node->t; } if (!(node->flags & exact))