[bitboard] Add pawn attacks bitboards to the Library
This commit is contained in:
parent
164fe94bc0
commit
1f873879bb
2 changed files with 20 additions and 1 deletions
|
@ -40,6 +40,10 @@ impl BitBoard {
|
|||
library().ray(sq, dir)
|
||||
}
|
||||
|
||||
pub fn pawn_attacks(sq: Square, color: Color) -> BitBoard {
|
||||
library().pawn_attacks(sq, color)
|
||||
}
|
||||
|
||||
moves_getter!(knight_moves);
|
||||
moves_getter!(bishop_moves);
|
||||
moves_getter!(rook_moves);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
use crate::BitBoard;
|
||||
use chessfriend_core::{Direction, Square};
|
||||
use chessfriend_core::{Color, Direction, Square};
|
||||
use std::sync::Once;
|
||||
|
||||
pub(super) const RANKS: [BitBoard; 8] = [
|
||||
|
@ -57,6 +57,7 @@ pub(super) struct MoveLibrary {
|
|||
rays: [[BitBoard; 8]; Square::NUM],
|
||||
|
||||
// Piecewise move tables
|
||||
pawn_attacks: [[BitBoard; 64]; 2],
|
||||
knight_moves: [BitBoard; 64],
|
||||
bishop_moves: [BitBoard; 64],
|
||||
rook_moves: [BitBoard; 64],
|
||||
|
@ -68,6 +69,7 @@ impl MoveLibrary {
|
|||
const fn new() -> MoveLibrary {
|
||||
MoveLibrary {
|
||||
rays: [[BitBoard::empty(); 8]; Square::NUM],
|
||||
pawn_attacks: [[BitBoard::empty(); 64]; 2],
|
||||
knight_moves: [BitBoard::empty(); 64],
|
||||
bishop_moves: [BitBoard::empty(); 64],
|
||||
rook_moves: [BitBoard::empty(); 64],
|
||||
|
@ -78,6 +80,7 @@ impl MoveLibrary {
|
|||
|
||||
fn init(&mut self) {
|
||||
for sq in Square::ALL {
|
||||
self.init_pawn_moves(sq);
|
||||
self.init_orthogonal_rays(sq);
|
||||
self.init_diagonal_rays(sq);
|
||||
self.init_knight_moves(sq as usize);
|
||||
|
@ -164,6 +167,14 @@ impl MoveLibrary {
|
|||
self.queen_moves[sq as usize] = rook_moves | bishop_moves;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn generate_ray(sq: BitBoard, shift: fn(&BitBoard) -> BitBoard) -> BitBoard {
|
||||
let mut ray = BitBoard::empty();
|
||||
|
@ -181,6 +192,10 @@ impl MoveLibrary {
|
|||
self.rays[sq as usize][dir as usize]
|
||||
}
|
||||
|
||||
pub(super) fn pawn_attacks(&self, sq: Square, color: Color) -> BitBoard {
|
||||
self.pawn_attacks[color as usize][sq as usize]
|
||||
}
|
||||
|
||||
library_getter!(knight_moves);
|
||||
library_getter!(bishop_moves);
|
||||
library_getter!(rook_moves);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue