From aa0eb6d507b381ea971682083890a5a252ed23bb Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 16 Dec 2023 15:34:54 +0100 Subject: Reformatted WriteMoves() --- FICS/gamedb.c | 98 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 53 insertions(+), 45 deletions(-) (limited to 'FICS') diff --git a/FICS/gamedb.c b/FICS/gamedb.c index 9799b7b..a6a5f2c 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -653,54 +653,62 @@ PUBLIC int PieceToChar(int piece) } /* One line has everything on it */ -PRIVATE int WriteMoves(FILE * fp, move_t *m) +PRIVATE int +WriteMoves(FILE *fp, move_t *m) { - unsigned long MoveInfo = (m->color == BLACK); - int piece, castle; - int useFile = 0, useRank = 0, check = 0; - int i; + int i; + int piece, castle; + int useFile = 0, useRank = 0, check = 0; + unsigned long MoveInfo = (m->color == BLACK); - castle = (m->moveString[0] == 'o'); - if (castle) - piece = KING; - else - piece = piecetype(CharToPiece(m->moveString[0])); - - MoveInfo = (MoveInfo <<= 3) | piece; - MoveInfo = (MoveInfo <<= 3) | m->fromFile; - MoveInfo = (MoveInfo <<= 3) | m->fromRank; - MoveInfo = (MoveInfo <<= 3) | m->toFile; - MoveInfo = (MoveInfo <<= 3) | m->toRank; - MoveInfo = (MoveInfo <<= 3) | (m->pieceCaptured & 7); - MoveInfo = (MoveInfo <<= 3) | (m->piecePromotionTo & 7); - MoveInfo = (MoveInfo <<= 1) | (m->enPassant != 0); - - /* Are we using from-file or from-rank in algString? */ - i = strlen(m->algString) - 1; - if (m->algString[i] == '+') { - check = 1; - i--; - } - if (piece != PAWN && !castle) { - i -= 2; - if (i < 0) - return -1; - if (m->algString[i] == 'x') - i--; - if (i < 0) - return -1; - if (isdigit(m->algString[i])) { - useRank = 2; - i--; - } - if (i < 0) - return -1; - useFile = (islower(m->algString[i]) ? 4 : 0); - } - MoveInfo = (MoveInfo << 3) | useFile | useRank | check; - fprintf(fp, "%lx %x %x\n", MoveInfo, m->tookTime, m->atTime); + castle = (m->moveString[0] == 'o'); - return 0; + if (castle) + piece = KING; + else + piece = piecetype(CharToPiece(m->moveString[0])); + + MoveInfo = (MoveInfo <<= 3) | piece; + MoveInfo = (MoveInfo <<= 3) | m->fromFile; + MoveInfo = (MoveInfo <<= 3) | m->fromRank; + MoveInfo = (MoveInfo <<= 3) | m->toFile; + MoveInfo = (MoveInfo <<= 3) | m->toRank; + MoveInfo = (MoveInfo <<= 3) | (m->pieceCaptured & 7); + MoveInfo = (MoveInfo <<= 3) | (m->piecePromotionTo & 7); + MoveInfo = (MoveInfo <<= 1) | (m->enPassant != 0); + + /* Are we using from-file or from-rank in 'algString'? */ + + i = strlen(m->algString) - 1; + + if (m->algString[i] == '+') { + check = 1; + i--; + } + + if (piece != PAWN && !castle) { + i -= 2; + + if (i < 0) + return -1; + if (m->algString[i] == 'x') + i--; + if (i < 0) + return -1; + if (isdigit(m->algString[i])) { + useRank = 2; + i--; + } + if (i < 0) + return -1; + + useFile = (islower(m->algString[i]) ? 4 : 0); + } + + MoveInfo = ((MoveInfo << 3) | useFile | useRank | check); + + fprintf(fp, "%lx %x %x\n", MoveInfo, m->tookTime, m->atTime); + return 0; } PRIVATE int ReadMove(FILE * fp, move_t *m) -- cgit v1.2.3