X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=f028af444d38b2a135e3ccb2ee67f56e0c9948da;hb=cde66749ec8a0b3c823bbc7aa3818b86821514ec;hp=6520238f8d03a979bb23a60d31ffc2885fe736c3;hpb=f81b07c4e3bcbc2260a348beb8c48df27faa1d81;p=xboard.git diff --git a/backend.c b/backend.c index 6520238..f028af4 100644 --- a/backend.c +++ b/backend.c @@ -1451,7 +1451,7 @@ MatchEvent(int mode) } matchMode = mode; matchGame = roundNr = 1; - first.matchWins = second.matchWins = 0; // [HGM] match: needed in later matches + first.matchWins = second.matchWins = 0; // [HGM] match: needed in later matches NextMatchGame(); } @@ -5276,6 +5276,7 @@ ParseOneMove(move, moveNum, moveType, fromX, fromY, toX, toY, promoChar) } Boolean pushed = FALSE; +char *lastParseAttempt; void ParsePV(char *pv, Boolean storeComments, Boolean atEnd) @@ -5293,6 +5294,7 @@ ParsePV(char *pv, Boolean storeComments, Boolean atEnd) do { while(*pv == ' ' || *pv == '\n' || *pv == '\t') pv++; // must still read away whitespace if(nr == 0 && !storeComments && *pv == '(') pv++; // first (ponder) move can be in parentheses + lastParseAttempt = pv; valid = ParseOneMove(pv, endPV, &moveType, &fromX, &fromY, &toX, &toY, &promoChar); if(appData.debugMode){ fprintf(debugFP,"parsePV: %d %c%c%c%c yy='%s'\nPV = '%s'\n", valid, fromX+AAA, fromY+ONE, toX+AAA, toY+ONE, yy_textstr, pv); @@ -5334,6 +5336,7 @@ fprintf(debugFP,"parsePV: %d %c%c%c%c yy='%s'\nPV = '%s'\n", valid, fromX+AAA, f fromY, fromX, toY, toX, promoChar, parseList[endPV - 1]); } while(valid); + if(atEnd == 2) return; // used hidden, for PV conversion currentMove = (atEnd || endPV == forwardMostMove) ? endPV : forwardMostMove + 1; if(currentMove == forwardMostMove) ClearPremoveHighlights(); else SetPremoveHighlights(moveList[currentMove-1][0]-AAA, moveList[currentMove-1][1]-ONE, @@ -5381,6 +5384,25 @@ LoadMultiPV(int x, int y, char *buf, int index, int *start, int *end) return TRUE; } +char * +PvToSAN(char *pv) +{ + static char buf[10*MSG_SIZ]; + int i, k=0, savedEnd=endPV; + *buf = NULLCHAR; + if(forwardMostMove < endPV) PushInner(forwardMostMove, endPV); + ParsePV(pv, FALSE, 2); // this appends PV to game, suppressing any display of it + for(i = forwardMostMove; i= BOARD_RGHT) return -1; + if(xSqr < BOARD_LEFT || xSqr >= BOARD_RGHT) return -1; case EditPosition: - if (xSqr == BOARD_LEFT-1 || xSqr == BOARD_RGHT) return -1; + if (xSqr == BOARD_LEFT-1 || xSqr == BOARD_RGHT) return -1; if (xSqr < 0 || ySqr < 0) return -1; if(appData.pieceMenu) { whichMenu = 0; break; } // edit-position menu pieceSweep = shiftKey ? BlackPawn : WhitePawn; // [HGM] sweep: prepare selecting piece by mouse sweep toX = xSqr; toY = ySqr; lastX = x, lastY = y; if(flipView) toX = BOARD_WIDTH - 1 - toX; else toY = BOARD_HEIGHT - 1 - toY; NextPiece(0); - return -2; + return -2; case IcsObserving: if(!appData.icsEngineAnalyze) return -1; case IcsPlayingWhite: @@ -7667,7 +7689,7 @@ HandleMachineMove(message, cps) int fromX, fromY, toX, toY; ChessMove moveType; char promoChar; - char *p; + char *p, *pv=buf1; int machineWhite; char *bookHit; @@ -8524,6 +8546,7 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. curscore = -curscore; } + if(appData.pvSAN[cps==&second]) pv = PvToSAN(buf1); tempStats.depth = plylev; tempStats.nodes = nodes; @@ -8545,15 +8568,15 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. } /* Buffer overflow protection */ - if (buf1[0] != NULLCHAR) { - if (strlen(buf1) >= sizeof(tempStats.movelist) + if (pv[0] != NULLCHAR) { + if (strlen(pv) >= sizeof(tempStats.movelist) && appData.debugMode) { fprintf(debugFP, "PV is too long; using the first %u bytes.\n", (unsigned) sizeof(tempStats.movelist) - 1); } - safeStrCpy( tempStats.movelist, buf1, sizeof(tempStats.movelist)/sizeof(tempStats.movelist[0]) ); + safeStrCpy( tempStats.movelist, pv, sizeof(tempStats.movelist)/sizeof(tempStats.movelist[0]) ); } else { sprintf(tempStats.movelist, " no PV\n"); } @@ -8590,14 +8613,14 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. if( buf1[0] != NULLCHAR ) { unsigned max_len = sizeof(thinkOutput) - strlen(thinkOutput) - 1; - if( strlen(buf1) > max_len ) { + if( strlen(pv) > max_len ) { if( appData.debugMode) { fprintf(debugFP,"PV is too long for thinkOutput, truncating.\n"); } - buf1[max_len+1] = '\0'; + pv[max_len+1] = '\0'; } - strcat( thinkOutput, buf1 ); + strcat( thinkOutput, pv); } if (currentMove == forwardMostMove || gameMode == AnalyzeMode @@ -9718,6 +9741,7 @@ void SwapEngines(int n) SWAP(timeOdds, h) SWAP(logo, p) SWAP(pgnName, p) + SWAP(pvSAN, h) } void @@ -15035,14 +15059,14 @@ AskQuestionEvent(title, question, replyPrefix, which) void TypeInEvent(char firstChar) { - if ((gameMode == BeginningOfGame && !appData.icsActive) || - gameMode == MachinePlaysWhite || gameMode == MachinePlaysBlack || - gameMode == AnalyzeMode || gameMode == EditGame || - gameMode == EditPosition || gameMode == IcsExamining || - gameMode == IcsPlayingWhite || gameMode == IcsPlayingBlack || - isdigit(firstChar) && // [HGM] movenum: allow typing in of move nr in 'passive' modes - ( gameMode == AnalyzeFile || gameMode == PlayFromGameFile || - gameMode == IcsObserving || gameMode == TwoMachinesPlay ) || + if ((gameMode == BeginningOfGame && !appData.icsActive) || + gameMode == MachinePlaysWhite || gameMode == MachinePlaysBlack || + gameMode == AnalyzeMode || gameMode == EditGame || + gameMode == EditPosition || gameMode == IcsExamining || + gameMode == IcsPlayingWhite || gameMode == IcsPlayingBlack || + isdigit(firstChar) && // [HGM] movenum: allow typing in of move nr in 'passive' modes + ( gameMode == AnalyzeFile || gameMode == PlayFromGameFile || + gameMode == IcsObserving || gameMode == TwoMachinesPlay ) || gameMode == Training) PopUpMoveDialog(firstChar); } @@ -15052,34 +15076,34 @@ TypeInDoneEvent(char *move) Board board; int n, fromX, fromY, toX, toY; char promoChar; - ChessMove moveType; - - // [HGM] FENedit - if(gameMode == EditPosition && ParseFEN(board, &n, move) ) { - EditPositionPasteFEN(move); - return; - } - // [HGM] movenum: allow move number to be typed in any mode - if(sscanf(move, "%d", &n) == 1 && n != 0 ) { - ToNrEvent(2*n-1); - return; - } - - if (gameMode != EditGame && currentMove != forwardMostMove && - gameMode != Training) { - DisplayMoveError(_("Displayed move is not current")); - } else { - int ok = ParseOneMove(move, gameMode == EditPosition ? blackPlaysFirst : currentMove, - &moveType, &fromX, &fromY, &toX, &toY, &promoChar); - if(!ok && move[0] >= 'a') { move[0] += 'A' - 'a'; ok = 2; } // [HGM] try also capitalized - if (ok==1 || ok && ParseOneMove(move, gameMode == EditPosition ? blackPlaysFirst : currentMove, - &moveType, &fromX, &fromY, &toX, &toY, &promoChar)) { - UserMoveEvent(fromX, fromY, toX, toY, promoChar); - } else { - DisplayMoveError(_("Could not parse move")); - } - } -} + ChessMove moveType; + + // [HGM] FENedit + if(gameMode == EditPosition && ParseFEN(board, &n, move) ) { + EditPositionPasteFEN(move); + return; + } + // [HGM] movenum: allow move number to be typed in any mode + if(sscanf(move, "%d", &n) == 1 && n != 0 ) { + ToNrEvent(2*n-1); + return; + } + + if (gameMode != EditGame && currentMove != forwardMostMove && + gameMode != Training) { + DisplayMoveError(_("Displayed move is not current")); + } else { + int ok = ParseOneMove(move, gameMode == EditPosition ? blackPlaysFirst : currentMove, + &moveType, &fromX, &fromY, &toX, &toY, &promoChar); + if(!ok && move[0] >= 'a') { move[0] += 'A' - 'a'; ok = 2; } // [HGM] try also capitalized + if (ok==1 || ok && ParseOneMove(move, gameMode == EditPosition ? blackPlaysFirst : currentMove, + &moveType, &fromX, &fromY, &toX, &toY, &promoChar)) { + UserMoveEvent(fromX, fromY, toX, toY, promoChar); + } else { + DisplayMoveError(_("Could not parse move")); + } + } +} void DisplayMove(moveNumber)