[bitboard, board, core, moves] Implement SliderMoveGenerator
This generator produces moves for slider pieces: bishops, rooks, and queens. All of these pieces behave identically, though with different sets of rays that emanate from the origin square. Claude helped me significantly with the implementation and unit testing. All the unit tests that took advantage of Claude for implementation are marked as such with an _ai_claude suffix to the test name. One unique aspect of this move generator that Claude suggested to me was to use loop { } instead of a recursive call to next() when the internal iterators expire. I may try to port this to the other move generators in the future. To support this move generator, implement a Slider enum in core that represents one of the three slider pieces. Add Board::bishops(), Board::rooks() and Board::queens() to return BitBoards of those pieces. These are analogous to the pawns() and knights() methods that return their corresponding pieces. Also in the board create, replace the separate sight method implementations with a macro. These are all the same, but with a different sight method called under the hood. Finally, derive Clone and Debug for the bit_scanner types.
This commit is contained in:
parent
2c6a7828bc
commit
f005d94fc2
7 changed files with 676 additions and 1 deletions
|
@ -119,6 +119,18 @@ impl Board {
|
|||
pub fn knights(&self, color: Color) -> BitBoard {
|
||||
self.find_pieces(Piece::knight(color))
|
||||
}
|
||||
|
||||
pub fn bishops(&self, color: Color) -> BitBoard {
|
||||
self.find_pieces(Piece::bishop(color))
|
||||
}
|
||||
|
||||
pub fn rooks(&self, color: Color) -> BitBoard {
|
||||
self.find_pieces(Piece::rook(color))
|
||||
}
|
||||
|
||||
pub fn queens(&self, color: Color) -> BitBoard {
|
||||
self.find_pieces(Piece::queen(color))
|
||||
}
|
||||
}
|
||||
|
||||
impl Board {
|
||||
|
|
|
@ -94,6 +94,28 @@ impl Sight for Piece {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! sight_method {
|
||||
($name:ident) => {
|
||||
pub fn $name(&self, square: Square, color: Option<Color>) -> BitBoard {
|
||||
let color = self.unwrap_color(color);
|
||||
|
||||
let info = SightInfo {
|
||||
square,
|
||||
occupancy: self.occupancy(),
|
||||
friendly_occupancy: self.friendly_occupancy(color),
|
||||
};
|
||||
|
||||
$name(&info)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl Board {
|
||||
sight_method!(bishop_sight);
|
||||
sight_method!(rook_sight);
|
||||
sight_method!(queen_sight);
|
||||
}
|
||||
|
||||
struct SightInfo {
|
||||
square: Square,
|
||||
occupancy: BitBoard,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue