eschac
This commit is contained in:
commit
faccfbc1c5
16 changed files with 5154 additions and 0 deletions
44
src/rays.rs
Normal file
44
src/rays.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use crate::bitboard::*;
|
||||
use crate::board::*;
|
||||
|
||||
pub(crate) struct Rays(BySquare<ByDirection<Bitboard>>);
|
||||
|
||||
impl Rays {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self(BySquare::new(|square| {
|
||||
ByDirection::new(|direction| {
|
||||
let mut square = square;
|
||||
let mut res = Bitboard::new();
|
||||
while let Some(x) = square.trans(direction) {
|
||||
square = x;
|
||||
res |= square.bitboard();
|
||||
}
|
||||
res
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn ray(&self, square: Square, direction: Direction) -> Bitboard {
|
||||
*self.0.get(square).get(direction)
|
||||
}
|
||||
|
||||
pub(crate) fn blocked(
|
||||
&self,
|
||||
square: Square,
|
||||
direction: Direction,
|
||||
blockers: Bitboard,
|
||||
) -> Bitboard {
|
||||
let blockers = blockers & *self.0.get(square).get(direction);
|
||||
let square2 = if (direction as u8) < 4 {
|
||||
blockers.first()
|
||||
} else {
|
||||
blockers.last()
|
||||
};
|
||||
*self.0.get(square).get(direction)
|
||||
& !match square2 {
|
||||
Some(square2) => *self.0.get(square2).get(direction),
|
||||
None => Bitboard::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue