From be72018a0a1285a343ad129e96c83a2e74e6d357 Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Tue, 20 Aug 2019 13:09:37 +0200 Subject: [PATCH] Invalid moves when checked now checked --- assignment1-18/chessboard.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/assignment1-18/chessboard.c b/assignment1-18/chessboard.c index 2d348e8..dfac173 100644 --- a/assignment1-18/chessboard.c +++ b/assignment1-18/chessboard.c @@ -331,13 +331,19 @@ enum mstatus move( return INVALID; } + bool check_before_move = player_checks(cb, p == WHITE ? BLACK : WHITE); bool can = can_move(cb, p, from_row, from_col, to_row, to_col); if (!can) { return INVALID; } else { + // FIXME: check if move is allowed in check state cb_move(cb, from_row, from_col, to_row, to_col); if (player_checks(cb, p)) { + if (check_before_move) { + DEBUG("move: move does not end check state, invalid"); + return INVALID; + } // TODO: check checkmate return CHECK; } else {