From 08c9436657f0649356c3b16d8cb8cafb0a3b8c31 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sat, 22 Aug 2009 17:07:10 -0700 Subject: [PATCH 1/1] fixed several bugs in the backend and added some more polyglot support * I added recognition for the new UCI3 option types that are recognized in the WB option features, to make sure this version is compatible with future Polyglots. Also fixed a bug that failed to strip an asterisk prefix from the first combo-box item. * I fixed the ICS-time-in-PGN bug. * I fixed a bug which caused a space to be missing when long lines broken up by an ICS were joined. --- backend.c | 41 ++++++++++++++++++++++++++++++++--------- backend.h | 5 +++-- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/backend.c b/backend.c index 40fb9ce..674b14a 100644 --- a/backend.c +++ b/backend.c @@ -2111,6 +2111,7 @@ read_from_ics(isr, closure, data, count, error) if(buf_len >= 5 && buf[buf_len-5]=='\n' && buf[buf_len-4]=='\\' && buf[buf_len-3]==' ' && buf[buf_len-2]==' ' && buf[buf_len-1]==' ') buf_len -= 5; // [HGM] ICS: join continuation line of Lasker 2.2.3 server with previous + buf[buf_len++] = ' '; // replace by space (assumes ICS does not break lines within word) } buf[buf_len] = NULLCHAR; @@ -5644,12 +5645,12 @@ 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 !!! %+.2f/%d (%.2f sec, %.0f nodes, %1.0f knps) PV=%s\n", + sprintf(buf, "kibitz !!! %+.2f/%d (%.2f sec, %u 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.), + (unsigned int)programStats.nodes, + (unsigned int)programStats.nodes / (10*abs(programStats.time) + 1.), programStats.movelist); SendToICS(buf); } @@ -6123,6 +6124,10 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h cps->useSigint = FALSE; cps->useSigterm = FALSE; } + if (strncmp(message, "feature ", 8) == 0) { // [HGM] moved forward to pre-empt non-compliant commands + ParseFeatures(message+8, cps); + return; // [HGM] This return was missing, causing option features to be recognized as non-compliant commands! + } /* [HGM] Allow engine to set up a position. Don't ask me why one would * want this, I was asked to put it in, and obliged. @@ -6227,9 +6232,6 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h return; } } - if (strncmp(message, "feature ", 8) == 0) { - ParseFeatures(message+8, cps); - } if (sscanf(message, "pong %d", &cps->lastPong) == 1) { return; } @@ -9602,8 +9604,10 @@ SaveGamePGN(f) linelen += numlen; /* Get move */ - strcpy(move_buffer, parseList[i]); // [HGM] pgn: print move via buffer, so it can be edited + strcpy(move_buffer, SavePart(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 0 + // SavePart already does this! if( i >= 0 && appData.saveExtendedInfoInPGN && pvInfoList[i].depth > 0 ) { int p = movelen - 1; if(move_buffer[p] == ' ') p--; @@ -9612,7 +9616,7 @@ SaveGamePGN(f) if(p && move_buffer[p-1] == ' ') move_buffer[movelen=p-1] = 0; } } - +#endif /* Print move */ blank = linelen > 0 && movelen > 0; if (linelen + (blank ? 1 : 0) + movelen > PGN_MAX_LINE) { @@ -12382,9 +12386,27 @@ ParseOption(Option *opt, ChessProgramState *cps) opt->min = min; opt->max = max; opt->type = Spin; - } else if(p = strstr(opt->name, " -string ")) { + } else if((p = strstr(opt->name, " -slider "))) { + // for now -slider is a synonym for -spin, to already provide compatibility with future polyglots + if((n = sscanf(p, " -slider %d %d %d", &def, &min, &max)) < 3 ) return FALSE; + if(max < min) max = min; // enforce consistency + if(def < min) def = min; + if(def > max) def = max; + opt->value = def; + opt->min = min; + opt->max = max; + opt->type = Spin; // Slider; + } else if((p = strstr(opt->name, " -string "))) { opt->textValue = p+9; opt->type = TextBox; + } else if((p = strstr(opt->name, " -file "))) { + // for now -file is a synonym for -string, to already provide compatibility with future polyglots + opt->textValue = p+7; + opt->type = TextBox; // FileName; + } else if((p = strstr(opt->name, " -path "))) { + // for now -file is a synonym for -string, to already provide compatibility with future polyglots + opt->textValue = p+7; + opt->type = TextBox; // PathName; } else if(p = strstr(opt->name, " -check ")) { if(sscanf(p, " -check %d", &def) < 1) return FALSE; opt->value = (def != 0); @@ -12392,6 +12414,7 @@ ParseOption(Option *opt, ChessProgramState *cps) } else if(p = strstr(opt->name, " -combo ")) { opt->textValue = (char*) (&cps->comboList[cps->comboCnt]); // cheat with pointer type cps->comboList[cps->comboCnt++] = q = p+8; // holds possible choices + if(*q == '*') cps->comboList[cps->comboCnt-1]++; opt->value = n = 0; while(q = StrStr(q, " /// ")) { n++; *q = 0; // count choices, and null-terminate each of them diff --git a/backend.h b/backend.h index 81d0566..f02835f 100644 --- a/backend.h +++ b/backend.h @@ -255,7 +255,8 @@ char * GameListLineFull P(( int, GameInfo *)); extern char* StripHighlight P((char *)); /* returns static data */ extern char* StripHighlightAndTitle P((char *)); /* returns static data */ -typedef enum { CheckBox, ComboBox, TextBox, Button, Spin, SaveButton } Control; +typedef enum { CheckBox, ComboBox, TextBox, Button, Spin, + SaveButton, FileName, PathName, Slider, Message } Control; typedef struct _OPT { // [HGM] options: descriptor of UCI-style option int value; // current setting, starts as default @@ -328,7 +329,7 @@ typedef struct _CPS { char egtFormats[MSG_SIZ]; /* [HGM] EGT: supported tablebase formats */ int bookSuspend; /* [HGM] book: go was deferred because of book hit */ int nrOptions; /* [HGM] options: remembered option="..." features */ -#define MAX_OPTIONS 100 +#define MAX_OPTIONS 200 Option option[MAX_OPTIONS]; int comboCnt; char *comboList[20*MAX_OPTIONS]; -- 1.7.0.4