diff --git a/source/board.cpp b/source/board.cpp index 5983049..139ade9 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -290,7 +290,7 @@ void Board::DoMove(Move move) { int targetType = GetPieceType(move.moveTo); - int direction = attackerColor ? north : south; + int direction = attackerColor ? south : north; pieces[attackerType].PopBit(move.moveFrom); colors[attackerColor].PopBit(move.moveFrom); @@ -303,7 +303,7 @@ void Board::DoMove(Move move) { } else if (moveType == doublePawnPush) { occupied.SetBit(move.moveTo); enPassantTarget = move.moveFrom + direction; - } else if (moveType == capture) { + } else if (moveType == capture || moveType == epCapture) { pieces[targetType].PopBit(move.moveTo); colors[!attackerColor].PopBit(move.moveTo); } diff --git a/source/movegen.cpp b/source/movegen.cpp index 9be3468..b5bd374 100644 --- a/source/movegen.cpp +++ b/source/movegen.cpp @@ -276,7 +276,18 @@ static void GenPawnMoves(Board &board, bool color) { int square = pawns.getLS1BIndex(); int direction = color ? south : north; - Bitboard attacks = pawnAttacks[color][square] & board.colors[!color]; + Bitboard attacks = pawnAttacks[color][square]; + + // Checking for possible en passant + if (board.enPassantTarget) { + if ((attacks & Bitboard::GetSquare(board.enPassantTarget)).GetBoard() + && board.sideToMove == color) { + + board.AddMove(Move(square, board.enPassantTarget, epCapture)); + } + } + + attacks &= board.colors[!color]; Bitboard firstAhead = Bitboard::GetSquare(square + direction) & ~board.occupied; Bitboard secondAhead = Bitboard::GetSquare(square + 2 * direction) & ~board.occupied; @@ -307,7 +318,6 @@ static void GenPawnMoves(Board &board, bool color) { } } - pawns.PopBit(square); } } @@ -459,6 +469,8 @@ static void GenKingMoves(Board &board, bool color) { } void GenerateMoves(Board &board) { + board.moveList.clear(); + GenPawnMoves(board, White); GenPawnMoves(board, Black);