diff options
author | Jaume Delclòs Coll <cosa@cosarara.me> | 2024-05-08 14:52:40 +0000 |
---|---|---|
committer | Jaume Delclòs Coll <cosa@cosarara.me> | 2024-05-08 14:52:40 +0000 |
commit | 987117110618cf1f287eaee3fd09a4c73d00f4b7 (patch) | |
tree | 6639d26ad0b58fd6ac98050f4d571b63abe9f8ab | |
parent | 839625737c494e88d191e926c1ee814cd63fe9cb (diff) |
print promotions and check
-rw-r--r-- | chess.c | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -6,7 +6,6 @@ #include <keyboard.h> // Missing features -// underpromotion // display checkmate and stalemate // arrows to go back and forward in history // show moves better @@ -405,6 +404,8 @@ islegal(int board[8][8], Point src, Point dst, Move prev_move, CastleRights cr) void print_move(char* movestring, int board[8][8], Move move, Move prev_move, MoveType type, int was_capture, CastleRights cr) { char capturestr[2] = "x"; char piece_id[3] = ""; + char promotion[3] = ""; + char check[2] = ""; if (!was_capture) { capturestr[0] = 0; @@ -439,13 +440,29 @@ void print_move(char* movestring, int board[8][8], Move move, Move prev_move, Mo } sprint(piece_id, "%c%s%s", PIECE_STR[move.piece][1], src_file, src_rank); } + if (type == PromotionQ) { + sprint(promotion, "=Q"); + } else if (type == PromotionN) { + sprint(promotion, "=N"); + } else if (type == PromotionB) { + sprint(promotion, "=B"); + } else if (type == PromotionR) { + sprint(promotion, "=R"); + } + // test if it will be check + int tmpboard[8][8]; + memcpy(tmpboard, board, sizeof(int)*8*8); + do_move(tmpboard, move.src, move.dst, type); + if (is_in_check(tmpboard, !owner(move.piece))) { + sprint(check, "+"); + } if (type == WhiteLongCastle || type == BlackLongCastle) { sprint(movestring, "O-O-O"); } else if (type == WhiteShortCastle || type == BlackShortCastle) { sprint(movestring, "O-O"); } else { - sprint(movestring, "%s%s%c%d", piece_id, - capturestr, 'a'+move.dst.x, 8-move.dst.y); + sprint(movestring, "%s%s%c%d%s%s", piece_id, + capturestr, 'a'+move.dst.x, 8-move.dst.y, promotion, check); } } |