[board] Replace implementation of Board::piece_on_square with a simpler one

Now that board has a Mailbox, the implementation of this routine can be greatly
simplified. Instead of needing to iterate through all BitBoards to find the
occupied square, just consult the mailbox.
This commit is contained in:
Eryn Wells 2024-07-13 11:57:57 -07:00
parent 3785502ea0
commit c297e4cbfa

View file

@ -135,17 +135,10 @@ impl Board {
}
#[must_use]
pub fn piece_on_square(&self, sq: Square) -> Option<PlacedPiece> {
for color in Color::iter() {
for shape in Shape::iter() {
let piece = Piece::new(*color, *shape);
if self.pieces.bitboard_for_piece(&piece).is_set(sq) {
return Some(PlacedPiece::new(piece, sq));
}
}
}
None
pub fn piece_on_square(&self, square: Square) -> Option<PlacedPiece> {
self.pieces
.get(square)
.map(|piece| PlacedPiece::new(piece, square))
}
#[must_use]