Improve readability and remove redundant code

This commit is contained in:
stefiosif
2024-09-06 20:07:10 +03:00
parent 2081ddac56
commit 6b9650a6f0
7 changed files with 65 additions and 59 deletions

View File

@@ -104,11 +104,13 @@ impl Board {
Color::Black => lsb(self.black_pieces[PieceType::King].bitboard),
};
self.is_attacked(own_king_square, Color::opponent_color(color))
self.is_attacked(own_king_square, color.opponent())
}
pub fn pseudo_moves_all(&self, color: Color) -> Vec<Move> {
pub fn pseudo_moves_all(&self) -> Vec<Move> {
let color = self.state.current_player();
let mut moves = vec![];
moves.extend(self.pseudo_moves(color, PieceType::Pawn));
moves.extend(self.pseudo_moves(color, PieceType::Knight));
moves.extend(self.pseudo_moves(color, PieceType::Bishop));
@@ -245,8 +247,8 @@ pub enum Color {
}
impl Color {
pub const fn opponent_color(color: Self) -> Self {
match color {
pub const fn opponent(&self) -> Self {
match self {
Self::White => Self::Black,
Self::Black => Self::White,
}

View File

@@ -75,13 +75,11 @@ impl MoveParameters {
pub fn add_capture_and_promotion_piece(&mut self, board: &Board, mv: Move, color: Color) {
match mv.move_type {
MoveType::Capture => {
self.add_captured_piece(board, mv.dst, Color::opponent_color(color))
}
MoveType::Capture => self.add_captured_piece(board, mv.dst, color.opponent()),
MoveType::Promotion(piece) => self.add_promoted_piece(piece),
MoveType::PromotionCapture(piece) => {
self.add_promoted_piece(piece);
self.add_captured_piece(board, mv.dst, Color::opponent_color(color));
self.add_captured_piece(board, mv.dst, color.opponent());
}
_ => (),
}