use crate::get_king_attacks;
use crate::get_knight_attacks;
use crate::get_pawn_attacks;
use crate::{BitBoard, Board, Color, Piece, Square};
use crate::{get_bishop_attacks, get_rook_attacks};
impl Board {
#[inline(always)]
pub const fn white_bitboard(&self) -> BitBoard {
self.sides_bitboard[Color::White as usize]
}
#[inline(always)]
pub const fn black_bitboard(&self) -> BitBoard {
self.sides_bitboard[Color::Black as usize]
}
#[inline(always)]
pub const fn combined_bitboard(&self) -> BitBoard {
BitBoard(self.white_bitboard().0 | self.black_bitboard().0)
}
#[inline(always)]
pub const fn piece_presence(&self, piece: Piece) -> BitBoard {
BitBoard(
self.pieces_bitboard[piece.piece_index()].0
& self.sides_bitboard[piece.color() as usize].0,
)
}
#[inline(always)]
pub const fn allied_presence(&self) -> BitBoard {
self.sides_bitboard[self.side as usize]
}
#[inline(always)]
pub const fn enemy_presence(&self) -> BitBoard {
self.sides_bitboard[self.side as usize ^ 1]
}
#[inline(always)]
pub fn enemy_queen_bishops(&self) -> BitBoard {
self.enemy_queens() | self.enemy_bishops()
}
#[inline(always)]
pub fn enemy_queen_rooks(&self) -> BitBoard {
self.enemy_queens() | self.enemy_rooks()
}
#[inline]
pub fn attackers(&self, square: Square, blockers: BitBoard) -> BitBoard {
self.enemy_presence()
& (self.knights() & get_knight_attacks(square)
| self.kings() & get_king_attacks(square)
| self.pawns() & get_pawn_attacks(self.side, square)
| (self.queens() | self.bishops()) & get_bishop_attacks(square, blockers)
| (self.queens() | self.rooks()) & get_rook_attacks(square, blockers))
}
#[inline(always)]
pub fn attacked_square(&self, square: Square, blockers: BitBoard) -> bool {
self.attackers(square, blockers) != BitBoard::EMPTY
}
#[inline(always)]
pub fn checkers(&self) -> BitBoard {
self.attackers(
self.allied_king().to_square().unwrap(),
self.combined_bitboard(),
)
}
}