use crate::bitboard::*;
use crate::board::*;
use crate::magic::Magic;
pub(crate) use crate::util::*;
static MAGICS: &[Magic] = &include!(concat!(env!("OUT_DIR"), "/magics.rs"));
static TABLE: &[u64] = &include!(concat!(env!("OUT_DIR"), "/table.rs"));
#[inline]
pub(crate) fn bishop(square: Square, blockers: Bitboard) -> Bitboard {
aux(0, BISHOP_SHR, square, blockers)
}
#[inline]
pub(crate) fn rook(square: Square, blockers: Bitboard) -> Bitboard {
aux(1, ROOK_SHR, square, blockers)
}
#[inline]
pub(crate) fn aux(j: usize, shr: u8, square: Square, blockers: Bitboard) -> Bitboard {
let i = square.index() as usize + j * 64;
let Magic {
premask,
factor,
offset,
} = MAGICS[i];
let value = TABLE[((hash(shr, factor, blockers | premask) as isize) + offset) as usize];
Bitboard(value)
}
#[cfg(feature = "alloc")]
#[test]
fn test_magic_data() {
let (magics, table) = crate::magic::build();
assert_eq!(&magics, &MAGICS);
assert_eq!(&table, &TABLE);
assert_eq!(table.len(), 108731);
}