Thu, 03 Apr 2014 16:07:04 +0200
moved checkmate and stalemate flags to gamestate
src/chess/rules.c | file | annotate | diff | comparison | revisions | |
src/chess/rules.h | file | annotate | diff | comparison | revisions | |
src/game.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/chess/rules.c Tue Apr 01 14:04:00 2014 +0200 1.2 +++ b/src/chess/rules.c Thu Apr 03 16:07:04 2014 +0200 1.3 @@ -241,7 +241,7 @@ 1.4 move->check = 1; 1.5 } else if (mstr[len-1] == '#') { 1.6 len--; mstr[len] = '\0'; 1.7 - move->checkmate = 1; 1.8 + /* ignore - validation should set game state */ 1.9 } 1.10 1.11 /* evaluate promotion */
2.1 --- a/src/chess/rules.h Tue Apr 01 14:04:00 2014 +0200 2.2 +++ b/src/chess/rules.h Thu Apr 03 16:07:04 2014 +0200 2.3 @@ -77,8 +77,6 @@ 2.4 uint8_t torow; 2.5 uint8_t promotion; 2.6 _Bool check; 2.7 - _Bool checkmate; 2.8 - _Bool stalemate; // TODO: find a better place for checkmate and stalemate 2.9 _Bool capture; 2.10 } Move; 2.11 2.12 @@ -94,6 +92,8 @@ 2.13 uint8_t mycolor; 2.14 MoveList* movelist; 2.15 MoveList* lastmove; 2.16 + _Bool checkmate; 2.17 + _Bool stalemate; 2.18 } GameState; 2.19 2.20 #define opponent_color(color) ((color)==WHITE?BLACK:WHITE)
3.1 --- a/src/game.c Tue Apr 01 14:04:00 2014 +0200 3.2 +++ b/src/game.c Thu Apr 03 16:07:04 2014 +0200 3.3 @@ -95,8 +95,7 @@ 3.4 filechr(move.fromfile), rowchr(move.fromrow), 3.5 move.capture ? 'x':'\0', 3.6 filechr(move.tofile), rowchr(move.torow), 3.7 - move.check ? '+' : (move.checkmate ? '#' : 3.8 - (move.promotion ? '=' : '\0')), 3.9 + move.check ? '+' : (move.promotion ? '=' : '\0'), 3.10 move.promotion ? getpiecechr(move.promotion) : '\0' 3.11 }; 3.12 for (int stri = 0 ; stri < sizeof(logstr) ; stri++) { 3.13 @@ -105,6 +104,13 @@ 3.14 } 3.15 } 3.16 } 3.17 + if (!logelem->next) { 3.18 + if (gamestate->checkmate) { 3.19 + addch('#'); 3.20 + } else if (gamestate->stalemate) { 3.21 + addstr(" stalemate"); 3.22 + } 3.23 + } 3.24 addch(' '); 3.25 3.26 logelem = logelem->next; 3.27 @@ -162,11 +168,11 @@ 3.28 case VALID_MOVE_SYNTAX: 3.29 if (validate_move(gamestate, &move)) { 3.30 apply_move(gamestate, &move); 3.31 - if (move.checkmate) { 3.32 + if (gamestate->checkmate) { 3.33 printw("Checkmate!"); 3.34 clrtoeol(); 3.35 return 1; 3.36 - } else if (move.stalemate) { 3.37 + } else if (gamestate->stalemate) { 3.38 printw("Stalemate!"); 3.39 clrtoeol(); 3.40 return 1; 3.41 @@ -238,17 +244,17 @@ 3.42 net_send_data(opponent, NETCODE_MOVE, &move, sizeof(Move)); 3.43 code = net_recieve_code(opponent); 3.44 move.check = code == NETCODE_CHECK; 3.45 - move.checkmate = code == NETCODE_CHECKMATE; 3.46 - move.stalemate = code == NETCODE_STALEMATE; 3.47 + gamestate->checkmate = code == NETCODE_CHECKMATE; 3.48 + gamestate->stalemate = code == NETCODE_STALEMATE; 3.49 if (code == NETCODE_DECLINE) { 3.50 printw("Invalid move."); 3.51 } else { 3.52 apply_move(gamestate, &move); 3.53 - if (move.checkmate) { 3.54 + if (gamestate->checkmate) { 3.55 printw("Checkmate!"); 3.56 clrtoeol(); 3.57 return 1; 3.58 - } else if (move.stalemate) { 3.59 + } else if (gamestate->stalemate) { 3.60 printw("Stalemate!"); 3.61 clrtoeol(); 3.62 return 1; 3.63 @@ -300,12 +306,12 @@ 3.64 apply_move(gamestate, &move); 3.65 if (move.check) { 3.66 net_send_code(opponent, NETCODE_CHECK); 3.67 - } else if (move.checkmate) { 3.68 + } else if (gamestate->checkmate) { 3.69 net_send_code(opponent, NETCODE_CHECKMATE); 3.70 printw("\rCheckmate!"); 3.71 clrtoeol(); 3.72 return 1; 3.73 - } else if (move.stalemate) { 3.74 + } else if (gamestate->stalemate) { 3.75 net_send_code(opponent, NETCODE_STALEMATE); 3.76 printw("\rStalemate!"); 3.77 clrtoeol();