X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=0e36ec2b3452c8272ce08e964a5b2e20099c455b;hb=8266210f545277e589f08fc68f42900dc04a9366;hp=7dfb130b565c5fbcb86892766d19f788f90fcf69;hpb=90f6f34297e5405cef465d82f14bbda2674f032f;p=xboard.git diff --git a/backend.c b/backend.c index 7dfb130..0e36ec2 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 @@ -68,6 +70,7 @@ #include #include #include +#include #if STDC_HEADERS # include @@ -208,6 +211,10 @@ void ParseFeatures P((char* args, ChessProgramState *cps)); void InitBackEnd3 P((void)); void FeatureDone P((ChessProgramState* cps, int val)); void InitChessProgram P((ChessProgramState *cps, int setup)); +void OutputKibitz(int window, char *text); +int PerpetualChase(int first, int last); +int EngineOutputIsUp(); +void InitDrawingSizes(int x, int y); #ifdef WIN32 extern void ConsoleCreate(); @@ -226,8 +233,7 @@ extern char installDir[MSG_SIZ]; extern int tinyLayout, smallLayout; ChessProgramStats programStats; static int exiting = 0; /* [HGM] moved to top */ -static int setboardSpoiledMachineBlack = 0, errorExitFlag = 0; -extern int startedFromPositionFile; +static int setboardSpoiledMachineBlack = 0 /*, errorExitFlag = 0*/; int startedFromPositionFile = FALSE; Board filePosition; /* [HGM] loadPos */ char endingGame = 0; /* [HGM] crash: flag to prevent recursion of GameEnds() */ int whiteNPS, blackNPS; /* [HGM] nps: for easily making clocks aware of NPS */ @@ -288,6 +294,8 @@ static char * safeStrCpy( char * dst, const char * src, size_t count ) return dst; } +#if 0 +//[HGM] for future use? Conditioned out for now to suppress warning. static char * safeStrCat( char * dst, const char * src, size_t count ) { size_t dst_len; @@ -304,6 +312,7 @@ static char * safeStrCat( char * dst, const char * src, size_t count ) return dst; } +#endif /* Some compiler can't cast u64 to double * This function do the job for us: @@ -1941,7 +1950,7 @@ VariantSwitch(Board board, VariantClass newVariant) { int newHoldingsWidth, newWidth = 8, newHeight = 8, i, j; int oldCurrentMove = currentMove, oldForwardMostMove = forwardMostMove, oldBackwardMostMove = backwardMostMove; - Board tempBoard; int saveCastling[BOARD_SIZE], saveEP; +// Board tempBoard; int saveCastling[BOARD_SIZE], saveEP; startedFromPositionFile = FALSE; if(gameInfo.variant == newVariant) return; @@ -2357,10 +2366,10 @@ read_from_ics(isr, closure, data, count, error) (StrStr(star_match[0], gameInfo.white) == star_match[0] || StrStr(star_match[0], gameInfo.black) == star_match[0] )) { // kibitz of self or opponent suppressKibitz = TRUE; - if((StrStr(star_match[0], gameInfo.white) == star_match[0]) - && (gameMode == IcsPlayingWhite) || - (StrStr(star_match[0], gameInfo.black) == star_match[0]) - && (gameMode == IcsPlayingBlack) ) // opponent kibitz + if((StrStr(star_match[0], gameInfo.white) == star_match[0] + && (gameMode == IcsPlayingWhite)) || + (StrStr(star_match[0], gameInfo.black) == star_match[0] + && (gameMode == IcsPlayingBlack)) ) // opponent kibitz started = STARTED_CHATTER; // own kibitz we simply discard else { started = STARTED_COMMENT; // make sure it will be collected in parse[] @@ -2850,7 +2859,7 @@ read_from_ics(isr, closure, data, count, error) if(bookHit) { // [HGM] book: simulate book reply static char bookMove[MSG_SIZ]; // a bit generous? - programStats.depth = programStats.nodes = programStats.time = + programStats.nodes = programStats.depth = programStats.time = programStats.score = programStats.got_only_move = 0; sprintf(programStats.movelist, "%s (xbook)", bookHit); @@ -3880,7 +3889,7 @@ ParseBoard12(string) if(bookHit) { // [HGM] book: simulate book reply static char bookMove[MSG_SIZ]; // a bit generous? - programStats.depth = programStats.nodes = programStats.time = + programStats.nodes = programStats.depth = programStats.time = programStats.score = programStats.got_only_move = 0; sprintf(programStats.movelist, "%s (xbook)", bookHit); @@ -4100,7 +4109,7 @@ ProcessICSInitScript(f) void AlphaRank(char *move, int n) { - char *p = move, c; int x, y; +// char *p = move, c; int x, y; if (appData.debugMode) { fprintf(debugFP, "alphaRank(%s,%d)\n", move, n); @@ -4244,6 +4253,7 @@ ParseOneMove(move, moveNum, moveType, fromX, fromY, toX, toY, promoChar) } } +#if 0 /* [AS] FRC game initialization */ static int FindEmptySquare( Board board, int n ) { @@ -4260,7 +4270,6 @@ static int FindEmptySquare( Board board, int n ) return i; } -#if 0 static void ShuffleFRC( Board board ) { int i; @@ -4352,7 +4361,7 @@ static void SetupFRC( Board board, int pos_index ) int squaresLeft[4]; int piecesLeft[(int)BlackPawn]; -long long int seed, nrOfShuffles; +u64 seed, nrOfShuffles; void GetPositionNumber() { // sets global variable seed @@ -4373,9 +4382,9 @@ int put(Board board, int pieceType, int rank, int n, int shade) int i; for(i=BOARD_LEFT; i (int) WhitePawn; p--) { if(p != (int) WhiteBishop && p != (int) WhiteFerz && p != (int) WhiteAlfil) continue; @@ -4643,10 +4652,10 @@ InitPosition(redraw) nrCastlingRights = 6; castlingRights[0][0] = initialRights[0] = BOARD_RGHT-1; castlingRights[0][1] = initialRights[1] = BOARD_LEFT; - castlingRights[0][2] = initialRights[2] = BOARD_WIDTH-1>>1; + castlingRights[0][2] = initialRights[2] =(BOARD_WIDTH-1)>>1; castlingRights[0][3] = initialRights[3] = BOARD_RGHT-1; castlingRights[0][4] = initialRights[4] = BOARD_LEFT; - castlingRights[0][5] = initialRights[5] = BOARD_WIDTH-1>>1; + castlingRights[0][5] = initialRights[5] =(BOARD_WIDTH-1)>>1; break; case VariantFalcon: pieces = FalconArray; @@ -5440,7 +5449,7 @@ if(appData.debugMode) fprintf(debugFP, "moveType 2 = %d, promochar = %x\n", move if(bookHit) { // [HGM] book: simulate book reply static char bookMove[MSG_SIZ]; // a bit generous? - programStats.depth = programStats.nodes = programStats.time = + programStats.nodes = programStats.depth = programStats.time = programStats.score = programStats.got_only_move = 0; sprintf(programStats.movelist, "%s (xbook)", bookHit); @@ -5473,7 +5482,7 @@ if(appData.debugMode) fprintf(debugFP, "moveType 4 = %d, promochar = %x\n", move void SendProgramStatsToFrontend( ChessProgramState * cps, ChessProgramStats * cpstats ) { - char * hint = lastHint; +// char * hint = lastHint; FrontEndProgramStats stats; stats.which = cps == &first ? 0 : 1; @@ -5667,8 +5676,8 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h sprintf(buf1, _("Illegal move \"%s\" from %s machine"), machineMove, cps->which); DisplayError(buf1, 0); - sprintf(buf1, "Xboard: Forfeit due to invalid move: %s (%c%c%c%c) res=%d%c", - machineMove, fromX+AAA, fromY+ONE, toX+AAA, toY+ONE, 0); + sprintf(buf1, "Xboard: Forfeit due to invalid move: %s (%c%c%c%c) res=%d", + machineMove, fromX+AAA, fromY+ONE, toX+AAA, toY+ONE, moveType); if (gameMode == TwoMachinesPlay) { GameEnds(machineWhite ? BlackWins : WhiteWins, buf1, GE_XBOARD); @@ -5713,6 +5722,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h toX--; currentMoveString[2]--; break; + default: ; // nothing to do, but suppresses warning of pedantic compilers } } hintRequested = FALSE; @@ -5735,8 +5745,8 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h programStats.depth, programStats.score / 100., programStats.time / 100., - (double) programStats.nodes, - programStats.nodes / (10*abs(programStats.time) + 1.), + u64ToDouble(programStats.nodes), + u64ToDouble(programStats.nodes) / (10*abs(programStats.time) + 1.), programStats.movelist); SendToICS(buf); } @@ -5825,7 +5835,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h { /* [HGM] Some more adjudications for obstinate engines */ int NrWN=0, NrBN=0, NrWB=0, NrBB=0, NrWR=0, NrBR=0, NrWQ=0, NrBQ=0, NrW=0, bishopsColor = 0, - NrPieces=0, NrPawns=0, PawnAdvance=0, i, j, k; + NrPieces=0, NrPawns=0, PawnAdvance=0, i, j; static int moveCount = 6; /* First absolutely insufficient mating material. Count what is on board. */ @@ -5871,7 +5881,8 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h } } - if( NrPieces == 2 || gameInfo.variant != VariantXiangqi && + if( NrPieces == 2 || gameInfo.variant != VariantXiangqi && + gameInfo.variant != VariantShatranj && // [HGM] baring will remain possible (NrPieces == 3 && NrWN+NrBN+NrWB+NrBB == 1 || NrPieces == NrBB+NrWB+2 && bishopsColor != 3)) // [HGM] all Bishops (Ferz!) same color { /* KBK, KNK, KK of KBKB with like Bishops */ @@ -5994,6 +6005,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 ); @@ -6001,8 +6014,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; @@ -6111,7 +6135,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h strcat(bookMove, bookHit); message = bookMove; cps = cps->other; - programStats.depth = programStats.nodes = programStats.time = + programStats.nodes = programStats.depth = programStats.time = programStats.score = programStats.got_only_move = 0; sprintf(programStats.movelist, "%s (xbook)", bookHit); @@ -6645,8 +6669,8 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if(cps->nps >= 0) { /* [HGM] nps: use engine nodes or time to decrement clock */ int ticklen; - if(cps->nps == 0) ticklen = 10*time; // use engine reported time - else ticklen = (1000. * nodes) / cps->nps; // convert node count to time + if(cps->nps == 0) ticklen = 10*time; // use engine reported time + else ticklen = (1000. * u64ToDouble(nodes)) / cps->nps; // convert node count to time if(WhiteOnMove(forwardMostMove)) whiteTimeRemaining = timeRemaining[0][forwardMostMove] - ticklen; else blackTimeRemaining = timeRemaining[1][forwardMostMove] - ticklen; @@ -6805,7 +6829,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h else { buf1[0] = NULLCHAR; - if (sscanf(message, "%d%c %d %d %lu %[^\n]\n", + if (sscanf(message, "%d%c %d %d " u64Display " %[^\n]\n", &plylev, &plyext, &curscore, &time, &nodes, buf1) >= 5) { ChessProgramStats cpstats; @@ -7050,7 +7074,7 @@ ApplyMove(fromX, fromY, toX, toY, promoChar, board) /* [HGM] compute & store e.p. status and castling rights for new position */ /* if we are updating a board for which those exist (i.e. in boards[]) */ if((p = ((int)board - (int)boards[0])/((int)boards[1]-(int)boards[0])) < MAX_MOVES && p > 0) - { int i, j; + { int i; if(gameInfo.variant == VariantBerolina) berolina = EP_BEROLIN_A; oldEP = epStatus[p-1]; @@ -9501,7 +9525,7 @@ SaveGamePGN(f) { int i, offset, linelen, newblock; time_t tm; - char *movetext; +// char *movetext; char numtext[32]; int movelen, numlen, blank; char move_buffer[100]; /* [AS] Buffer for move+PV info */ @@ -9610,12 +9634,6 @@ SaveGamePGN(f) #else seconds = (pvInfoList[i].time + 5)/10; // [HGM] PVtime: use engine time #endif - if (appData.debugMode,0) { - fprintf(debugFP, "times = %d %d %d %d, seconds=%d\n", - timeRemaining[0][i+1], timeRemaining[0][i], - timeRemaining[1][i+1], timeRemaining[1][i], seconds - ); - } if( seconds <= 0) buf[0] = 0; else if( seconds < 30 ) sprintf(buf, " %3.1f%c", seconds/10., 0); else { @@ -10428,7 +10446,7 @@ MachineWhiteEvent() if(bookHit) { // [HGM] book: simulate book reply static char bookMove[MSG_SIZ]; // a bit generous? - programStats.depth = programStats.nodes = programStats.time = + programStats.nodes = programStats.depth = programStats.time = programStats.score = programStats.got_only_move = 0; sprintf(programStats.movelist, "%s (xbook)", bookHit); @@ -10503,7 +10521,7 @@ MachineBlackEvent() if(bookHit) { // [HGM] book: simulate book reply static char bookMove[MSG_SIZ]; // a bit generous? - programStats.depth = programStats.nodes = programStats.time = + programStats.nodes = programStats.depth = programStats.time = programStats.score = programStats.got_only_move = 0; sprintf(programStats.movelist, "%s (xbook)", bookHit); @@ -10649,7 +10667,7 @@ TwoMachinesEvent P((void)) if(bookHit) { // [HGM] book: simulate book reply static char bookMove[MSG_SIZ]; // a bit generous? - programStats.depth = programStats.nodes = programStats.time = + programStats.nodes = programStats.depth = programStats.time = programStats.score = programStats.got_only_move = 0; sprintf(programStats.movelist, "%s (xbook)", bookHit); @@ -12884,6 +12902,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) @@ -12901,7 +12924,7 @@ GetTimeMark(tm) #else /*!HAVE_GETTIMEOFDAY*/ #if HAVE_FTIME -#include +// include / moved to just above start of function struct timeb timeB; ftime(&timeB);