Invalid moves when checked now checked

This commit is contained in:
Claudio Maggioni (maggicl) 2019-08-20 13:09:37 +02:00
parent 635486c9b5
commit be72018a0a

View file

@ -331,13 +331,19 @@ enum mstatus move(
return INVALID; 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); bool can = can_move(cb, p, from_row, from_col, to_row, to_col);
if (!can) { if (!can) {
return INVALID; return INVALID;
} else { } else {
// FIXME: check if move is allowed in check state
cb_move(cb, from_row, from_col, to_row, to_col); cb_move(cb, from_row, from_col, to_row, to_col);
if (player_checks(cb, p)) { if (player_checks(cb, p)) {
if (check_before_move) {
DEBUG("move: move does not end check state, invalid");
return INVALID;
}
// TODO: check checkmate // TODO: check checkmate
return CHECK; return CHECK;
} else { } else {