Fri, 28 Mar 2014 11:45:01 +0100
completed pawn rules + bug fixes for 4-char-moves
src/game.c | file | annotate | diff | comparison | revisions | |
src/rules/pawn.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/game.c Wed Mar 26 14:53:15 2014 +0100 1.2 +++ b/src/game.c Fri Mar 28 11:45:01 2014 +0100 1.3 @@ -78,14 +78,35 @@ 1.4 * @param move the move to apply 1.5 */ 1.6 static void apply_move(Board board, Move *move) { 1.7 + uint8_t piece = move->piece & PIECE_MASK; 1.8 + uint8_t color = move->piece & COLOR_MASK; 1.9 + 1.10 + /* en passant capture */ 1.11 + if (move->capture && piece == PAWN && 1.12 + mdst(board, move) == 0) { 1.13 + board[move->fromrow][move->tofile] = 0; 1.14 + } 1.15 + 1.16 + /* remove old en passant threats */ 1.17 + for (uint8_t file = 0 ; file < 8 ; file++) { 1.18 + board[3][file] &= ~ENPASSANT_THREAT; 1.19 + board[4][file] &= ~ENPASSANT_THREAT; 1.20 + } 1.21 + 1.22 + /* add new en passant threat */ 1.23 + if (piece == PAWN && ( 1.24 + (move->fromrow == 1 && move->torow == 3) || 1.25 + (move->fromrow == 6 && move->torow == 4))) { 1.26 + move->piece |= ENPASSANT_THREAT; 1.27 + } 1.28 + 1.29 + /* move (and maybe capture) */ 1.30 msrc(board, move) = 0; 1.31 - // TODO: care for en passant capture 1.32 mdst(board, move) = move->piece; 1.33 1.34 /* castling */ 1.35 - if ((move->piece & PIECE_MASK) == KING && 1.36 + if (piece == KING && 1.37 move->fromfile == fileidx('e')) { 1.38 - uint8_t color = move->piece & COLOR_MASK; 1.39 1.40 if (move->tofile == fileidx('g')) { 1.41 board[move->torow][fileidx('h')] = 0; 1.42 @@ -245,17 +266,23 @@ 1.43 1.44 } else if (len == 4) { 1.45 move->piece = getpiece(mstr[0]); 1.46 + if (!move->piece) { 1.47 + move->piece = PAWN; 1.48 + move->fromfile = fileidx(mstr[0]); 1.49 + } 1.50 if (mstr[1] == 'x') { 1.51 /* capture (e.g. "Nxf3", "dxe5") */ 1.52 move->capture = TRUE; 1.53 - if (!move->piece) { 1.54 - move->piece = PAWN; 1.55 - move->fromfile = fileidx(mstr[0]); 1.56 + } else { 1.57 + /* move (e.g. "Ndf3", "N2c3", "e2e4") */ 1.58 + if (isfile(mstr[1])) { 1.59 + move->fromfile = fileidx(mstr[1]); 1.60 + if (move->piece == PAWN) { 1.61 + move->piece = 0; 1.62 + } 1.63 + } else { 1.64 + move->fromrow = rowidx(mstr[1]); 1.65 } 1.66 - } else { 1.67 - /* move (e.g. "Ndf3", "N2c3") */ 1.68 - move->fromfile = isfile(mstr[1]) ? 1.69 - fileidx(mstr[1]) : rowidx(mstr[1]); 1.70 } 1.71 move->tofile = fileidx(mstr[2]); 1.72 move->torow = rowidx(mstr[3]);
2.1 --- a/src/rules/pawn.c Wed Mar 26 14:53:15 2014 +0100 2.2 +++ b/src/rules/pawn.c Fri Mar 28 11:45:01 2014 +0100 2.3 @@ -35,8 +35,9 @@ 2.4 if (move->fromrow == move->torow + d && ( 2.5 move->fromfile == move->tofile + 1 || 2.6 move->fromfile == move->tofile - 1)) { 2.7 - // TODO: en passant 2.8 - return mdst(board,move) != 0; /* color has been checked */ 2.9 + 2.10 + return mdst(board,move) 2.11 + || (board[move->fromrow][move->tofile] & ENPASSANT_THREAT); 2.12 } else { 2.13 return FALSE; 2.14 }