static void ParseFile(const char *szFilePath) { int i, mv, mvMirror, nComp; PositionStruct pos, posMirror; PgnFileStruct pgn; if (pgn.Read(szFilePath)) { pos = posMirror = pgn.posStart; posMirror.Mirror(); for (i = 0; i < pgn.nMaxMove; i ++) { mv = pgn.wmvMoveTable[i + 1]; mvMirror = MOVE_MIRROR(mv); if (pos.zobr.dwLock1 < posMirror.zobr.dwLock1) { nComp = -1; } else if (pos.zobr.dwLock1 > posMirror.zobr.dwLock1) { nComp = 1; } else { if (pos.zobr.dwLock0 < posMirror.zobr.dwLock0) { nComp = -1; } else if (pos.zobr.dwLock0 > posMirror.zobr.dwLock0) { nComp = 1; } else { nComp = 0; } } if (nComp <= 0) { AddTemp(TempStruct(pos, mv, MoveValue(pos.sdPlayer, pgn.nResult))); } if (nComp >= 0) { AddTemp(TempStruct(posMirror, mvMirror, MoveValue(pos.sdPlayer, pgn.nResult))); } if (pos.ucpcSquares[DST(mv)] == 0) { pos.MakeMove(mv); } else { pos.MakeMove(mv); pos.SetIrrev(); } if (posMirror.ucpcSquares[DST(mvMirror)] == 0) { posMirror.MakeMove(mvMirror); } else { posMirror.MakeMove(mvMirror); posMirror.SetIrrev(); } } } }
static void AddEcco(const char *szPgnFile, const EccoApiStruct &EccoApi) { int i, nStatus; uint32_t dwEccoIndex, dwFileMove[20]; PgnFileStruct pgn; PositionStruct pos; if (pgn.Read(szPgnFile, NO_ADVERT)) { pos.FromFen(cszStartFen); for (i = 1; i <= MIN(pgn.nMaxMove, 20); i ++) { dwFileMove[i - 1] = Move2File(pgn.wmvMoveTable[i], pos); TryMove(pos, nStatus, pgn.wmvMoveTable[i]); } if (pgn.nMaxMove < 20) { dwFileMove[pgn.nMaxMove] = 0; } dwEccoIndex = EccoApi.EccoIndex((const char *) dwFileMove); strcpy(pgn.szEcco, (const char *) &dwEccoIndex); strcpy(pgn.szOpen, EccoApi.EccoOpening(dwEccoIndex)); strcpy(pgn.szVar, EccoApi.EccoVariation(dwEccoIndex)); pgn.Write(szPgnFile); } }
int Pgn2Xqf(const char *szPgnFile, const char *szXqfFile) { int i, nCommentLen; char szRed[MAX_STR_LEN * 2], szBlack[MAX_STR_LEN * 2]; FILE *fp; PgnFileStruct pgn; XqfHeaderStruct xqfhd; XqfMoveStruct xqfmv; if (!pgn.Read(szPgnFile)) { return PGN2XQF_ERROR_OPEN; } fp = fopen(szXqfFile, "wb"); if (fp == NULL) { return PGN2XQF_ERROR_CREATE; } memset(xqfhd.szTag, 0, sizeof(XqfHeaderStruct)); xqfhd.szTag[0] = 'X'; xqfhd.szTag[1] = 'Q'; xqfhd.szTag[2] = 10; for (i = 0; i < 32; i ++) { xqfhd.szPiecePos[i] = ccSquare2Xqf[pgn.posStart.ucsqPieces[cpcXqf2Piece[i]]]; } xqfhd.szResult[3] = cnResultTrans[pgn.nResult]; xqfhd.szSetUp[0] = 2; SetXqfString(xqfhd.szEvent, pgn.szEvent, sizeof(xqfhd.szEvent)); SetXqfString(xqfhd.szDate, pgn.szDate, sizeof(xqfhd.szDate)); SetXqfString(xqfhd.szSite, pgn.szSite, sizeof(xqfhd.szSite)); if (pgn.szRedTeam[0] == '\0') { SetXqfString(xqfhd.szRed, pgn.szRed, sizeof(xqfhd.szRed)); } else { sprintf(szRed, "%s %s", pgn.szRedTeam, pgn.szRed); SetXqfString(xqfhd.szRed, szRed, sizeof(xqfhd.szRed)); } if (pgn.szBlackTeam[0] == '\0') { SetXqfString(xqfhd.szBlack, pgn.szBlack, sizeof(xqfhd.szBlack)); } else { sprintf(szBlack, "%s %s", pgn.szBlackTeam, pgn.szBlack); SetXqfString(xqfhd.szBlack, szBlack, sizeof(xqfhd.szBlack)); } fwrite(&xqfhd, sizeof(xqfhd), 1, fp); memset(&xqfhd, 0, sizeof(xqfhd)); fwrite(&xqfhd, sizeof(xqfhd), 1, fp); for (i = 0; i <= pgn.nMaxMove; i ++) { xqfmv.ucTag = (i == pgn.nMaxMove ? 0 : 240); if (i == 0) { xqfmv.ucSrc = 24; xqfmv.ucDst = 32; xqfmv.ucReserved = 255; } else { xqfmv.ucSrc = 24 + ccSquare2Xqf[SRC(pgn.wmvMoveTable[i])]; xqfmv.ucDst = 32 + ccSquare2Xqf[DST(pgn.wmvMoveTable[i])]; xqfmv.ucReserved = 0; } fwrite(&xqfmv, sizeof(XqfMoveStruct), 1, fp); nCommentLen = (pgn.szCommentTable[i] == NULL ? 0 : strlen(pgn.szCommentTable[i])); fwrite(&nCommentLen, sizeof(int), 1, fp); if (pgn.szCommentTable[i] != NULL) { fwrite(pgn.szCommentTable[i], nCommentLen, 1, fp); } } fclose(fp); return 0; }