X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=c6eedec7f5a35c86b2f0f6201094d286da9a29d1;hb=f4f20b290bc05bdd35be748a9282adcbdc582534;hp=e2aa771d5874bacd19f014a18a756667d88dbf53;hpb=08d1691b8c734f49773076a001059a59812505d0;p=xboard.git diff --git a/backend.c b/backend.c index e2aa771..c6eedec 100755 --- a/backend.c +++ b/backend.c @@ -607,7 +607,7 @@ InitBackEnd1() ShowThinkingEvent(); // [HGM] thinking: make sure post/nopost state is set according to options GetTimeMark(&programStartTime); - srandom(programStartTime.ms); // [HGM] book: makes sure random is unpredictabe to msec level + srandom((programStartTime.ms + 1000*programStartTime.sec)*0x1001001); // [HGM] book: makes sure random is unpredictabe to msec level ClearProgramStats(); programStats.ok_to_send = 1; @@ -1977,7 +1977,7 @@ VariantSwitch(Board board, VariantClass newVariant) case VariantSuper: newHoldingsWidth = 2; gameInfo.holdingsSize = 8; - return; + break; case VariantGothic: case VariantCapablanca: case VariantCapaRandom: @@ -2011,10 +2011,8 @@ VariantSwitch(Board board, VariantClass newVariant) gameInfo.holdingsWidth = newHoldingsWidth; gameInfo.variant = newVariant; InitDrawingSizes(-2, 0); - InitPosition(FALSE); /* this sets up board[0], but also other stuff */ - } else { gameInfo.variant = newVariant; InitPosition(FALSE); } - - DrawPosition(TRUE, boards[currentMove]); + InitPosition(TRUE); /* this sets up board[0], but also other stuff */ + } else { gameInfo.variant = newVariant; InitPosition(TRUE); } } static int loggedOn = FALSE; @@ -2731,7 +2729,7 @@ read_from_ics(isr, closure, data, count, error) moves and soak them up so user can step through them and/or save them. */ - Reset(FALSE, TRUE); + Reset(TRUE, TRUE); gameMode = IcsObserving; ModeHighlight(); ics_gamenum = -1; @@ -3303,8 +3301,8 @@ read_from_ics(isr, closure, data, count, error) white_holding[strlen(white_holding)-1] = NULLCHAR; black_holding[strlen(black_holding)-1] = NULLCHAR; /* [HGM] copy holdings to board holdings area */ - CopyHoldings(boards[currentMove], white_holding, WhitePawn); - CopyHoldings(boards[currentMove], black_holding, BlackPawn); + CopyHoldings(boards[forwardMostMove], white_holding, WhitePawn); + CopyHoldings(boards[forwardMostMove], black_holding, BlackPawn); #if ZIPPY if (appData.zippyPlay && first.initDone) { ZippyHoldings(white_holding, black_holding, @@ -3426,7 +3424,7 @@ ParseBoard12(string) &white_stren, &black_stren, &white_time, &black_time, &moveNum, str, elapsed_time, move_str, &ics_flip, &ticking); -fprintf(debugFP, "old: %dx%d new: %dx%d weird=%d variant=%d\n",gameInfo.boardHeight,gameInfo.boardWidth,ranks,files,weird,gameInfo.variant);fflush(debugFP); + if (gameInfo.boardHeight != ranks || gameInfo.boardWidth != files || weird && (int)gameInfo.variant <= (int)VariantShogi) { /* [HGM] We seem to switch variant during a game! @@ -3436,7 +3434,8 @@ fprintf(debugFP, "old: %dx%d new: %dx%d weird=%d variant=%d\n",gameInfo.boardH if(ranks == 8 && files == 10) newVariant = VariantCapablanca; else if(ranks == 10 && files == 9) newVariant = VariantXiangqi; else if(ranks == 8 && files == 12) newVariant = VariantCourier; else - if(ranks == 9 && files == 9) newVariant = VariantShogi; + if(ranks == 9 && files == 9) newVariant = VariantShogi; else + if(!weird) newVariant = VariantNormal; VariantSwitch(boards[currentMove], newVariant); /* temp guess */ /* Get a move list just to see the header, which will tell us whether this is really bug or zh */ @@ -3531,7 +3530,7 @@ fprintf(debugFP, "old: %dx%d new: %dx%d weird=%d variant=%d\n",gameInfo.boardH /* Forget the old game and get the history (if any) of the new one */ if (gameMode != BeginningOfGame) { - Reset(FALSE, TRUE); + Reset(TRUE, TRUE); } newGame = TRUE; if (appData.autoRaiseBoard) BoardToTop(); @@ -3721,15 +3720,6 @@ fprintf(debugFP, "old: %dx%d new: %dx%d weird=%d variant=%d\n",gameInfo.boardH /* Update currentMove and known move number limits */ newMove = newGame || moveNum > forwardMostMove; - /* [DM] If we found takebacks during icsEngineAnalyze try send to engine */ - if (!newGame && appData.icsEngineAnalyze && moveNum < forwardMostMove) { - takeback = forwardMostMove - moveNum; - for (i = 0; i < takeback; i++) { - if (appData.debugMode) fprintf(debugFP, "take back move\n"); - SendToProgram("undo\n", &first); - } - } - if (newGame) { forwardMostMove = backwardMostMove = currentMove = moveNum; if (gameMode == IcsExamining && moveNum == 0) { @@ -3742,6 +3732,20 @@ fprintf(debugFP, "old: %dx%d new: %dx%d weird=%d variant=%d\n",gameInfo.boardH } } else if (moveNum == forwardMostMove + 1 || moveNum == forwardMostMove || (moveNum < forwardMostMove && moveNum >= backwardMostMove)) { +#if ZIPPY + /* [DM] If we found takebacks during icsEngineAnalyze try send to engine */ + /* [HGM] applied this also to an engine that is silently watching */ + if (appData.zippyPlay && moveNum < forwardMostMove && first.initDone && + (gameMode == IcsObserving || gameMode == IcsExamining) && + gameInfo.variant == currentlyInitializedVariant) { + takeback = forwardMostMove - moveNum; + for (i = 0; i < takeback; i++) { + if (appData.debugMode) fprintf(debugFP, "take back move\n"); + SendToProgram("undo\n", &first); + } + } +#endif + forwardMostMove = moveNum; if (!pausing || currentMove > forwardMostMove) currentMove = forwardMostMove; @@ -3752,12 +3756,20 @@ fprintf(debugFP, "old: %dx%d new: %dx%d weird=%d variant=%d\n",gameInfo.boardH forwardMostMove = pauseExamForwardMostMove; return; } - forwardMostMove = backwardMostMove = currentMove = moveNum; if (gameMode == IcsExamining && moveNum > 0 && appData.getMoveList) { +#if ZIPPY + if(appData.zippyPlay && forwardMostMove > 0 && first.initDone) { + // [HGM] when we will receive the move list we now request, it will be + // fed to the engine from the first move on. So if the engine is not + // in the initial position now, bring it there. + InitChessProgram(&first, 0); + } +#endif ics_getting_history = H_REQUESTED; sprintf(str, "%smoves %d\n", ics_prefix, gamenum); SendToICS(str); } + forwardMostMove = backwardMostMove = currentMove = moveNum; } /* Update the clocks */ @@ -6423,7 +6435,7 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. DisplayError(_("Bad FEN received from engine"), 0); return ; } else { - Reset(FALSE, FALSE); + Reset(TRUE, FALSE); CopyBoard(boards[0], initial_position); initialRulePlies = FENrulePlies; epStatus[0] = FENepStatus; @@ -7966,7 +7978,7 @@ TwoMachinesEventIfReady P((void)) void NextMatchGame P((void)) { - int index; /* [HGM] autoinc: step lod index during match */ + int index; /* [HGM] autoinc: step load index during match */ Reset(FALSE, TRUE); if (*appData.loadGameFile != NULLCHAR) { index = appData.loadGameIndex;