From c297e4cbfaa2e08c5f6c17326061e870f0efa76f Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 13 Jul 2024 11:57:57 -0700 Subject: [PATCH] [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. --- board/src/board.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/board/src/board.rs b/board/src/board.rs index 036d4ee..b602237 100644 --- a/board/src/board.rs +++ b/board/src/board.rs @@ -135,17 +135,10 @@ impl Board { } #[must_use] - pub fn piece_on_square(&self, sq: Square) -> Option { - 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 { + self.pieces + .get(square) + .map(|piece| PlacedPiece::new(piece, square)) } #[must_use]