[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:
parent
3785502ea0
commit
c297e4cbfa
1 changed files with 4 additions and 11 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue