X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=5ae5525bc14792f8ee0d7a8984b036c542dbdfd2;hb=873f7b33a08877e546e16f63a3a70dae8b3633aa;hp=b8cfa92f2ceacc4fbf810305c9e9b49ecc4c22ef;hpb=ea750683ac62717dd7346de17b5ae072622ff92a;p=xboard.git diff --git a/backend.c b/backend.c index b8cfa92..5ae5525 100644 --- a/backend.c +++ b/backend.c @@ -2,8 +2,10 @@ * backend.c -- Common back end for X and Windows NT versions of * XBoard $Id: backend.c,v 2.6 2003/11/28 09:37:36 mann Exp $ * - * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts. - * Enhancements Copyright 1992-2001 Free Software Foundation, Inc. + * Copyright 1991 by Digital Equipment Corporation, Maynard, + * Massachusetts. Enhancements Copyright + * 1992-2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software + * Foundation, Inc. * * The following terms apply to Digital Equipment Corporation's copyright * interest in XBoard: @@ -27,25 +29,25 @@ * SOFTWARE. * ------------------------------------------------------------------------ * - * The following terms apply to the enhanced version of XBoard distributed - * by the Free Software Foundation: + * The following terms apply to the enhanced version of XBoard + * distributed by the Free Software Foundation: * ------------------------------------------------------------------------ - * This program is free software; you can redistribute it and/or modify + * + * GNU XBoard is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU XBoard is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ------------------------------------------------------------------------ + * along with this program. If not, see http://www.gnu.org/licenses/. * * - * See the file ChangeLog for a revision history. */ + *------------------------------------------------------------------------ + ** See the file ChangeLog for a revision history. */ /* [AS] Also useful here for debugging */ #ifdef WIN32 @@ -759,6 +761,10 @@ InitBackEnd1() first.debug = second.debug = FALSE; first.supportsNPS = second.supportsNPS = UNKNOWN; + /* [HGM] options */ + first.optionSettings = appData.firstOptions; + second.optionSettings = appData.secondOptions; + first.scoreIsAbsolute = appData.firstScoreIsAbsolute; /* [AS] */ second.scoreIsAbsolute = appData.secondScoreIsAbsolute; /* [AS] */ first.isUCI = appData.firstIsUCI; /* [AS] */ @@ -5990,6 +5996,8 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h EP_NONE, castlingRights[m-1]) != MT_CHECK) hisPerpetual = 0; // the opponent did not always check } + if(appData.debugMode) fprintf(debugFP, "XQ perpetual test, our=%d, his=%d\n", + ourPerpetual, hisPerpetual); if(ourPerpetual && !hisPerpetual) { // we are actively checking him: forfeit GameEnds( WhiteOnMove(forwardMostMove) ? WhiteWins : BlackWins, "Xboard adjudication: perpetual checking", GE_XBOARD ); @@ -5997,8 +6005,19 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h } if(hisPerpetual && !ourPerpetual) // he is checking us, but did not repeat yet break; // (or we would have caught him before). Abort repetition-checking loop. - // if neither of us is checking all the time, or both are, it is draw - // (illegal-chase forfeits not implemented yet!) + // Now check for perpetual chases + if(!ourPerpetual && !hisPerpetual) { // no perpetual check, test for chase + hisPerpetual = PerpetualChase(k, forwardMostMove); + ourPerpetual = PerpetualChase(k+1, forwardMostMove); + if(ourPerpetual && !hisPerpetual) { // we are actively checking him: forfeit + GameEnds( WhiteOnMove(forwardMostMove) ? WhiteWins : BlackWins, + "Xboard adjudication: perpetual chasing", GE_XBOARD ); + return; + } + if(hisPerpetual && !ourPerpetual) // he is chasing us, but did not repeat yet + break; // Abort repetition-checking loop. + } + // if neither of us is checking or chasing all the time, or both are, it is draw } GameEnds( GameIsDrawn, "Xboard adjudication: repetition draw", GE_XBOARD ); return; @@ -7331,15 +7350,15 @@ MakeMove(fromX, fromY, toX, toY, promoChar) int fromX, fromY, toX, toY; int promoChar; { - forwardMostMove++; +// forwardMostMove++; // [HGM] bare: moved downstream - if(serverMoves != NULL) { /* [HGM] write moves on file for broadcasting */ + if(serverMoves != NULL) { /* [HGM] write moves on file for broadcasting (should be separate routine, really) */ int timeLeft; static int lastLoadFlag=0; int king, piece; - piece = boards[forwardMostMove-1][fromY][fromX]; + piece = boards[forwardMostMove][fromY][fromX]; king = piece < (int) BlackPawn ? WhiteKing : BlackKing; if(gameInfo.variant == VariantKnightmate) king += (int) WhiteUnicorn - (int) WhiteKing; - if(forwardMostMove == 1) { + if(forwardMostMove == 0) { if(blackPlaysFirst) fprintf(serverMoves, "%s;", second.tidy); fprintf(serverMoves, "%s;", first.tidy); @@ -7357,9 +7376,9 @@ MakeMove(fromX, fromY, toX, toY, promoChar) fprintf(serverMoves, ":%c%c:%c%c", AAA+BOARD_LEFT, ONE+fromY, AAA+toX+1,ONE+toY); } // e.p. suffix - if( (boards[forwardMostMove-1][fromY][fromX] == WhitePawn || - boards[forwardMostMove-1][fromY][fromX] == BlackPawn ) && - boards[forwardMostMove-1][toY][toX] == EmptySquare + if( (boards[forwardMostMove][fromY][fromX] == WhitePawn || + boards[forwardMostMove][fromY][fromX] == BlackPawn ) && + boards[forwardMostMove][toY][toX] == EmptySquare && fromX != toX ) fprintf(serverMoves, ":%c%c:%c%c", AAA+fromX, ONE+fromY, AAA+toX, ONE+fromY); // promotion suffix @@ -7367,28 +7386,29 @@ MakeMove(fromX, fromY, toX, toY, promoChar) fprintf(serverMoves, ":%c:%c%c", promoChar, AAA+toX, ONE+toY); if(!loadFlag) { fprintf(serverMoves, "/%d/%d", - pvInfoList[forwardMostMove-1].depth, pvInfoList[forwardMostMove-1].score); - if(forwardMostMove & 1) timeLeft = whiteTimeRemaining/1000; - else timeLeft = blackTimeRemaining/1000; + pvInfoList[forwardMostMove].depth, pvInfoList[forwardMostMove].score); + if(forwardMostMove+1 & 1) timeLeft = whiteTimeRemaining/1000; + else timeLeft = blackTimeRemaining/1000; fprintf(serverMoves, "/%d", timeLeft); } fflush(serverMoves); } - if (forwardMostMove >= MAX_MOVES) { + if (forwardMostMove+1 >= MAX_MOVES) { DisplayFatalError(_("Game too long; increase MAX_MOVES and recompile"), 0, 1); return; } SwitchClocks(); - timeRemaining[0][forwardMostMove] = whiteTimeRemaining; - timeRemaining[1][forwardMostMove] = blackTimeRemaining; - if (commentList[forwardMostMove] != NULL) { - free(commentList[forwardMostMove]); - commentList[forwardMostMove] = NULL; - } - CopyBoard(boards[forwardMostMove], boards[forwardMostMove - 1]); - ApplyMove(fromX, fromY, toX, toY, promoChar, boards[forwardMostMove]); + timeRemaining[0][forwardMostMove+1] = whiteTimeRemaining; + timeRemaining[1][forwardMostMove+1] = blackTimeRemaining; + if (commentList[forwardMostMove+1] != NULL) { + free(commentList[forwardMostMove+1]); + commentList[forwardMostMove+1] = NULL; + } + CopyBoard(boards[forwardMostMove+1], boards[forwardMostMove]); + ApplyMove(fromX, fromY, toX, toY, promoChar, boards[forwardMostMove+1]); + forwardMostMove++; // [HGM] bare: moved to after ApplyMove, to make sure clock interrupt finds complete board gameInfo.result = GameUnfinished; if (gameInfo.resultDetails != NULL) { free(gameInfo.resultDetails); @@ -12377,6 +12397,14 @@ ParseOption(Option *opt, ChessProgramState *cps) opt->type = SaveButton; } else return FALSE; *p = 0; // terminate option name + // now look if the command-line options define a setting for this engine option. + p = strstr(cps->optionSettings, opt->name); + if(p == cps->optionSettings || p[-1] == ',') { + sprintf(buf, "option %s", p); + if(p = strstr(buf, ",")) *p = 0; + strcat(buf, "\n"); + SendToProgram(buf, cps); + } return TRUE; } @@ -12584,6 +12612,8 @@ DisplayMove(moveNumber) char res[MSG_SIZ]; char cpThinkOutput[MSG_SIZ]; + if(appData.noGUI) return; // [HGM] fast: suppress display of moves + if (moveNumber == forwardMostMove - 1 || gameMode == AnalyzeMode || gameMode == AnalyzeFile) { @@ -12621,7 +12651,7 @@ DisplayMove(moveNumber) } else { res[0] = NULLCHAR; } - + if (moveNumber < 0 || parseList[moveNumber][0] == NULLCHAR) { DisplayMessage(res, cpThinkOutput); } else { @@ -12869,6 +12899,11 @@ DisplayBothClocks() you have neither ftime nor gettimeofday. */ +/* VS 2008 requires the #include outside of the function */ +#if !HAVE_GETTIMEOFDAY && HAVE_FTIME +#include +#endif + /* Get the current time as a TimeMark */ void GetTimeMark(tm)