# HG changeset patch # User Mike Becker # Date 1396003501 -3600 # Node ID 7ffd66591afef09dd9710fb19718376839d40b05 # Parent 970748b9a73b8d3f9a22fc9bf109423094aa94ed completed pawn rules + bug fixes for 4-char-moves diff -r 970748b9a73b -r 7ffd66591afe src/game.c --- a/src/game.c Wed Mar 26 14:53:15 2014 +0100 +++ b/src/game.c Fri Mar 28 11:45:01 2014 +0100 @@ -78,14 +78,35 @@ * @param move the move to apply */ static void apply_move(Board board, Move *move) { + uint8_t piece = move->piece & PIECE_MASK; + uint8_t color = move->piece & COLOR_MASK; + + /* en passant capture */ + if (move->capture && piece == PAWN && + mdst(board, move) == 0) { + board[move->fromrow][move->tofile] = 0; + } + + /* remove old en passant threats */ + for (uint8_t file = 0 ; file < 8 ; file++) { + board[3][file] &= ~ENPASSANT_THREAT; + board[4][file] &= ~ENPASSANT_THREAT; + } + + /* add new en passant threat */ + if (piece == PAWN && ( + (move->fromrow == 1 && move->torow == 3) || + (move->fromrow == 6 && move->torow == 4))) { + move->piece |= ENPASSANT_THREAT; + } + + /* move (and maybe capture) */ msrc(board, move) = 0; - // TODO: care for en passant capture mdst(board, move) = move->piece; /* castling */ - if ((move->piece & PIECE_MASK) == KING && + if (piece == KING && move->fromfile == fileidx('e')) { - uint8_t color = move->piece & COLOR_MASK; if (move->tofile == fileidx('g')) { board[move->torow][fileidx('h')] = 0; @@ -245,17 +266,23 @@ } else if (len == 4) { move->piece = getpiece(mstr[0]); + if (!move->piece) { + move->piece = PAWN; + move->fromfile = fileidx(mstr[0]); + } if (mstr[1] == 'x') { /* capture (e.g. "Nxf3", "dxe5") */ move->capture = TRUE; - if (!move->piece) { - move->piece = PAWN; - move->fromfile = fileidx(mstr[0]); + } else { + /* move (e.g. "Ndf3", "N2c3", "e2e4") */ + if (isfile(mstr[1])) { + move->fromfile = fileidx(mstr[1]); + if (move->piece == PAWN) { + move->piece = 0; + } + } else { + move->fromrow = rowidx(mstr[1]); } - } else { - /* 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]); diff -r 970748b9a73b -r 7ffd66591afe src/rules/pawn.c --- a/src/rules/pawn.c Wed Mar 26 14:53:15 2014 +0100 +++ b/src/rules/pawn.c Fri Mar 28 11:45:01 2014 +0100 @@ -35,8 +35,9 @@ if (move->fromrow == move->torow + d && ( move->fromfile == move->tofile + 1 || move->fromfile == move->tofile - 1)) { - // TODO: en passant - return mdst(board,move) != 0; /* color has been checked */ + + return mdst(board,move) + || (board[move->fromrow][move->tofile] & ENPASSANT_THREAT); } else { return FALSE; }