# HG changeset patch # User Mike Becker # Date 1535556696 -7200 # Node ID b34de5ce7d0e5d3bc984ac11738492115f8df515 # Parent c76e46970a597eb603b5ee7625ee24a67f1fe4e8 error message when syntactically validating a King's move into a check position is now correct diff -r c76e46970a59 -r b34de5ce7d0e src/chess/rules.c --- 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]); } diff -r c76e46970a59 -r b34de5ce7d0e src/game.c --- 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(); diff -r c76e46970a59 -r b34de5ce7d0e src/terminal-chess.h --- a/src/terminal-chess.h Wed Aug 29 17:05:40 2018 +0200 +++ b/src/terminal-chess.h Wed Aug 29 17:31:36 2018 +0200 @@ -36,7 +36,7 @@ #ifndef TERMINAL_CHESS_H #define TERMINAL_CHESS_H -#define PROGRAM_VERSION "0.9-r66" +#define PROGRAM_VERSION "0.9-r68" #ifdef __cplusplus extern "C" {