From 7a5a8ea11998209db6c9a3184633b3ad4ca9b7cf Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sun, 8 May 2011 13:02:52 +0200 Subject: [PATCH] Allow changing MultiPV setting from Engine-Output window In analyze mode a header line is printed in the first engine-output pane, which can be right-clicked to increase or decrease the number of PVs. (Only with engines that support the MultiPV option.) --- backend.c | 25 ++++++++++++++++++++++--- backend.h | 1 + engineoutput.c | 12 +++++++++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/backend.c b/backend.c index a2c554f..fa46773 100644 --- a/backend.c +++ b/backend.c @@ -5315,22 +5315,41 @@ fprintf(debugFP,"parsePV: %d %c%c%c%c yy='%s'\nPV = '%s'\n", valid, fromX+AAA, f DrawPosition(TRUE, boards[currentMove]); } +int +MultiPV(ChessProgramState *cps) +{ // check if engine supports MultiPV, and if so, return the nmber of the option that sets it + int i; + for(i=0; inrOptions; i++) + if(!strcmp(cps->option[i].name, "MultiPV") && cps->option[i].type == Spin) + return i; + return -1; +} + Boolean LoadMultiPV(int x, int y, char *buf, int index, int *start, int *end) { - int startPV; - char *p; + int startPV, multi, lineStart, origIndex = index; + char *p, buf2[MSG_SIZ]; if(index < 0 || index >= strlen(buf)) return FALSE; // sanity lastX = x; lastY = y; while(index > 0 && buf[index-1] != '\n') index--; // beginning of line - startPV = index; + lineStart = startPV = index; while(buf[index] != '\n') if(buf[index++] == '\t') startPV = index; if(index == startPV && (p = StrCaseStr(buf+index, "PV="))) startPV = p - buf + 3; index = startPV; do{ while(buf[index] && buf[index] != '\n') index++; } while(buf[index] == '\n' && buf[index+1] == '\\' && buf[index+2] == ' ' && index++); // join kibitzed PV continuation line buf[index] = 0; + if(lineStart == 0 && gameMode == AnalyzeMode && (multi = MultiPV(&first)) >= 0) { + int n = first.option[multi].value; + if(origIndex < 10) { if(n>1) n--; } else if(origIndex > index - 6) n++; + snprintf(buf2, MSG_SIZ, "option MultiPV=%d\n", n); + if(first.option[multi].value != n) SendToProgram(buf2, &first); + first.option[multi].value = n; + *start = *end = 0; + return TRUE; + } ParsePV(buf+startPV, FALSE, !shiftKey); *start = startPV; *end = index-1; return TRUE; diff --git a/backend.h b/backend.h index 8e499dd..ebcc74f 100644 --- a/backend.h +++ b/backend.h @@ -417,5 +417,6 @@ extern int errorExitStatus; void SettingsPopUp P((ChessProgramState *cps)); // [HGM] really in front-end, but CPS not known in frontend.h int WaitForEngine P((ChessProgramState *cps, DelayedEventCallback x)); void Load P((ChessProgramState *cps, int n)); +int MultiPV P((ChessProgramState *cps)); #endif /* _BACKEND */ diff --git a/engineoutput.c b/engineoutput.c index f37b9c2..12081f5 100644 --- a/engineoutput.c +++ b/engineoutput.c @@ -70,6 +70,7 @@ static int lastDepth[2] = { -1, -1 }; static int lastForwardMostMove[2] = { -1, -1 }; static int engineState[2] = { -1, -1 }; static char lastLine[2][MSG_SIZ]; +static char header[MSG_SIZ]; #define MAX_VAR 400 static int scores[MAX_VAR], textEnd[MAX_VAR], curDepth[2], nrVariations[2]; @@ -111,8 +112,7 @@ void SetProgramStats( FrontEndProgramStats * stats ) // now directly called by b { EngineOutputData ed; int clearMemo = FALSE; - int which; - int depth; + int which, depth, multi; if( stats == 0 ) { SetEngineState( 0, STATE_IDLE, "" ); @@ -171,6 +171,12 @@ void SetProgramStats( FrontEndProgramStats * stats ) // now directly called by b if( clearMemo ) { DoClearMemo(which); nrVariations[which] = 0; + header[0] = NULLCHAR; + if(gameMode == AnalyzeMode && (multi = MultiPV(&first)) >= 0) { + snprintf(header, MSG_SIZ, "\t\t\t\tfewer / Multi-PV setting = %d / more\n", + first.option[multi].value); + InsertIntoMemo( which, header, 0); + } else if(appData.ponderNextMove && lastLine[which][0]) { InsertIntoMemo( which, lastLine[which], 0 ); InsertIntoMemo( which, "\n", 0 ); @@ -345,7 +351,7 @@ static int InsertionPoint( int len, EngineOutputData * ed ) scores[n] = newScore; } nrVariations[n] += 2; - return offs; + return offs + (gameMode == AnalyzeMode)*strlen(header); } -- 1.7.0.4