error message when syntactically validating a King's move into a check position is now correct

Wed, 29 Aug 2018 17:31:36 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 29 Aug 2018 17:31:36 +0200
changeset 68
b34de5ce7d0e
parent 67
c76e46970a59
child 69
c8f2c280cff7

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
     1.1 --- a/src/chess/rules.c	Wed Aug 29 17:05:40 2018 +0200
     1.2 +++ b/src/chess/rules.c	Wed Aug 29 17:31:36 2018 +0200
     1.3 @@ -576,6 +576,7 @@
     1.4  static int getlocation(GameState *gamestate, Move *move) {   
     1.5  
     1.6      uint8_t color = move->piece & COLOR_MASK;
     1.7 +    uint8_t piece = move->piece & PIECE_MASK;
     1.8      _Bool incheck = gamestate->lastmove?gamestate->lastmove->move.check:0;
     1.9      
    1.10      Move threats[16], *threat = NULL;
    1.11 @@ -588,8 +589,8 @@
    1.12          
    1.13          /* find threats for the specified position */
    1.14          for (uint8_t i = 0 ; i < threatcount ; i++) {            
    1.15 -            if ((threats[i].piece & (PIECE_MASK | COLOR_MASK))
    1.16 -                    == move->piece &&
    1.17 +            if ((threats[i].piece & PIECE_MASK) == piece
    1.18 +                    && (threats[i].piece & COLOR_MASK) == color &&
    1.19                      (move->fromrow == POS_UNSPECIFIED ||
    1.20                      move->fromrow == threats[i].fromrow) &&
    1.21                      (move->fromfile == POS_UNSPECIFIED ||
    1.22 @@ -600,7 +601,8 @@
    1.23                  } else {
    1.24                      /* found threat is no real threat */
    1.25                      if (is_pinned(gamestate, &(threats[i]))) {
    1.26 -                        reason = incheck?KING_IN_CHECK:PIECE_PINNED;
    1.27 +                        reason = incheck?KING_IN_CHECK:
    1.28 +                            (piece==KING?KING_MOVES_INTO_CHECK:PIECE_PINNED);
    1.29                      } else {
    1.30                          threat = &(threats[i]);
    1.31                      }
     2.1 --- a/src/game.c	Wed Aug 29 17:05:40 2018 +0200
     2.2 +++ b/src/game.c	Wed Aug 29 17:31:36 2018 +0200
     2.3 @@ -235,8 +235,7 @@
     2.4              } else {
     2.5                  Move move;
     2.6                  int result = eval_move(gamestate, movestr, &move, curcolor);
     2.7 -                switch (result) {
     2.8 -                case VALID_MOVE_SYNTAX:
     2.9 +                if (result == VALID_MOVE_SYNTAX) {
    2.10                      result = validate_move(gamestate, &move);
    2.11                      if (result == VALID_MOVE_SEMANTICS) {
    2.12                          apply_move(gamestate, &move);
    2.13 @@ -254,8 +253,7 @@
    2.14                      } else {
    2.15                          eval_move_failed_msg(result);
    2.16                      }
    2.17 -                    break;
    2.18 -                default:
    2.19 +                } else {
    2.20                      eval_move_failed_msg(result);
    2.21                  }
    2.22                  clrtoeol();
     3.1 --- a/src/terminal-chess.h	Wed Aug 29 17:05:40 2018 +0200
     3.2 +++ b/src/terminal-chess.h	Wed Aug 29 17:31:36 2018 +0200
     3.3 @@ -36,7 +36,7 @@
     3.4  #ifndef TERMINAL_CHESS_H
     3.5  #define	TERMINAL_CHESS_H
     3.6  
     3.7 -#define PROGRAM_VERSION "0.9-r66"
     3.8 +#define PROGRAM_VERSION "0.9-r68"
     3.9  
    3.10  #ifdef	__cplusplus
    3.11  extern "C" {

mercurial