summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaume Delclòs Coll <cosa@cosarara.me>2024-05-08 15:01:57 +0000
committerJaume Delclòs Coll <cosa@cosarara.me>2024-05-08 15:01:57 +0000
commitc29b4c401e1a0e99fc05da96f392bd240c29b67b (patch)
tree5c4572fbc488150ac4a265e97560a0a2059b32ee
parent987117110618cf1f287eaee3fd09a4c73d00f4b7 (diff)
annotate checkmate
-rw-r--r--chess.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/chess.c b/chess.c
index 0977877..6b71578 100644
--- a/chess.c
+++ b/chess.c
@@ -398,6 +398,19 @@ islegal(int board[8][8], Point src, Point dst, Move prev_move, CastleRights cr)
return move_type;
}
+int can_move(int board[8][8], Player player, Move prev_move, CastleRights cr) {
+ for (int srcx=0; srcx<8; srcx++) for (int srcy=0; srcy<8; srcy++) {
+ if (owner(board[srcy][srcx]) == player) {
+ for (int dstx=0; dstx<8; dstx++) for (int dsty=0; dsty<8; dsty++) {
+ if (islegal(board, Pt(srcx, srcy), Pt(dstx, dsty), prev_move, cr)) {
+ return 1;
+ }
+ }
+ }
+ }
+ return 0;
+}
+
// longest possible move would be something like Qa1xe4+,
// so with null byte 8 characters is enough
#define MOVE_STR_LEN 8
@@ -455,6 +468,8 @@ void print_move(char* movestring, int board[8][8], Move move, Move prev_move, Mo
do_move(tmpboard, move.src, move.dst, type);
if (is_in_check(tmpboard, !owner(move.piece))) {
sprint(check, "+");
+ if (!can_move(tmpboard, !owner(move.piece), move, cr))
+ sprint(check, "#");
}
if (type == WhiteLongCastle || type == BlackLongCastle) {
sprint(movestring, "O-O-O");