From 5ec02fef40c35757bf05a91600ada714f0fb799b Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sat, 1 Jun 2013 19:53:34 +0200 Subject: [PATCH] Make writing of move counts in PositionToFEN optional This way it can be used to write the position part of an EPD, which should not contain the move-count fields. --- backend.c | 20 +++++++++++--------- backend.h | 2 +- menus.c | 2 +- winboard/wclipbrd.c | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/backend.c b/backend.c index 8554b56..f6bbefb 100644 --- a/backend.c +++ b/backend.c @@ -5164,7 +5164,7 @@ UploadGameEvent () SendToICS(ics_prefix); SendToICS(buf); if(startedFromSetupPosition || backwardMostMove != 0) { - fen = PositionToFEN(backwardMostMove, NULL); + fen = PositionToFEN(backwardMostMove, NULL, 1); if(ics_type == ICS_ICC) { // on ICC we can simply send a complete FEN to set everything snprintf(buf, MSG_SIZ,"loadfen %s\n", fen); SendToICS(buf); @@ -6155,7 +6155,7 @@ SendBoard (ChessProgramState *cps, int moveNum) char message[MSG_SIZ]; if (cps->useSetboard) { - char* fen = PositionToFEN(moveNum, cps->fenOverride); + char* fen = PositionToFEN(moveNum, cps->fenOverride, 1); snprintf(message, MSG_SIZ,"setboard %s\n", fen); SendToProgram(message, cps); free(fen); @@ -12836,7 +12836,7 @@ SaveGamePGN (FILE *f) if(appData.numberTag && matchMode) fprintf(f, "[Number \"%d\"]\n", nextGame+1); // [HGM] number tag if (backwardMostMove > 0 || startedFromSetupPosition) { - char *fen = PositionToFEN(backwardMostMove, NULL); + char *fen = PositionToFEN(backwardMostMove, NULL, 1); fprintf(f, "[FEN \"%s\"]\n[SetUp \"1\"]\n", fen); fprintf(f, "\n{--------------\n"); PrintPosition(f, backwardMostMove); @@ -13105,7 +13105,7 @@ SavePosition (FILE *f, int dummy, char *dummy2) PrintPosition(f, currentMove); fprintf(f, "--------------]\n"); } else { - fen = PositionToFEN(currentMove, NULL); + fen = PositionToFEN(currentMove, NULL, 1); fprintf(f, "%s\n", fen); free(fen); } @@ -17020,7 +17020,7 @@ PGNDate () char * -PositionToFEN (int move, char *overrideCastling) +PositionToFEN (int move, char *overrideCastling, int moveCounts) { int i, j, fromX, fromY, toX, toY; int whiteToPlay; @@ -17183,9 +17183,10 @@ PositionToFEN (int move, char *overrideCastling) } } - /* [HGM] find reversible plies */ + if(moveCounts) { int i = 0, j=move; + /* [HGM] find reversible plies */ if (appData.debugMode) { int k; fprintf(debugFP, "write FEN 50-move: %d %d %d\n", initialRulePlies, forwardMostMove, backwardMostMove); for(k=backwardMostMove; k<=forwardMostMove; k++) @@ -17197,9 +17198,10 @@ PositionToFEN (int move, char *overrideCastling) if( j == backwardMostMove ) i += initialRulePlies; sprintf(p, "%d ", i); p += i>=100 ? 4 : i >= 10 ? 3 : 2; - } - /* Fullmove number */ - sprintf(p, "%d", (move / 2) + 1); + + /* Fullmove number */ + sprintf(p, "%d", (move / 2) + 1); + } else *--p = NULLCHAR; return StrSave(buf); } diff --git a/backend.h b/backend.h index 1092957..201d5b4 100644 --- a/backend.h +++ b/backend.h @@ -119,7 +119,7 @@ extern Boolean mcMode; void MarkMenuItem P((char *menuRef, int state)); char *CmailMsg P((void)); /* Tord: Added the useFEN960 parameter in PositionToFEN() below */ -char *PositionToFEN P((int move, char* useFEN960)); +char *PositionToFEN P((int move, char* useFEN960, int moveCounts)); void AlphaRank P((char *s, int n)); /* [HGM] Shogi move preprocessor */ void EditPositionPasteFEN P((char *fen)); void TimeDelay P((long ms)); diff --git a/menus.c b/menus.c index f131a68..ee66139 100644 --- a/menus.c +++ b/menus.c @@ -215,7 +215,7 @@ CopyPositionProc () static char *selected_fen_position=NULL; if(gameMode == EditPosition) EditPositionDone(TRUE); if (selected_fen_position) free(selected_fen_position); - selected_fen_position = (char *)PositionToFEN(currentMove, NULL); + selected_fen_position = (char *)PositionToFEN(currentMove, NULL, 1); if (!selected_fen_position) return; CopySomething(selected_fen_position); } diff --git a/winboard/wclipbrd.c b/winboard/wclipbrd.c index 72acf05..d1c5538 100644 --- a/winboard/wclipbrd.c +++ b/winboard/wclipbrd.c @@ -54,7 +54,7 @@ CopyFENToClipboard() char *fen = NULL; if(gameMode == EditPosition) EditPositionDone(TRUE); // [HGM] mak sure castling rights are set consistently - fen = PositionToFEN(currentMove, NULL); + fen = PositionToFEN(currentMove, NULL, 1); if (!fen) { DisplayError(_("Unable to convert position to FEN."), 0); return; -- 1.7.0.4