[board] Convert &BitBoard to BitBoard for several Board methods
I don't think passing by reference buys much for BitBoard. So simplify the logic and borrowing semantics to make these easier to work with.
This commit is contained in:
parent
7ec72035ae
commit
30188d478e
1 changed files with 13 additions and 10 deletions
|
@ -111,23 +111,26 @@ impl Board {
|
||||||
/// A [`BitBoard`] representing the set of squares containing a piece. This
|
/// A [`BitBoard`] representing the set of squares containing a piece. This
|
||||||
/// set is the inverse of [`Board::empty_squares`].
|
/// set is the inverse of [`Board::empty_squares`].
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn occupied_squares(&self) -> &BitBoard {
|
pub fn occupied_squares(&self) -> BitBoard {
|
||||||
self.pieces.all_pieces()
|
self.pieces.all_pieces()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn friendly_pieces(&self) -> &BitBoard {
|
pub fn friendly_pieces_bitboard(&self) -> BitBoard {
|
||||||
self.pieces.all_pieces_of_color(self.player_to_move)
|
self.pieces.all_pieces_of_color(self.player_to_move)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn opposing_pieces(&self) -> &BitBoard {
|
pub fn opposing_pieces_bitboard(&self) -> BitBoard {
|
||||||
self.pieces.all_pieces_of_color(self.player_to_move.other())
|
self.pieces.all_pieces_of_color(self.player_to_move.other())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn all_pieces(&self) -> (&BitBoard, &BitBoard) {
|
pub fn all_pieces(&self) -> (BitBoard, BitBoard) {
|
||||||
(self.friendly_pieces(), self.opposing_pieces())
|
(
|
||||||
|
self.friendly_pieces_bitboard(),
|
||||||
|
self.opposing_pieces_bitboard(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [BitBoard] representing the set of squares containing a piece. This
|
/// A [BitBoard] representing the set of squares containing a piece. This
|
||||||
|
@ -166,8 +169,8 @@ impl Board {
|
||||||
self.en_passant
|
self.en_passant
|
||||||
}
|
}
|
||||||
|
|
||||||
fn king_bitboard(&self, player: Color) -> &BitBoard {
|
fn king_bitboard(&self, player: Color) -> BitBoard {
|
||||||
self.pieces.bitboard_for_piece(&Piece::king(player))
|
self.pieces.bitboard_for_piece(Piece::king(player))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn king_square(&self, player: Color) -> Square {
|
pub(crate) fn king_square(&self, player: Color) -> Square {
|
||||||
|
@ -183,13 +186,13 @@ impl Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn bitboard_for_color(&self, color: Color) -> &BitBoard {
|
pub fn bitboard_for_color(&self, color: Color) -> BitBoard {
|
||||||
self.pieces.bitboard_for_color(color)
|
self.pieces.bitboard_for_color(color)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn bitboard_for_piece(&self, piece: Piece) -> &BitBoard {
|
pub fn bitboard_for_piece(&self, piece: Piece) -> BitBoard {
|
||||||
self.pieces.bitboard_for_piece(&piece)
|
self.pieces.bitboard_for_piece(piece)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue