added en passant

This commit is contained in:
rektdie committed 2024-03-30 22:22:30 +01:00
1 parent 2d777be0a5
commit 9534a787f9
2 files changed
+16 -4

No files matched your search

+2 -2
View File
@@ -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);
}
+14 -2
View File
@@ -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);