GenPawnMoves function

This commit is contained in:
rektdie committed 2024-03-28 20:00:33 +01:00
1 parent b58c6bea77
commit 2aebd781fb
6 files changed
+53 -16

No files matched your search

+28
View File
@@ -271,4 +271,32 @@ Bitboard getQueenAttack(int square, U64 occupancy) {
rookOccupancy >>= (64 - rookRelevantBits[square]);
return rookAttacks[square][rookOccupancy] | bishopAttacks[square][bishopOccupancy];
}
void GenPawnMoves(Board &board, bool color) {
Bitboard pawns = board.colors[color] & board.pieces[Pawn];
while (pawns.GetBoard()) {
int square = pawns.getLS1BIndex();
int direction = color ? south : north;
Bitboard attacks = pawnAttacks[color][square] & board.colors[!color];
attacks |= (Bitboard::GetSquare(square + direction)
| Bitboard::GetSquare(square + 2 * direction)) & ~(board.occupied);
while (attacks.GetBoard()) {
int targetSquare = attacks.getLS1BIndex();
board.AddMove(Move(SQUARE(square), SQUARE(targetSquare)));
attacks.PopBit(targetSquare);
}
pawns.PopBit(square);
}
}
void GenerateMoves(Board &board) {
GenPawnMoves(board, White);
GenPawnMoves(board, Black);
}