diff -r faec61c4901f -r 970748b9a73b src/game.c --- a/src/game.c Wed Mar 26 14:12:59 2014 +0100 +++ b/src/game.c Wed Mar 26 14:53:15 2014 +0100 @@ -78,9 +78,9 @@ * @param move the move to apply */ static void apply_move(Board board, Move *move) { - board[move->fromrow][move->fromfile] = 0; + msrc(board, move) = 0; // TODO: care for en passant capture - board[move->torow][move->tofile] = move->piece; + mdst(board, move) = move->piece; /* castling */ if ((move->piece & PIECE_MASK) == KING && @@ -112,8 +112,14 @@ } /* does piece exist */ - result = board[move->fromrow][move->fromfile] == move->piece; + result = msrc(board, move) == move->piece; + /* can't capture own pieces */ + if ((mdst(board, move) & COLOR_MASK) == (move->piece & COLOR_MASK)) { + return FALSE; + } + + /* validate individual rules */ switch (move->piece & PIECE_MASK) { case PAWN: result = result && pawn_chkrules(board, move); @@ -247,8 +253,9 @@ move->fromfile = fileidx(mstr[0]); } } else { - /* move (e.g. "Ndf3") */ - move->fromfile = fileidx(mstr[1]); + /* move (e.g. "Ndf3", "N2c3") */ + move->fromfile = isfile(mstr[1]) ? + fileidx(mstr[1]) : rowidx(mstr[1]); } move->tofile = fileidx(mstr[2]); move->torow = rowidx(mstr[3]); @@ -366,6 +373,8 @@ if (move.checkmate) { printw("Checkmate!"); return 1; + } else { + return 0; } } } else {