src/game.c

changeset 27
efeb98bc69c9
parent 26
e0a76ee1bb2b
child 28
0c1371488d87
     1.1 --- a/src/game.c	Tue Apr 01 14:04:00 2014 +0200
     1.2 +++ b/src/game.c	Thu Apr 03 16:07:04 2014 +0200
     1.3 @@ -95,8 +95,7 @@
     1.4                      filechr(move.fromfile), rowchr(move.fromrow),
     1.5                      move.capture ? 'x':'\0',
     1.6                      filechr(move.tofile), rowchr(move.torow),
     1.7 -                    move.check ? '+' : (move.checkmate ? '#' : 
     1.8 -                        (move.promotion ? '=' : '\0')),
     1.9 +                    move.check ? '+' : (move.promotion ? '=' : '\0'),
    1.10                      move.promotion ? getpiecechr(move.promotion) : '\0'
    1.11                  };
    1.12                  for (int stri = 0 ; stri < sizeof(logstr) ; stri++) {
    1.13 @@ -105,6 +104,13 @@
    1.14                      }
    1.15                  }
    1.16              }
    1.17 +            if (!logelem->next) {
    1.18 +                if (gamestate->checkmate) {
    1.19 +                    addch('#');
    1.20 +                } else if (gamestate->stalemate) {
    1.21 +                    addstr(" stalemate");
    1.22 +                }
    1.23 +            }
    1.24              addch(' ');
    1.25              
    1.26              logelem = logelem->next;
    1.27 @@ -162,11 +168,11 @@
    1.28              case VALID_MOVE_SYNTAX:
    1.29                  if (validate_move(gamestate, &move)) {
    1.30                      apply_move(gamestate, &move);
    1.31 -                    if (move.checkmate) {
    1.32 +                    if (gamestate->checkmate) {
    1.33                          printw("Checkmate!");
    1.34                          clrtoeol();
    1.35                          return 1;
    1.36 -                    } else if (move.stalemate) {
    1.37 +                    } else if (gamestate->stalemate) {
    1.38                          printw("Stalemate!");
    1.39                          clrtoeol();
    1.40                          return 1;
    1.41 @@ -238,17 +244,17 @@
    1.42                  net_send_data(opponent, NETCODE_MOVE, &move, sizeof(Move));
    1.43                  code = net_recieve_code(opponent);
    1.44                  move.check = code == NETCODE_CHECK;
    1.45 -                move.checkmate = code == NETCODE_CHECKMATE;
    1.46 -                move.stalemate = code == NETCODE_STALEMATE;
    1.47 +                gamestate->checkmate = code == NETCODE_CHECKMATE;
    1.48 +                gamestate->stalemate = code == NETCODE_STALEMATE;
    1.49                  if (code == NETCODE_DECLINE) {
    1.50                      printw("Invalid move.");
    1.51                  } else {
    1.52                      apply_move(gamestate, &move);
    1.53 -                    if (move.checkmate) {
    1.54 +                    if (gamestate->checkmate) {
    1.55                          printw("Checkmate!");
    1.56                          clrtoeol();
    1.57                          return 1;
    1.58 -                    } else if (move.stalemate) {
    1.59 +                    } else if (gamestate->stalemate) {
    1.60                          printw("Stalemate!");
    1.61                          clrtoeol();
    1.62                          return 1;
    1.63 @@ -300,12 +306,12 @@
    1.64                      apply_move(gamestate, &move);
    1.65                      if (move.check) {
    1.66                          net_send_code(opponent, NETCODE_CHECK);
    1.67 -                    } else if (move.checkmate) {
    1.68 +                    } else if (gamestate->checkmate) {
    1.69                          net_send_code(opponent, NETCODE_CHECKMATE);
    1.70                          printw("\rCheckmate!");
    1.71                          clrtoeol();
    1.72                          return 1;
    1.73 -                    } else if (move.stalemate) {
    1.74 +                    } else if (gamestate->stalemate) {
    1.75                          net_send_code(opponent, NETCODE_STALEMATE);
    1.76                          printw("\rStalemate!");
    1.77                          clrtoeol();

mercurial