1.1 --- a/src/game.c Wed Mar 26 14:12:59 2014 +0100 1.2 +++ b/src/game.c Wed Mar 26 14:53:15 2014 +0100 1.3 @@ -78,9 +78,9 @@ 1.4 * @param move the move to apply 1.5 */ 1.6 static void apply_move(Board board, Move *move) { 1.7 - board[move->fromrow][move->fromfile] = 0; 1.8 + msrc(board, move) = 0; 1.9 // TODO: care for en passant capture 1.10 - board[move->torow][move->tofile] = move->piece; 1.11 + mdst(board, move) = move->piece; 1.12 1.13 /* castling */ 1.14 if ((move->piece & PIECE_MASK) == KING && 1.15 @@ -112,8 +112,14 @@ 1.16 } 1.17 1.18 /* does piece exist */ 1.19 - result = board[move->fromrow][move->fromfile] == move->piece; 1.20 + result = msrc(board, move) == move->piece; 1.21 1.22 + /* can't capture own pieces */ 1.23 + if ((mdst(board, move) & COLOR_MASK) == (move->piece & COLOR_MASK)) { 1.24 + return FALSE; 1.25 + } 1.26 + 1.27 + /* validate individual rules */ 1.28 switch (move->piece & PIECE_MASK) { 1.29 case PAWN: 1.30 result = result && pawn_chkrules(board, move); 1.31 @@ -247,8 +253,9 @@ 1.32 move->fromfile = fileidx(mstr[0]); 1.33 } 1.34 } else { 1.35 - /* move (e.g. "Ndf3") */ 1.36 - move->fromfile = fileidx(mstr[1]); 1.37 + /* move (e.g. "Ndf3", "N2c3") */ 1.38 + move->fromfile = isfile(mstr[1]) ? 1.39 + fileidx(mstr[1]) : rowidx(mstr[1]); 1.40 } 1.41 move->tofile = fileidx(mstr[2]); 1.42 move->torow = rowidx(mstr[3]); 1.43 @@ -366,6 +373,8 @@ 1.44 if (move.checkmate) { 1.45 printw("Checkmate!"); 1.46 return 1; 1.47 + } else { 1.48 + return 0; 1.49 } 1.50 } 1.51 } else {