[position] Implement generating pawn moves by looking up bitboards in the Library

This enables a bunch of clean up! Remove the MoveGenerationParameters and MoveList
types from move_generator::pawn.

Implement BitBoard::pawn_pushes to look up pawn pushes by square and color.
This commit is contained in:
Eryn Wells 2024-01-28 10:25:01 -08:00
parent 77f419ad3b
commit ea74b214da
3 changed files with 48 additions and 72 deletions

View file

@ -44,6 +44,10 @@ impl BitBoard {
library().pawn_attacks(sq, color)
}
pub fn pawn_pushes(sq: Square, color: Color) -> BitBoard {
library().pawn_pushes(sq, color)
}
moves_getter!(knight_moves);
moves_getter!(bishop_moves);
moves_getter!(rook_moves);

View file

@ -58,6 +58,7 @@ pub(super) struct MoveLibrary {
// Piecewise move tables
pawn_attacks: [[BitBoard; 64]; 2],
pawn_pushes: [[BitBoard; 64]; 2],
knight_moves: [BitBoard; 64],
bishop_moves: [BitBoard; 64],
rook_moves: [BitBoard; 64],
@ -70,6 +71,7 @@ impl MoveLibrary {
MoveLibrary {
rays: [[BitBoard::empty(); 8]; Square::NUM],
pawn_attacks: [[BitBoard::empty(); 64]; 2],
pawn_pushes: [[BitBoard::empty(); 64]; 2],
knight_moves: [BitBoard::empty(); 64],
bishop_moves: [BitBoard::empty(); 64],
rook_moves: [BitBoard::empty(); 64],
@ -169,10 +171,29 @@ impl MoveLibrary {
fn init_pawn_moves(&mut self, sq: Square) {
let bitboard: BitBoard = sq.into();
self.pawn_attacks[Color::White as usize][sq as usize] =
bitboard.shift_north_west_one() | bitboard.shift_north_east_one();
self.pawn_attacks[Color::Black as usize][sq as usize] =
bitboard.shift_south_west_one() | bitboard.shift_south_east_one();
self.pawn_pushes[Color::White as usize][sq as usize] = {
let mut push = bitboard.shift_north_one();
if !(bitboard & RANKS[1]).is_empty() {
push |= push.shift_north_one();
}
push
};
self.pawn_pushes[Color::Black as usize][sq as usize] = {
let mut push = bitboard.shift_south_one();
if !(bitboard & RANKS[6]).is_empty() {
push |= push.shift_south_one();
}
push
};
}
#[inline]
@ -192,6 +213,10 @@ impl MoveLibrary {
self.rays[sq as usize][dir as usize]
}
pub(super) fn pawn_pushes(&self, sq: Square, color: Color) -> BitBoard {
self.pawn_pushes[color as usize][sq as usize]
}
pub(super) fn pawn_attacks(&self, sq: Square, color: Color) -> BitBoard {
self.pawn_attacks[color as usize][sq as usize]
}