[board] Implement a PositionBuilder; refactor piece bitboards into a PieceBitBoards struct
This makes Position immutable, even if declared mut. I think this will also make it easier to build positions going forward. Moving to a PieceBitBoards struct also required a lot of places that return owned BitBoards to return refs. This is basically fine except for adding a few more & here and there. This was a huge refactoring project. All the move generators and a bunch of BitBoard stuff needed to be updated.
This commit is contained in:
parent
939fac80d7
commit
24cce95a88
17 changed files with 472 additions and 381 deletions
|
|
@ -53,7 +53,7 @@ impl BitBoard {
|
|||
}
|
||||
|
||||
pub fn is_set(self, sq: Square) -> bool {
|
||||
!(self & sq.into()).is_empty()
|
||||
!(self & &sq.into()).is_empty()
|
||||
}
|
||||
|
||||
pub fn set_square(&mut self, sq: Square) {
|
||||
|
|
@ -180,11 +180,15 @@ macro_rules! assign_op {
|
|||
}
|
||||
|
||||
infix_op!(BitAnd, bitand, BitBoard, BitBoard);
|
||||
infix_op!(BitAnd, bitand, BitBoard, &BitBoard);
|
||||
infix_op!(BitAnd, bitand, &BitBoard, &BitBoard);
|
||||
|
||||
assign_op!(BitAndAssign, bitand_assign, BitBoard);
|
||||
assign_op!(BitOrAssign, bitor_assign, BitBoard);
|
||||
|
||||
infix_op!(BitOr, bitor, BitBoard, BitBoard);
|
||||
infix_op!(BitOr, bitor, BitBoard, &BitBoard);
|
||||
infix_op!(BitOr, bitor, &BitBoard, &BitBoard);
|
||||
|
||||
impl Not for BitBoard {
|
||||
type Output = BitBoard;
|
||||
|
|
|
|||
|
|
@ -165,13 +165,13 @@ impl MoveLibrary {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn generate_ray(sq: BitBoard, shift: fn(BitBoard) -> BitBoard) -> BitBoard {
|
||||
fn generate_ray(sq: BitBoard, shift: fn(&BitBoard) -> BitBoard) -> BitBoard {
|
||||
let mut ray = BitBoard::empty();
|
||||
|
||||
let mut iter = shift(sq);
|
||||
let mut iter = shift(&sq);
|
||||
while !iter.is_empty() {
|
||||
ray |= iter;
|
||||
iter = shift(iter);
|
||||
iter = shift(&iter);
|
||||
}
|
||||
|
||||
ray
|
||||
|
|
|
|||
|
|
@ -7,58 +7,58 @@ impl BitBoard {
|
|||
const NOT_H_FILE: u64 = 0x7f7f7f7f7f7f7f7f;
|
||||
|
||||
#[inline]
|
||||
pub fn shift_north(self, n: u8) -> BitBoard {
|
||||
pub fn shift_north(&self, n: u8) -> BitBoard {
|
||||
BitBoard(self.0 << (8 * n))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn shift_north_one(self) -> BitBoard {
|
||||
pub fn shift_north_one(&self) -> BitBoard {
|
||||
BitBoard(self.0 << 8)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn shift_north_east_one(self) -> BitBoard {
|
||||
pub fn shift_north_east_one(&self) -> BitBoard {
|
||||
BitBoard(self.0 << 9 & BitBoard::NOT_A_FILE)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn shift_east(self, n: u8) -> BitBoard {
|
||||
pub fn shift_east(&self, n: u8) -> BitBoard {
|
||||
// TODO: Implement a bounds check here.
|
||||
BitBoard(self.0 << n)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn shift_east_one(self) -> BitBoard {
|
||||
pub fn shift_east_one(&self) -> BitBoard {
|
||||
BitBoard(self.0 << 1 & BitBoard::NOT_A_FILE)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn shift_south_east_one(self) -> BitBoard {
|
||||
pub fn shift_south_east_one(&self) -> BitBoard {
|
||||
BitBoard(self.0 >> 7 & BitBoard::NOT_A_FILE)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn shift_south(self, n: u8) -> BitBoard {
|
||||
pub fn shift_south(&self, n: u8) -> BitBoard {
|
||||
BitBoard(self.0 >> (8 * n))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn shift_south_one(self) -> BitBoard {
|
||||
pub fn shift_south_one(&self) -> BitBoard {
|
||||
BitBoard(self.0 >> 8)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn shift_south_west_one(self) -> BitBoard {
|
||||
pub fn shift_south_west_one(&self) -> BitBoard {
|
||||
BitBoard(self.0 >> 9 & BitBoard::NOT_H_FILE)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn shift_west_one(self) -> BitBoard {
|
||||
pub fn shift_west_one(&self) -> BitBoard {
|
||||
BitBoard(self.0 >> 1 & BitBoard::NOT_H_FILE)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn shift_north_west_one(self) -> BitBoard {
|
||||
pub fn shift_north_west_one(&self) -> BitBoard {
|
||||
BitBoard(self.0 << 7 & BitBoard::NOT_H_FILE)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue