diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-01-04 22:21:56 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-01-04 22:21:56 +0100 |
commit | dbfca4600fef677163158dc41dd989da557c60c9 (patch) | |
tree | a5bd07db8d37c968de53e37f296106479da67628 /FICS/algcheck.c | |
parent | 27beba0b8cf7800d78e74e2069bc5842efa7ef3f (diff) |
Reformatted alg_unparse()
Diffstat (limited to 'FICS/algcheck.c')
-rw-r--r-- | FICS/algcheck.c | 323 |
1 files changed, 170 insertions, 153 deletions
diff --git a/FICS/algcheck.c b/FICS/algcheck.c index bbed69b..5ae3bee 100644 --- a/FICS/algcheck.c +++ b/FICS/algcheck.c @@ -299,167 +299,184 @@ PUBLIC int alg_parse_move(char *mstr, game_state_t * gs, move_t * mt) return MOVE_OK; } -/* A assumes the move has yet to be made on the board */ -/* this is the old stupid function, we are testing one from soso... -PUBLIC char *alg_unparse( game_state_t *gs, move_t *mt ) +/* + * Soso: rewrote alg_unparse function. Algebraic deparser - sets the + * 'mStr' variable with move description in short notation. Used in + * last move report and in 'moves' command. + */ +PUBLIC char * +alg_unparse(game_state_t *gs, move_t *mt) { - static char mStr[20]; - - if ((piecetype(gs->board[mt->fromFile][mt->fromRank]) == KING) && - ((mt->fromFile == 4) && (mt->toFile == 6)) ) - return "o-o"; - if ((piecetype(gs->board[mt->fromFile][mt->fromRank]) == KING) && - ((mt->fromFile == 4) && (mt->toFile == 2)) ) - return "o-o-o"; - - sprintf( mStr, "%c%d%c%d", mt->fromFile+'a', mt->fromRank+1, - mt->toFile+'a', mt->toRank+1 ); - return mStr; -} -*/ + char tmp[20] = { '\0' }; + game_state_t fakeMove; + int ambig, r_ambig, f_ambig; + int piece, f, r; + static char mStr[20] = { '\0' }; + if (mt->fromFile == ALG_DROP) { + piece = mt->fromRank; + } else { + piece = piecetype(gs->board[mt->fromFile][mt->fromRank]); + } -/* A assumes the move has yet to be made on the board */ + if (piece == KING && (mt->fromFile == 4 && mt->toFile == 6)) { + strcpy(mStr, "O-O"); + goto check; + } + if (piece == KING && (mt->fromFile == 4 && mt->toFile == 2)) { + strcpy(mStr, "O-O-O"); + goto check; + } -/* Soso: rewrote alg_unparse function. - * Algebraic deparser - sets the mStr variable with move description - * in short notation. Used in last move report and in 'moves' command. - */ + strcpy(mStr, ""); -PUBLIC char *alg_unparse(game_state_t * gs, move_t * mt) -{ - static char mStr[20]; - char tmp[20]; - int piece, f, r; - int ambig, r_ambig, f_ambig; - game_state_t fakeMove; - - if (mt->fromFile == ALG_DROP) { - piece = mt->fromRank; - } else { - piece = piecetype(gs->board[mt->fromFile][mt->fromRank]); - } + switch (piece) { + case PAWN: + if (mt->fromFile == ALG_DROP) { + strcpy(mStr,"P"); + } else if (mt->fromFile != mt->toFile) { + sprintf(tmp, "%c", (mt->fromFile + 'a')); + strcpy(mStr, tmp); + } + break; + case KNIGHT: + strcpy(mStr, "N"); + break; + case BISHOP: + strcpy(mStr, "B"); + break; + case ROOK: + strcpy(mStr, "R"); + break; + case QUEEN: + strcpy(mStr, "Q"); + break; + case KING: + strcpy(mStr, "K"); + break; + default: + strcpy(mStr, ""); + break; + } /* switch */ - if ((piece == KING) && ((mt->fromFile == 4) && (mt->toFile == 6))) { - strcpy(mStr, "O-O"); - goto check; - } - if ((piece == KING) && ((mt->fromFile == 4) && (mt->toFile == 2))) { - strcpy(mStr, "O-O-O"); - goto check; - } - strcpy(mStr, ""); - switch (piece) { - case PAWN: - if (mt->fromFile == ALG_DROP) { - strcpy(mStr,"P"); - } else if (mt->fromFile != mt->toFile) { - sprintf(tmp, "%c", mt->fromFile + 'a'); - strcpy(mStr, tmp); - } - break; - case KNIGHT: - strcpy(mStr, "N"); - break; - case BISHOP: - strcpy(mStr, "B"); - break; - case ROOK: - strcpy(mStr, "R"); - break; - case QUEEN: - strcpy(mStr, "Q"); - break; - case KING: - strcpy(mStr, "K"); - break; - default: - strcpy(mStr, ""); - break; - } + if (mt->fromFile == ALG_DROP) { + strcat(mStr, DROP_STR); + } else { + /* + * Checks for ambiguity in short notation (Ncb3, R8e8 + * or so.) + */ + + if (piece != PAWN) { + ambig = r_ambig = f_ambig = 0; + + for (r = 0; r < 8; r++) { + for (f = 0; f < 8; f++) { + if (gs->board[f][r] != NOPIECE && + iscolor(gs->board[f][r], gs->onMove) && + piecetype(gs->board[f][r]) == piece && + (f != mt->fromFile || + r != mt->fromRank)) { + if (legal_move(gs, f, r, + mt->toFile, mt->toRank)) { + fakeMove = *gs; + fakeMove.board[f][r] = + NOPIECE; + fakeMove.onMove = + CToggle(fakeMove.onMove); + + gs->onMove = + CToggle(gs->onMove); + + /* + * New + * bracketing + * below to + * try to fix + * 'ambiguous + * move' bug. + */ + if (in_check(gs) || + !in_check(&fakeMove)) + ambig++; + + if (f == mt->fromFile) { + f_ambig++; + ambig++; + } + if (r == mt->fromRank) { + r_ambig++; + ambig++; + } + + gs->onMove = + CToggle(gs->onMove); + } + } + } /* for */ + } /* for */ + + if (ambig > 0) { + /* + * Ambiguity in short notation. need + * to add file, rank or _both_ in + * notation. + */ - if (mt->fromFile == ALG_DROP) { - strcat(mStr, DROP_STR); - } else { - /* Checks for ambiguity in short notation ( Ncb3, R8e8 or so) */ - if (piece != PAWN) { - ambig = r_ambig = f_ambig = 0; - for (r = 0; r < 8; r++) - for (f = 0; f < 8; f++) { - if ((gs->board[f][r] != NOPIECE) && iscolor(gs->board[f][r], gs->onMove) - && (piecetype(gs->board[f][r]) == piece) && - ((f != mt->fromFile) || (r != mt->fromRank))) { - if (legal_move(gs, f, r, mt->toFile, mt->toRank)) { - fakeMove = *gs; - fakeMove.board[f][r] = NOPIECE; - fakeMove.onMove = CToggle(fakeMove.onMove); - gs->onMove = CToggle(gs->onMove); - - /* New bracketing below to try to fix 'ambiguous move' bug. */ - if ((in_check(gs)) || !in_check(&fakeMove)) { - ambig++; - } - if (f == mt->fromFile) { - f_ambig++; - ambig++; - } - if (r == mt->fromRank) { - r_ambig++; - ambig++; - } - gs->onMove = CToggle(gs->onMove); - } + if (f_ambig == 0) { + sprintf(tmp, "%c", + (mt->fromFile + 'a')); + strcat(mStr, tmp); + } else if (r_ambig == 0) { + sprintf(tmp, "%d", (mt->fromRank + 1)); + strcat(mStr, tmp); + } else { + sprintf(tmp, "%c%d", + (mt->fromFile + 'a'), + (mt->fromRank + 1)); + strcat(mStr, tmp); + } + } + } + + if (gs->board[mt->toFile][mt->toRank] != NOPIECE || + (piece == PAWN && mt->fromFile != mt->toFile)) + strcat(mStr, "x"); } - } - if (ambig > 0) { - /* Ambiguity in short notation, need to add file,rank or _both_ in - notation */ - if (f_ambig == 0) { - sprintf(tmp, "%c", mt->fromFile + 'a'); - strcat(mStr, tmp); - } else if (r_ambig == 0) { - sprintf(tmp, "%d", mt->fromRank + 1); - strcat(mStr, tmp); - } else { - sprintf(tmp, "%c%d", mt->fromFile + 'a', mt->fromRank + 1); + + sprintf(tmp, "%c%d", mt->toFile + 'a', mt->toRank + 1); strcat(mStr, tmp); - } - } - } - if ((gs->board[mt->toFile][mt->toRank] != NOPIECE) || - ((piece == PAWN) && (mt->fromFile != mt->toFile))) { - strcat(mStr, "x"); - } - } - sprintf(tmp, "%c%d", mt->toFile + 'a', mt->toRank + 1); - strcat(mStr, tmp); - - if ((piece == PAWN) && (mt->piecePromotionTo != NOPIECE)) { - strcat(mStr, "="); /* = before promoting piece */ - switch (piecetype(mt->piecePromotionTo)) { - case KNIGHT: - strcat(mStr, "N"); - break; - case BISHOP: - strcat(mStr, "B"); - break; - case ROOK: - strcat(mStr, "R"); - break; - case QUEEN: - strcat(mStr, "Q"); - break; - default: - break; - } - } -check:; - fakeMove = *gs; - execute_move(&fakeMove, mt, 0); - fakeMove.onMove = CToggle(fakeMove.onMove); - if (in_check(&fakeMove)) { - strcat(mStr, "+"); - } - return mStr; + + if (piece == PAWN && mt->piecePromotionTo != NOPIECE) { + strcat(mStr, "="); /* = before promoting piece */ + + switch (piecetype(mt->piecePromotionTo)) { + case KNIGHT: + strcat(mStr, "N"); + break; + case BISHOP: + strcat(mStr, "B"); + break; + case ROOK: + strcat(mStr, "R"); + break; + case QUEEN: + strcat(mStr, "Q"); + break; + default: + break; + } + } + + check:; + + fakeMove = *gs; + execute_move(&fakeMove, mt, 0); + fakeMove.onMove = CToggle(fakeMove.onMove); + + if (in_check(&fakeMove)) + strcat(mStr, "+"); + + return mStr; } |