1.1 --- a/src/game.c Wed May 28 15:47:57 2014 +0200 1.2 +++ b/src/game.c Wed Jun 11 15:38:01 2014 +0200 1.3 @@ -162,7 +162,7 @@ 1.4 printw("Ambiguous move - please specify the piece to move."); 1.5 break; 1.6 case INVALID_POSITION: 1.7 - printw("Cannot find the piece that shall be moved."); 1.8 + printw("No piece can be moved this way."); 1.9 break; 1.10 case NEED_PROMOTION: 1.11 printw("You need to promote the pawn (append \"=Q\" e.g.)!"); 1.12 @@ -176,6 +176,12 @@ 1.13 case INVALID_MOVE_SYNTAX: 1.14 printw("Can't interpret move - please use algebraic notation."); 1.15 break; 1.16 + case RULES_VIOLATED: 1.17 + printw("Move does not comply chess rules."); 1.18 + break; 1.19 + case KING_MOVES_INTO_CHECK: 1.20 + printw("Can't move the king into a check position."); 1.21 + break; 1.22 default: 1.23 printw("Unknown move parser error."); 1.24 } 1.25 @@ -218,7 +224,8 @@ 1.26 int eval_result = eval_move(gamestate, movestr, &move); 1.27 switch (eval_result) { 1.28 case VALID_MOVE_SYNTAX: 1.29 - if (validate_move(gamestate, &move)) { 1.30 + eval_result = validate_move(gamestate, &move); 1.31 + if (eval_result == VALID_MOVE_SEMANTICS) { 1.32 apply_move(gamestate, &move); 1.33 if (gamestate->checkmate) { 1.34 printw("Checkmate!"); 1.35 @@ -232,7 +239,7 @@ 1.36 return 0; 1.37 } 1.38 } else { 1.39 - printw("Invalid move."); 1.40 + eval_move_failed_msg(eval_result); 1.41 } 1.42 break; 1.43 default: 1.44 @@ -306,11 +313,15 @@ 1.45 case VALID_MOVE_SYNTAX: 1.46 net_send_data(opponent, NETCODE_MOVE, &move, sizeof(Move)); 1.47 code = net_recieve_code(opponent); 1.48 - move.check = code == NETCODE_CHECK; 1.49 + move.check = code == NETCODE_CHECK || 1.50 + code == NETCODE_CHECKMATE; 1.51 gamestate->checkmate = code == NETCODE_CHECKMATE; 1.52 gamestate->stalemate = code == NETCODE_STALEMATE; 1.53 if (code == NETCODE_DECLINE) { 1.54 - printw("Invalid move."); 1.55 + uint32_t reason; 1.56 + net_recieve_data(opponent, &reason, sizeof(uint32_t)); 1.57 + reason = ntohl(reason); 1.58 + eval_move_failed_msg(reason); 1.59 } else if (code == NETCODE_ACCEPT 1.60 || code == NETCODE_CHECK 1.61 || code == NETCODE_CHECKMATE 1.62 @@ -397,7 +408,8 @@ 1.63 break; 1.64 case NETCODE_MOVE: 1.65 net_recieve_data(opponent, &move, sizeof(Move)); 1.66 - if (validate_move(gamestate, &move)) { 1.67 + code = validate_move(gamestate, &move); 1.68 + if (code == VALID_MOVE_SEMANTICS) { 1.69 apply_move(gamestate, &move); 1.70 if (move.check) { 1.71 net_send_code(opponent, NETCODE_CHECK); 1.72 @@ -416,7 +428,9 @@ 1.73 } 1.74 return 0; 1.75 } else { 1.76 - net_send_code(opponent, NETCODE_DECLINE); 1.77 + uint32_t reason = htonl(code); 1.78 + net_send_data(opponent, NETCODE_DECLINE, 1.79 + &reason, sizeof(uint32_t)); 1.80 } 1.81 break; 1.82 default: