From f29ff21f23c2a22fc55e14ba48c53d704c22289d Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Thu, 18 Aug 2011 18:53:09 +0200 Subject: [PATCH] Allow two-games-per-opening to work with book A new option -seedBase is added, and written to the tourney file. It allows all XBoard instances working on a tourney to generate the same 'random' openings in a deterministic way, based on this one-time seed and the game number. When -loadGameIndex equals -2, it uses the same seed for an odd and the following even game. --- args.h | 1 + backend.c | 3 +++ common.h | 1 + winboard/wsettings.c | 3 ++- 4 files changed, 7 insertions(+), 1 deletions(-) diff --git a/args.h b/args.h index 32350ba..bbdaeeb 100644 --- a/args.h +++ b/args.h @@ -577,6 +577,7 @@ ArgDescriptor argDescriptors[] = { { "results", ArgString, (void *) &appData.results, FALSE, (ArgIniType) "" }, { "syncAfterRound", ArgBoolean, (void *) &appData.roundSync, FALSE, (ArgIniType) FALSE }, { "syncAfterCycle", ArgBoolean, (void *) &appData.cycleSync, FALSE, (ArgIniType) TRUE }, + { "seedBase", ArgInt, (void *) &appData.seedBase, FALSE, (ArgIniType) 1 }, /* [HGM] board-size, adjudication and misc. options */ { "oneClickMove", ArgBoolean, (void *) &appData.oneClick, TRUE, (ArgIniType) FALSE }, diff --git a/backend.c b/backend.c index 05ce951..26ebe3c 100644 --- a/backend.c +++ b/backend.c @@ -981,6 +981,7 @@ InitBackEnd1() GetTimeMark(&programStartTime); srandom((programStartTime.ms + 1000*programStartTime.sec)*0x1001001); // [HGM] book: makes sure random is unpredictabe to msec level + appData.seedBase = random() + (random()<<15); pauseStart = programStartTime; pauseStart.sec -= 100; // [HGM] matchpause: fake a pause that has long since ended ClearProgramStats(); @@ -9726,6 +9727,7 @@ WriteTourneyFile(char *results, FILE *f) if(f == NULL) DisplayError(_("Could not write on tourney file"), 0); else { // create a file with tournament description fprintf(f, "-participants {%s}\n", appData.participants); + fprintf(f, "-seedBase %d\n", appData.seedBase); fprintf(f, "-tourneyType %d\n", appData.tourneyType); fprintf(f, "-tourneyCycles %d\n", appData.tourneyCycles); fprintf(f, "-defaultMatchGames %d\n", appData.defaultMatchGames); @@ -10026,6 +10028,7 @@ NextMatchGame() first.twoMachinesColor = firstWhite ? "white\n" : "black\n"; // perform actual color assignement second.twoMachinesColor = firstWhite ? "black\n" : "white\n"; appData.noChessProgram = (first.pr == NoProc); // kludge to prevent Reset from starting up chess program + if(appData.loadGameIndex == -2) srandom(appData.seedBase + 68163*(nextGame & ~1)); // deterministic seed to force same opening Reset(FALSE, first.pr != NoProc); appData.noChessProgram = FALSE; if(!LoadGameOrPosition(matchGame)) return; // setup game; abort when bad game/pos file diff --git a/common.h b/common.h index 5f8f5f1..b45fcf1 100644 --- a/common.h +++ b/common.h @@ -669,6 +669,7 @@ typedef struct { char *participants; int tourneyType; int tourneyCycles; + int seedBase; Boolean roundSync; Boolean cycleSync; } AppData, *AppDataPtr; diff --git a/winboard/wsettings.c b/winboard/wsettings.c index bfad588..6fc5c40 100644 --- a/winboard/wsettings.c +++ b/winboard/wsettings.c @@ -694,6 +694,7 @@ char *tfName; int MatchOK() { if(autoinc) appData.loadGameIndex = appData.loadPositionIndex = -(twice + 1); + if(!appData.loadGameFile[0]) appData.loadGameIndex = -2*twice; // kludge to pass value of "twice" for use in GUI book if(swiss) { appData.defaultMatchGames = 1; appData.tourneyType = -1; } if(CreateTourney(tfName) && !matchMode) { // CreateTourney reloads original settings if file already existed MatchEvent(2); @@ -771,7 +772,7 @@ void TourneyPopup(HWND hwnd) NamesToList(firstChessProgramNames, engineList, engineMnemonic); comboCallback = &AddToTourney; autoinc = appData.loadGameIndex < 0 || appData.loadPositionIndex < 0; - twice = TRUE; swiss = appData.tourneyType < 0; + twice = FALSE; swiss = appData.tourneyType < 0; while(engineList[n]) n++; tourneyOptions[3].max = n-1; snprintf(title, MSG_SIZ, _("Tournament and Match Options")); ASSIGN(tfName, appData.tourneyFile[0] ? appData.tourneyFile : MakeName(appData.defName)); -- 1.7.0.4