From: H.G.Muller Date: Thu, 25 Sep 2014 21:37:24 +0000 (+0200) Subject: Print PGN Piece tag listing engine-defined pieces X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=5bee433e9f42c5194734b2671dbbcfcf9068eab8;p=xboard.git Print PGN Piece tag listing engine-defined pieces A newly defined PGN tag is printed, which summarizes all non-standard pieces. Black copies of identically named white pieces are suppressed. In the future also non-standard naming should be reported here. --- diff --git a/backend.h b/backend.h index 583a98a..456a0e3 100644 --- a/backend.h +++ b/backend.h @@ -422,6 +422,8 @@ void MakeEngineOutputTitle P((void)); void LoadTheme P((void)); void CreateBookEvent P((void)); char *SupportedVariant P((char *list, VariantClass v, int w, int h, int s, int proto, char *engine)); +char *CollectPieceDescriptors P((void)); + /* A point in time */ typedef struct { diff --git a/moves.c b/moves.c index 32cabf7..bcaef30 100644 --- a/moves.c +++ b/moves.c @@ -74,6 +74,16 @@ int PosFlags(int index); extern signed char initialRights[BOARD_FILES]; /* [HGM] all rights enabled, set in InitPosition */ int quickFlag; char *pieceDesc[EmptySquare]; +char *defaultDesc[EmptySquare] = { + "fmWfceFifmnD", "N", "B", "R", "Q", + "F", "A", "BN", "RN", "W", "K", + "mRcpR", "N0", "BW", "RF", "gQ", + "", "", "QN", "", "N", "", + "", "", "", "", "", + "", "", "", "", "", "", + "", "", "", "", "", + "", "", "", "", "", "K" +}; int WhitePiece (ChessSquare piece) @@ -168,6 +178,45 @@ CompareBoards (Board board1, Board board2) return TRUE; } +char defaultName[] = "PNBRQ......................................K" // white + "pnbrq......................................k"; // black +char shogiName[] = "PNBRLS...G.++++++..........................K" // white + "pnbrls...g.++++++..........................k"; // black +char xqName[] = "PH.R.AE..K.C................................" // white + "ph.r.ae..k.c................................"; // black + +char * +CollectPieceDescriptors () +{ // make a line of piece descriptions for use in the PGN Piece tag: + // dump all engine defined pieces, and pieces with non-standard names, + // but suppress black pieces that are the same as their white counterpart + ChessSquare p; + static char buf[MSG_SIZ]; + char *m, c, d, *pieceName = defaultName; + int len; + *buf = NULLCHAR; + if(!pieceDefs) return ""; + if(gameInfo.variant == VariantChu) return ""; // for now don't do this for Chu Shogi + if(gameInfo.variant == VariantShogi) pieceName = shogiName; + if(gameInfo.variant == VariantXiangqi) pieceName = xqName; + for(p=WhitePawn; p= BlackPawn && pieceToChar[BLACK_TO_WHITE p] == toupper(c) + && (c != '+' || pieceToChar[DEMOTED BLACK_TO_WHITE p] == d)) { // black member of normal pair + char *wm = pieceDesc[BLACK_TO_WHITE p]; + if(!m && !wm || m && wm && !strcmp(wm, m)) continue; // moves as a white piece + } else // white or unpaired black + if((p < BlackPawn || CharToPiece(toupper(d)) != EmptySquare) && // white or lone black + !pieceDesc[p] /*&& pieceName[p] == c*/) continue; // orthodox piece known by its usual name +// TODO: listing pieces because of unusual name can only be done if we have accurate Betza of all defaults + if(!m) m = defaultDesc[p]; + len = strlen(buf); + snprintf(buf+len, MSG_SIZ-len, "%s%s%c:%s", len ? ";" : "", c == '+' ? "+" : "", d, m); + } + return buf; +} + // [HGM] gen: configurable move generation from Betza notation sent by engine. Boolean pieceDefs; diff --git a/pgntags.c b/pgntags.c index 74e4495..2caed09 100644 --- a/pgntags.c +++ b/pgntags.c @@ -144,6 +144,7 @@ ParsePGNTag (char *tag, GameInfo *gameInfo) void PrintPGNTags (FILE *fp, GameInfo *gameInfo) { + char *p; fprintf(fp, "[Event \"%s\"]\n", gameInfo->event ? gameInfo->event : "?"); fprintf(fp, "[Site \"%s\"]\n", gameInfo->site ? gameInfo->site : "?"); fprintf(fp, "[Date \"%s\"]\n", gameInfo->date ? gameInfo->date : "?"); @@ -159,6 +160,8 @@ PrintPGNTags (FILE *fp, GameInfo *gameInfo) fprintf(fp, "[TimeControl \"%s\"]\n", gameInfo->timeControl); if (gameInfo->variant != VariantNormal) fprintf(fp, "[Variant \"%s\"]\n", VariantName(gameInfo->variant)); + if (*(p = CollectPieceDescriptors())) + fprintf(fp, "[Pieces \"%s\"]\n", p); if (gameInfo->extraTags) fputs(gameInfo->extraTags, fp); }