X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=3205cdea754e33645f66b3154418d4ace5eb8953;hb=9384069316e400042076bd749ba0c6e0b07427fa;hp=a49464adc3d00b54e70070af188bbd26cd8db1fd;hpb=f8ab6dcab6427bb25a1bd4b9bde024e34c6f57bf;p=xboard.git diff --git a/backend.c b/backend.c index a49464a..3205cde 100644 --- a/backend.c +++ b/backend.c @@ -157,7 +157,7 @@ int LoadGameFromFile P((char *filename, int n, char *title, int useList)); int LoadPositionFromFile P((char *filename, int n, char *title)); int SavePositionToFile P((char *filename)); void ApplyMove P((int fromX, int fromY, int toX, int toY, int promoChar, - Board board)); + Board board, char *castle, char *ep)); void MakeMove P((int fromX, int fromY, int toX, int toY, int promoChar)); void ShowMove P((int fromX, int fromY, int toX, int toY)); int FinishMove P((ChessMove moveType, int fromX, int fromY, int toX, int toY, @@ -669,7 +669,7 @@ InitBackEnd1() if (!ParseTimeControl(appData.timeControl, appData.timeIncrement, appData.movesPerSession)) { char buf[MSG_SIZ]; - sprintf(buf, _("bad timeControl option %s"), appData.timeControl); + snprintf(buf, sizeof(buf), _("bad timeControl option %s"), appData.timeControl); DisplayFatalError(buf, 0, 2); } @@ -684,7 +684,7 @@ InitBackEnd1() searchTime = min * 60 + sec; } else { char buf[MSG_SIZ]; - sprintf(buf, _("bad searchTime option %s"), appData.searchTime); + snprintf(buf, sizeof(buf), _("bad searchTime option %s"), appData.searchTime); DisplayFatalError(buf, 0, 2); } } @@ -831,7 +831,7 @@ InitBackEnd1() q = first.program; while (*q != ' ' && *q != NULLCHAR) q++; p = q; - while (p > first.program && *(p-1) != '/' && *(p-1) != '\\') p--; /* [HGM] bckslash added */ + while (p > first.program && *(p-1) != '/' && *(p-1) != '\\') p--; /* [HGM] backslash added */ programVersion = (char*) malloc(8 + strlen(PRODUCT) + strlen(VERSION) + strlen(PATCHLEVEL) + (q - p)); sprintf(programVersion, "%s %s.%s + ", PRODUCT, VERSION, PATCHLEVEL); @@ -1124,7 +1124,7 @@ InitBackEnd3 P((void)) sprintf(buf, _("Could not open comm port %s"), appData.icsCommPort); } else { - sprintf(buf, _("Could not connect to host %s, port %s"), + snprintf(buf, sizeof(buf), _("Could not connect to host %s, port %s"), appData.icsHost, appData.icsPort); } DisplayFatalError(buf, err, 1); @@ -1319,18 +1319,18 @@ establish() } else if (*appData.gateway != NULLCHAR) { if (*appData.remoteShell == NULLCHAR) { /* Use the rcmd protocol to run telnet program on a gateway host */ - sprintf(buf, "%s %s %s", + snprintf(buf, sizeof(buf), "%s %s %s", appData.telnetProgram, appData.icsHost, appData.icsPort); return OpenRcmd(appData.gateway, appData.remoteUser, buf, &icsPR); } else { /* Use the rsh program to run telnet program on a gateway host */ if (*appData.remoteUser == NULLCHAR) { - sprintf(buf, "%s %s %s %s %s", appData.remoteShell, + snprintf(buf, sizeof(buf), "%s %s %s %s %s", appData.remoteShell, appData.gateway, appData.telnetProgram, appData.icsHost, appData.icsPort); } else { - sprintf(buf, "%s %s -l %s %s %s %s", + snprintf(buf, sizeof(buf), "%s %s -l %s %s %s %s", appData.remoteShell, appData.gateway, appData.remoteUser, appData.telnetProgram, appData.icsHost, appData.icsPort); @@ -2345,7 +2345,7 @@ read_from_ics(isr, closure, data, count, error) if (loggedOn && !have_set_title && ics_handle[0] != NULLCHAR) { char buf[MSG_SIZ]; - sprintf(buf, "%s@%s", ics_handle, appData.icsHost); + snprintf(buf, sizeof(buf), "%s@%s", ics_handle, appData.icsHost); DisplayIcsInteractionTitle(buf); have_set_title = TRUE; } @@ -3353,7 +3353,7 @@ ParseBoard12(string) &ticking); if (n < 21) { - sprintf(str, _("Failed to parse board string:\n\"%s\""), string); + snprintf(str, sizeof(str), _("Failed to parse board string:\n\"%s\""), string); DisplayError(str, 0); return; } @@ -3724,7 +3724,7 @@ ParseBoard12(string) else strcpy(buf, str); // might be castling if((prom = strstr(move_str, "=")) && !strstr(buf, "=")) strcat(buf, prom); // long move lacks promo specification! - if(!appData.testLegality) { + if(!appData.testLegality && move_str[1] != '@') { // drops never ambiguous (parser chokes on long form!) if(appData.debugMode) fprintf(debugFP, "replaced ICS move '%s' by '%s'\n", move_str, buf); strcpy(move_str, buf); @@ -5217,9 +5217,9 @@ if(appData.debugMode) fprintf(debugFP, "moveType 1 = %d, promochar = %x\n", move * If they don't match, display an error message. */ int saveAnimate; - Board testBoard; + Board testBoard; char testRights[BOARD_SIZE]; char testStatus; CopyBoard(testBoard, boards[currentMove]); - ApplyMove(fromX, fromY, toX, toY, promoChar, testBoard); + ApplyMove(fromX, fromY, toX, toY, promoChar, testBoard, testRights, &testStatus); if (CompareBoards(testBoard, boards[currentMove+1])) { ForwardInner(currentMove+1); @@ -5263,19 +5263,6 @@ if(appData.debugMode) fprintf(debugFP, "moveType 1 = %d, promochar = %x\n", move MakeMove(fromX, fromY, toX, toY, promoChar); /*updates forwardMostMove*/ - if((gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) - && promoChar != NULLCHAR && gameInfo.holdingsSize) { - // [HGM] superchess: take promotion piece out of holdings - int k = PieceToNumber(CharToPiece(ToUpper(promoChar))); - if(WhiteOnMove(forwardMostMove-1)) { - if(!--boards[forwardMostMove][k][BOARD_WIDTH-2]) - boards[forwardMostMove][k][BOARD_WIDTH-1] = EmptySquare; - } else { - if(!--boards[forwardMostMove][BOARD_HEIGHT-1-k][1]) - boards[forwardMostMove][BOARD_HEIGHT-1-k][0] = EmptySquare; - } - } - if (gameMode == BeginningOfGame) { if (appData.noChessProgram) { gameMode = EditGame; @@ -5807,8 +5794,20 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h // don't wait for engine to announce game end if we can judge ourselves switch (MateTest(boards[forwardMostMove], PosFlags(forwardMostMove), epFile, castlingRights[forwardMostMove]) ) { - case MT_NONE: case MT_CHECK: + if(gameInfo.variant == Variant3Check) { // [HGM] 3check: when in check, test if 3rd time + int i, checkCnt = 0; // (should really be done by making nr of checks part of game state) + for(i=forwardMostMove-2; i>=backwardMostMove; i-=2) { + if(MateTest(boards[i], PosFlags(i), epStatus[i], castlingRights[i]) == MT_CHECK) + checkCnt++; + if(checkCnt >= 2) { + reason = "Xboard adjudication: 3rd check"; + epStatus[forwardMostMove] = EP_CHECKMATE; + break; + } + } + } + case MT_NONE: default: break; case MT_STALEMATE: @@ -6155,7 +6154,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if (!strncmp(message, "tellopponent ", 13)) { if (appData.icsActive) { if (loggedOn) { - sprintf(buf1, "%ssay %s\n", ics_prefix, message + 13); + snprintf(buf1, sizeof(buf1), "%ssay %s\n", ics_prefix, message + 13); SendToICS(buf1); } } else { @@ -6166,7 +6165,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if (!strncmp(message, "tellothers ", 11)) { if (appData.icsActive) { if (loggedOn) { - sprintf(buf1, "%swhisper %s\n", ics_prefix, message + 11); + snprintf(buf1, sizeof(buf1), "%swhisper %s\n", ics_prefix, message + 11); SendToICS(buf1); } } @@ -6175,7 +6174,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if (!strncmp(message, "tellall ", 8)) { if (appData.icsActive) { if (loggedOn) { - sprintf(buf1, "%skibitz %s\n", ics_prefix, message + 8); + snprintf(buf1, sizeof(buf1), "%skibitz %s\n", ics_prefix, message + 8); SendToICS(buf1); } } else { @@ -6345,7 +6344,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h || (StrStr(message, "Permission denied") != NULL)) { cps->maybeThinking = FALSE; - sprintf(buf1, _("Failed to start %s chess program %s on %s: %s\n"), + snprintf(buf1, sizeof(buf1), _("Failed to start %s chess program %s on %s: %s\n"), cps->which, cps->program, cps->host, message); RemoveInputSource(cps->isr); DisplayFatalError(buf1, 0, 1); @@ -6363,11 +6362,11 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h (void) CoordsToAlgebraic(boards[forwardMostMove], PosFlags(forwardMostMove), EP_UNKNOWN, fromY, fromX, toY, toX, promoChar, buf1); - sprintf(buf2, _("Hint: %s"), buf1); + snprintf(buf2, sizeof(buf2), _("Hint: %s"), buf1); DisplayInformation(buf2); } else { /* Hint move could not be parsed!? */ - sprintf(buf2, + snprintf(buf2, sizeof(buf2), _("Illegal hint move \"%s\"\nfrom %s chess program"), buf1, cps->which); DisplayError(buf2, 0); @@ -6994,11 +6993,13 @@ ParseGameHistory(game) EP_UNKNOWN, fromY, fromX, toY, toX, promoChar, parseList[boardIndex]); CopyBoard(boards[boardIndex + 1], boards[boardIndex]); + {int i; for(i=0; i 0) + /* we can always do that 'in place', now pointers to these rights are passed to ApplyMove */ { int i; if(gameInfo.variant == VariantBerolina) berolina = EP_BEROLIN_A; - oldEP = epStatus[p-1]; - epStatus[p] = EP_NONE; + oldEP = *ep; + *ep = EP_NONE; if( board[toY][toX] != EmptySquare ) - epStatus[p] = EP_CAPTURE; + *ep = EP_CAPTURE; if( board[fromY][fromX] == WhitePawn ) { if(fromY != toY) // [HGM] Xiangqi sideway Pawn moves should not count as 50-move breakers - epStatus[p] = EP_PAWN_MOVE; + *ep = EP_PAWN_MOVE; if( toY-fromY==2) { if(toX>BOARD_LEFT && board[toY][toX-1] == BlackPawn && gameInfo.variant != VariantBerolina || toX < fromX) - epStatus[p] = toX | berolina; + *ep = toX | berolina; if(toX fromX) - epStatus[p] = toX; + *ep = toX; } } else if( board[fromY][fromX] == BlackPawn ) { if(fromY != toY) // [HGM] Xiangqi sideway Pawn moves should not count as 50-move breakers - epStatus[p] = EP_PAWN_MOVE; + *ep = EP_PAWN_MOVE; if( toY-fromY== -2) { if(toX>BOARD_LEFT && board[toY][toX-1] == WhitePawn && gameInfo.variant != VariantBerolina || toX < fromX) - epStatus[p] = toX | berolina; + *ep = toX | berolina; if(toX fromX) - epStatus[p] = toX; + *ep = toX; } } for(i=0; isendICS) { - sprintf(buf, "ics %s\n", appData.icsActive ? appData.icsHost : "-"); + snprintf(buf, sizeof(buf), "ics %s\n", appData.icsActive ? appData.icsHost : "-"); SendToProgram(buf, cps); } cps->maybeThinking = FALSE; @@ -7601,10 +7617,10 @@ StartChessProgram(cps) err = OpenRcmd(cps->host, appData.remoteUser, cps->program, &cps->pr); } else { if (*appData.remoteUser == NULLCHAR) { - sprintf(buf, "%s %s %s", appData.remoteShell, cps->host, + snprintf(buf, sizeof(buf), "%s %s %s", appData.remoteShell, cps->host, cps->program); } else { - sprintf(buf, "%s %s -l %s %s", appData.remoteShell, + snprintf(buf, sizeof(buf), "%s %s -l %s %s", appData.remoteShell, cps->host, appData.remoteUser, cps->program); } err = StartChildProcess(buf, "", &cps->pr); @@ -8525,7 +8541,7 @@ LoadGameFromFile(filename, n, title, useList) } else { f = fopen(filename, "rb"); if (f == NULL) { - sprintf(buf, _("Can't open \"%s\""), filename); + snprintf(buf, sizeof(buf), _("Can't open \"%s\""), filename); DisplayError(buf, errno); return FALSE; } @@ -8752,7 +8768,7 @@ LoadGame(f, gameNumber, title, useList) yynewfile(f); if (lg && lg->gameInfo.white && lg->gameInfo.black) { - sprintf(buf, "%s vs. %s", lg->gameInfo.white, + snprintf(buf, sizeof(buf), "%s vs. %s", lg->gameInfo.white, lg->gameInfo.black); DisplayTitle(buf); } else if (*title != NULLCHAR) { @@ -9179,7 +9195,7 @@ LoadPositionFromFile(filename, n, title) } else { f = fopen(filename, "rb"); if (f == NULL) { - sprintf(buf, _("Can't open \"%s\""), filename); + snprintf(buf, sizeof(buf), _("Can't open \"%s\""), filename); DisplayError(buf, errno); return FALSE; } else { @@ -9393,7 +9409,7 @@ SaveGameToFile(filename, append) } else { f = fopen(filename, append ? "a" : "w"); if (f == NULL) { - sprintf(buf, _("Can't open \"%s\""), filename); + snprintf(buf, sizeof(buf), _("Can't open \"%s\""), filename); DisplayError(buf, errno); return FALSE; } else { @@ -9767,7 +9783,7 @@ SavePositionToFile(filename) } else { f = fopen(filename, "a"); if (f == NULL) { - sprintf(buf, _("Can't open \"%s\""), filename); + snprintf(buf, sizeof(buf), _("Can't open \"%s\""), filename); DisplayError(buf, errno); return FALSE; } else { @@ -12755,16 +12771,16 @@ DisplayComment(moveNumber, text) WhiteOnMove(moveNumber) ? " " : ".. ", parseList[moveNumber]); } + // [HGM] PV info: display PV info together with (or as) comment + if(moveNumber >= 0 && (depth = pvInfoList[moveNumber].depth) > 0) { + if(text == NULL) text = ""; + score = pvInfoList[moveNumber].score; + sprintf(buf, "%s%.2f/%d %d\n%s", score>0 ? "+" : "", score/100., + depth, (pvInfoList[moveNumber].time+50)/100, text); + text = buf; + } } else title[0] = 0; - // [HGM] PV info: display PV info together with (or as) comment - if(moveNumber >= 0 && (depth = pvInfoList[moveNumber].depth) > 0) { - if(text == NULL) text = ""; - score = pvInfoList[moveNumber].score; - sprintf(buf, "%s%.2f/%d %d\n%s", score>0 ? "+" : "", score/100., - depth, (pvInfoList[moveNumber].time+50)/100, text); - CommentPopUp(title, buf); - } else if (text != NULL) CommentPopUp(title, text); }