From a64950c749acfae48d68e2c713bf86d06f026822 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Tue, 16 Jun 2009 00:06:59 -0700 Subject: [PATCH] bugfix and enhancement in autoKibitz mode changed the format of the autoKibitz: score/depth in stead of depth/score, as in PGN. I also supress the ICS time for the move now in the PGN if extended info is available. When enhancing the functionality of the autoKibitz command (using the opponent engine kibitz for the saved PGN) I discovered that the xengineoutput.c in our tree was obsolete, and contained a routine of which the arguments were no longer compatble with the call from backend.c, and caused segfaulting. I copied in the corresponding routine in wengineo.c, which was compatible. That the compiler did not flag this is a sign of badly organized code, I suppose... The enhancement itself affected backend.c. --- backend.c | 30 +++++++++++++++++++++++------- xengineoutput.c | 21 +++++++++++++++------ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/backend.c b/backend.c index 0f24243..0b1b144 100644 --- a/backend.c +++ b/backend.c @@ -2276,6 +2276,12 @@ read_from_ics(isr, closure, data, count, error) nrAlph += (parse[i] >= 'A' && parse[i] <= 'Z'); } if(nrAlph < 9*nrDigit) { // if more than 10% digit we assume search info + int depth=0; float score; + if(sscanf(parse, "%f/%d", &score, &depth) == 2 && depth>0) { + // [HGM] kibitz: save kibitzed opponent info for PGN and eval graph + pvInfoList[forwardMostMove-1].depth = depth; + pvInfoList[forwardMostMove-1].score = 100*score; + } OutputKibitz(suppressKibitz, parse); } else { char tmp[MSG_SIZ]; @@ -5640,9 +5646,9 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if(appData.autoKibitz && !appData.icsEngineAnalyze ) { /* [HGM] kibitz: send most-recent PV info to ICS */ char buf[3*MSG_SIZ]; - sprintf(buf, "kibitz %d/%+.2f (%.2f sec, %.0f nodes, %1.0f knps) PV = %s\n", - programStats.depth, + sprintf(buf, "kibitz %+.2f/%d (%.2f sec, %.0f nodes, %1.0f knps) PV=%s\n", programStats.score / 100., + programStats.depth, programStats.time / 100., u64ToDouble(programStats.nodes), u64ToDouble(programStats.nodes) / (10*abs(programStats.time) + 1.), @@ -5700,6 +5706,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h int k, count = 0, epFile = epStatus[forwardMostMove]; static int bare = 1; if(gameInfo.holdingsSize == 0 || gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) { + if( appData.testLegality ) { /* [HGM] Some more adjudications for obstinate engines */ int NrWN=0, NrBN=0, NrWB=0, NrBB=0, NrWR=0, NrBR=0, @@ -9552,7 +9559,16 @@ SaveGamePGN(f) linelen += numlen; /* Get move */ - movelen = strlen(parseList[i]); /* [HGM] pgn: line-break point before move */ + strcpy(move_buffer, parseList[i]); // [HGM] pgn: print move via buffer, so it can be edited + movelen = strlen(move_buffer); /* [HGM] pgn: line-break point before move */ + if( i >= 0 && appData.saveExtendedInfoInPGN && pvInfoList[i].depth > 0 ) { + int p = movelen - 1; + if(move_buffer[p] == ' ') p--; + if(move_buffer[p] == ')') { // [HGM] pgn: strip off ICS time if we have extended info + while(p && move_buffer[--p] != '('); + if(p && move_buffer[p-1] == ' ') move_buffer[movelen=p-1] = 0; + } + } /* Print move */ blank = linelen > 0 && movelen > 0; @@ -9565,7 +9581,7 @@ SaveGamePGN(f) fprintf(f, " "); linelen++; } - fprintf(f, parseList[i]); + fprintf(f, move_buffer); linelen += movelen; /* [AS] Add PV info if present */ @@ -9573,14 +9589,14 @@ SaveGamePGN(f) /* [HGM] add time */ char buf[MSG_SIZ]; int seconds = 0; -#if 0 +#if 1 if(i >= backwardMostMove) { if(WhiteOnMove(i)) seconds = timeRemaining[0][i] - timeRemaining[0][i+1] - + GetTimeQuota(i/2) / WhitePlayer()->timeOdds; + + GetTimeQuota(i/2) / (1000*WhitePlayer()->timeOdds); else seconds = timeRemaining[1][i] - timeRemaining[1][i+1] - + GetTimeQuota(i/2) / WhitePlayer()->other->timeOdds; + + GetTimeQuota(i/2) / (1000*WhitePlayer()->other->timeOdds); } seconds = (seconds+50)/100; // deci-seconds, rounded to nearest #else diff --git a/xengineoutput.c b/xengineoutput.c index 0ff63c6..5bd07a8 100644 --- a/xengineoutput.c +++ b/xengineoutput.c @@ -954,13 +954,22 @@ EngineOutputProc(w, event, prms, nprms) } // [HGM] kibitz: write kibitz line; split window for it if necessary -void OutputKibitz(char *text) +void OutputKibitz(int window, char *text) { if(!EngineOutputIsUp()) return; - if(!opponentKibitzes) DoClearMemo(1); - opponentKibitzes = TRUE; // thas causes split window DisplayMode in ICS modes. + if(!opponentKibitzes) { // on first kibitz of game, clear memos + DoClearMemo(1); + if(gameMode == IcsObserving) DoClearMemo(0); + } + opponentKibitzes = TRUE; // this causes split window DisplayMode in ICS modes. VerifyDisplayMode(); - DoSetWindowText(1, nLabel, gameMode == IcsPlayingWhite ? gameInfo.black : gameInfo.white); // opponent name - SetIcon( 1, nColorIcon, gameMode == IcsPlayingWhite ? nColorBlack : nColorWhite); - InsertIntoMemo(1, text); + if(gameMode == IcsObserving) { + DoSetWindowText(0, nLabel, gameInfo.white); + SetIcon( 0, nColorIcon, nColorWhite); + SetIcon( 0, nStateIcon, nClear); + } + DoSetWindowText(1, nLabel, gameMode == IcsPlayingBlack ? gameInfo.white : gameInfo.black); // opponent name + SetIcon( 1, nColorIcon, gameMode == IcsPlayingBlack ? nColorWhite : nColorBlack); + SetIcon( 1, nStateIcon, nClear); + InsertIntoMemo(window-1, text); } -- 1.7.0.4