[board] Update a bunch of methods to take &Piece instead of plain Piece
This commit is contained in:
parent
f7951d6110
commit
1a907844d6
8 changed files with 20 additions and 16 deletions
|
@ -48,7 +48,7 @@ impl<'pos> MoveGeneratorInternal for ClassicalMoveGenerator<'pos> {
|
||||||
let quiet_moves_bb = all_moves & (empty_squares | !friendly_pieces);
|
let quiet_moves_bb = all_moves & (empty_squares | !friendly_pieces);
|
||||||
let capture_moves_bb = all_moves & opposing_pieces;
|
let capture_moves_bb = all_moves & opposing_pieces;
|
||||||
|
|
||||||
let map_to_move = |sq| MoveBuilder::new(piece, square, sq).build();
|
let map_to_move = |sq| MoveBuilder::new(*piece, square, sq).build();
|
||||||
let quiet_moves = quiet_moves_bb.occupied_squares().map(map_to_move);
|
let quiet_moves = quiet_moves_bb.occupied_squares().map(map_to_move);
|
||||||
let capture_moves = capture_moves_bb.occupied_squares().map(map_to_move);
|
let capture_moves = capture_moves_bb.occupied_squares().map(map_to_move);
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ impl<'pos> MoveGeneratorInternal for KingMoveGenerator<'pos> {
|
||||||
// TODO: Handle checks. Prevent moving a king to a square attacked by a
|
// TODO: Handle checks. Prevent moving a king to a square attacked by a
|
||||||
// piece of the opposite color.
|
// piece of the opposite color.
|
||||||
|
|
||||||
let map_to_move = |sq| MoveBuilder::new(piece, square, sq).build();
|
let map_to_move = |sq| MoveBuilder::new(*piece, square, sq).build();
|
||||||
|
|
||||||
let king_side_castle = Self::king_side_castle(position, color);
|
let king_side_castle = Self::king_side_castle(position, color);
|
||||||
let queen_side_castle = Self::queen_side_castle(position, color);
|
let queen_side_castle = Self::queen_side_castle(position, color);
|
||||||
|
|
|
@ -22,11 +22,11 @@ impl<'pos> MoveGeneratorInternal for KnightMoveGenerator<'pos> {
|
||||||
let capture_moves_bb = knight_moves & opposing_pieces;
|
let capture_moves_bb = knight_moves & opposing_pieces;
|
||||||
|
|
||||||
let quiet_moves = quiet_moves_bb.occupied_squares().map(|to_sq| {
|
let quiet_moves = quiet_moves_bb.occupied_squares().map(|to_sq| {
|
||||||
MoveBuilder::new(placed_piece.piece(), placed_piece.square(), to_sq).build()
|
MoveBuilder::new(*placed_piece.piece(), placed_piece.square(), to_sq).build()
|
||||||
});
|
});
|
||||||
let capture_moves = capture_moves_bb.occupied_squares().map(|to_sq| {
|
let capture_moves = capture_moves_bb.occupied_squares().map(|to_sq| {
|
||||||
let captured_piece = position.piece_on_square(to_sq).unwrap();
|
let captured_piece = position.piece_on_square(to_sq).unwrap();
|
||||||
MoveBuilder::new(placed_piece.piece(), placed_piece.square(), to_sq)
|
MoveBuilder::new(*placed_piece.piece(), placed_piece.square(), to_sq)
|
||||||
.capturing(captured_piece)
|
.capturing(captured_piece)
|
||||||
.build()
|
.build()
|
||||||
});
|
});
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl<'pos> MoveGeneratorInternal for ClassicalMoveGenerator<'pos> {
|
||||||
let quiet_moves_bb = all_moves & (empty_squares | !friendly_pieces);
|
let quiet_moves_bb = all_moves & (empty_squares | !friendly_pieces);
|
||||||
let capture_moves_bb = all_moves & opposing_pieces;
|
let capture_moves_bb = all_moves & opposing_pieces;
|
||||||
|
|
||||||
let map_to_move = |sq| MoveBuilder::new(piece, square, sq).build();
|
let map_to_move = |sq| MoveBuilder::new(*piece, square, sq).build();
|
||||||
let quiet_moves = quiet_moves_bb.occupied_squares().map(map_to_move);
|
let quiet_moves = quiet_moves_bb.occupied_squares().map(map_to_move);
|
||||||
let capture_moves = capture_moves_bb.occupied_squares().map(map_to_move);
|
let capture_moves = capture_moves_bb.occupied_squares().map(map_to_move);
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl<'pos> MoveGeneratorInternal for ClassicalMoveGenerator<'pos> {
|
||||||
let quiet_moves_bb = all_moves & (empty_squares | !friendly_pieces);
|
let quiet_moves_bb = all_moves & (empty_squares | !friendly_pieces);
|
||||||
let capture_moves_bb = all_moves & opposing_pieces;
|
let capture_moves_bb = all_moves & opposing_pieces;
|
||||||
|
|
||||||
let map_to_move = |sq| MoveBuilder::new(piece, square, sq).build();
|
let map_to_move = |sq| MoveBuilder::new(*piece, square, sq).build();
|
||||||
let quiet_moves = quiet_moves_bb.occupied_squares().map(map_to_move);
|
let quiet_moves = quiet_moves_bb.occupied_squares().map(map_to_move);
|
||||||
let capture_moves = capture_moves_bb.occupied_squares().map(map_to_move);
|
let capture_moves = capture_moves_bb.occupied_squares().map(map_to_move);
|
||||||
|
|
||||||
|
|
|
@ -244,8 +244,8 @@ impl PlacedPiece {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn piece(&self) -> Piece {
|
pub fn piece(&self) -> &Piece {
|
||||||
self.piece
|
&self.piece
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -66,11 +66,11 @@ impl PieceBitBoards {
|
||||||
self.by_color.bitboard_mut(color)
|
self.by_color.bitboard_mut(color)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn bitboard_for_piece(&self, piece: Piece) -> &BitBoard {
|
pub(super) fn bitboard_for_piece(&self, piece: &Piece) -> &BitBoard {
|
||||||
self.by_color_and_shape.bitboard_for_piece(piece)
|
self.by_color_and_shape.bitboard_for_piece(piece)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn bitboard_for_piece_mut(&mut self, piece: Piece) -> &mut BitBoard {
|
pub(super) fn bitboard_for_piece_mut(&mut self, piece: &Piece) -> &mut BitBoard {
|
||||||
self.by_color_and_shape.bitboard_for_piece_mut(piece)
|
self.by_color_and_shape.bitboard_for_piece_mut(piece)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,15 +135,15 @@ impl ByColor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ByColorAndShape {
|
impl ByColorAndShape {
|
||||||
fn bitboard_for_piece(&self, piece: Piece) -> &BitBoard {
|
fn bitboard_for_piece(&self, piece: &Piece) -> &BitBoard {
|
||||||
&self.0[piece.color() as usize][piece.shape() as usize]
|
&self.0[piece.color() as usize][piece.shape() as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bitboard_for_piece_mut(&mut self, piece: Piece) -> &mut BitBoard {
|
fn bitboard_for_piece_mut(&mut self, piece: &Piece) -> &mut BitBoard {
|
||||||
&mut self.0[piece.color() as usize][piece.shape() as usize]
|
&mut self.0[piece.color() as usize][piece.shape() as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_square(&mut self, square: Square, piece: Piece) {
|
fn set_square(&mut self, square: Square, piece: &Piece) {
|
||||||
self.bitboard_for_piece_mut(piece).set_square(square);
|
self.bitboard_for_piece_mut(piece).set_square(square);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ impl Position {
|
||||||
for color in Color::iter() {
|
for color in Color::iter() {
|
||||||
for shape in Shape::iter() {
|
for shape in Shape::iter() {
|
||||||
let piece = Piece::new(color, *shape);
|
let piece = Piece::new(color, *shape);
|
||||||
if self.pieces.bitboard_for_piece(piece).is_set(sq) {
|
if self.pieces.bitboard_for_piece(&piece).is_set(sq) {
|
||||||
return Some(PlacedPiece::new(piece, sq));
|
return Some(PlacedPiece::new(piece, sq));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ impl Position {
|
||||||
|
|
||||||
fn king_square(&self) -> Square {
|
fn king_square(&self) -> Square {
|
||||||
self.pieces
|
self.pieces
|
||||||
.bitboard_for_piece(Piece::king(self.color_to_move))
|
.bitboard_for_piece(&Piece::king(self.color_to_move))
|
||||||
.occupied_squares()
|
.occupied_squares()
|
||||||
.next()
|
.next()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -207,6 +207,10 @@ impl Position {
|
||||||
pub(super) fn flags(&self) -> Flags {
|
pub(super) fn flags(&self) -> Flags {
|
||||||
self.flags
|
self.flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) fn piece_bitboards(&self) -> &PieceBitBoards {
|
||||||
|
&self.pieces
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// crate methods
|
// crate methods
|
||||||
|
@ -216,7 +220,7 @@ impl Position {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn bitboard_for_piece(&self, piece: Piece) -> &BitBoard {
|
pub(crate) 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