Remove BitBoardBuilder
It's unused except for the macro, and BitBoard itself can be declared mutable, and implements Copy and Clone. So, I don't think having a separate Builder type helps much.
This commit is contained in:
parent
19feff9591
commit
2480ef25e9
2 changed files with 17 additions and 35 deletions
|
@ -355,26 +355,6 @@ impl Not for &BitBoard {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct BitBoardBuilder(BitBoard);
|
||||
|
||||
impl BitBoardBuilder {
|
||||
pub const fn empty() -> BitBoardBuilder {
|
||||
BitBoardBuilder(BitBoard::empty())
|
||||
}
|
||||
|
||||
pub fn new(bits: u64) -> BitBoardBuilder {
|
||||
BitBoardBuilder(BitBoard::new(bits))
|
||||
}
|
||||
|
||||
pub fn square(mut self, square: Square) -> BitBoardBuilder {
|
||||
self.0.set_square(square);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(&self) -> BitBoard {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@ -453,18 +433,18 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn xor() {
|
||||
let a = bitboard![C5, G7];
|
||||
let b = bitboard![B5, G7, H3];
|
||||
let a = bitboard![C5 G7];
|
||||
let b = bitboard![B5 G7 H3];
|
||||
|
||||
assert_eq!(a ^ b, bitboard![B5, C5, H3]);
|
||||
assert_eq!(a ^ b, bitboard![B5 C5 H3]);
|
||||
assert_eq!(a ^ BitBoard::empty(), a);
|
||||
assert_eq!(BitBoard::empty() ^ BitBoard::empty(), BitBoard::empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitand_assign() {
|
||||
let mut a = bitboard![C5, G7];
|
||||
let b = bitboard![B5, G7, H3];
|
||||
let mut a = bitboard![C5 G7];
|
||||
let b = bitboard![B5 G7 H3];
|
||||
|
||||
a &= b;
|
||||
|
||||
|
@ -473,12 +453,12 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn bitor_assign() {
|
||||
let mut a = bitboard![C5, G7];
|
||||
let b = bitboard![B5, G7, H3];
|
||||
let mut a = bitboard![C5 G7];
|
||||
let b = bitboard![B5 G7 H3];
|
||||
|
||||
a |= b;
|
||||
|
||||
assert_eq!(a, bitboard![B5, C5, G7, H3]);
|
||||
assert_eq!(a, bitboard![B5 C5 G7 H3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -489,11 +469,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn first_occupied_squares() {
|
||||
let bb = bitboard![A8, E1];
|
||||
let bb = bitboard![A8 E1];
|
||||
assert_eq!(bb.first_occupied_square(), Some(Square::A8));
|
||||
assert_eq!(bb.first_occupied_square_trailing(), Some(Square::E1));
|
||||
|
||||
let bb = bitboard![D6, E7, F8];
|
||||
let bb = bitboard![D6 E7 F8];
|
||||
assert_eq!(bb.first_occupied_square_trailing(), Some(Square::D6));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,15 +5,17 @@ mod bitboard;
|
|||
mod library;
|
||||
mod shifts;
|
||||
|
||||
pub use bitboard::{BitBoard, BitBoardBuilder};
|
||||
pub use bitboard::BitBoard;
|
||||
|
||||
pub(crate) use bit_scanner::{LeadingBitScanner, TrailingBitScanner};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! bitboard {
|
||||
($($sq:ident),* $(,)?) => {
|
||||
$crate::BitBoardBuilder::empty()
|
||||
$(.square(chessfriend_core::Square::$sq))*
|
||||
.build()
|
||||
($($sq:ident)* $(,)?) => {
|
||||
{
|
||||
let mut bitboard = $crate::BitBoard::empty();
|
||||
$(bitboard.set(chessfriend_core::Square::$sq);)*
|
||||
bitboard
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue