Wed, 29 Aug 2018 17:31:36 +0200
error message when syntactically validating a King's move into a check position is now correct
src/chess/rules.c | file | annotate | diff | comparison | revisions | |
src/game.c | file | annotate | diff | comparison | revisions | |
src/terminal-chess.h | file | annotate | diff | comparison | revisions |
--- a/src/chess/rules.c Wed Aug 29 17:05:40 2018 +0200 +++ b/src/chess/rules.c Wed Aug 29 17:31:36 2018 +0200 @@ -576,6 +576,7 @@ static int getlocation(GameState *gamestate, Move *move) { uint8_t color = move->piece & COLOR_MASK; + uint8_t piece = move->piece & PIECE_MASK; _Bool incheck = gamestate->lastmove?gamestate->lastmove->move.check:0; Move threats[16], *threat = NULL; @@ -588,8 +589,8 @@ /* find threats for the specified position */ for (uint8_t i = 0 ; i < threatcount ; i++) { - if ((threats[i].piece & (PIECE_MASK | COLOR_MASK)) - == move->piece && + if ((threats[i].piece & PIECE_MASK) == piece + && (threats[i].piece & COLOR_MASK) == color && (move->fromrow == POS_UNSPECIFIED || move->fromrow == threats[i].fromrow) && (move->fromfile == POS_UNSPECIFIED || @@ -600,7 +601,8 @@ } else { /* found threat is no real threat */ if (is_pinned(gamestate, &(threats[i]))) { - reason = incheck?KING_IN_CHECK:PIECE_PINNED; + reason = incheck?KING_IN_CHECK: + (piece==KING?KING_MOVES_INTO_CHECK:PIECE_PINNED); } else { threat = &(threats[i]); }
--- a/src/game.c Wed Aug 29 17:05:40 2018 +0200 +++ b/src/game.c Wed Aug 29 17:31:36 2018 +0200 @@ -235,8 +235,7 @@ } else { Move move; int result = eval_move(gamestate, movestr, &move, curcolor); - switch (result) { - case VALID_MOVE_SYNTAX: + if (result == VALID_MOVE_SYNTAX) { result = validate_move(gamestate, &move); if (result == VALID_MOVE_SEMANTICS) { apply_move(gamestate, &move); @@ -254,8 +253,7 @@ } else { eval_move_failed_msg(result); } - break; - default: + } else { eval_move_failed_msg(result); } clrtoeol();