[board] Create a bitboard! macro and BitBoardBuilder
The Builder enables cleanly building a BitBoard out of squares. The macro lets you create a BitBoard from a simple list of coordinates: bitboard!(A1, B2, C3, D4, …)
This commit is contained in:
parent
9ef53b76f5
commit
a6b98abb95
3 changed files with 32 additions and 1 deletions
|
@ -188,6 +188,27 @@ 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 {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue