Refactor some clippy-pedantic errors

This commit is contained in:
stefiosif
2024-09-06 20:30:57 +03:00
parent 6b9650a6f0
commit 2093d91dfa
12 changed files with 42 additions and 47 deletions

View File

@@ -1,7 +1,6 @@
use u64 as Bitboard;
pub const EMPTY: Bitboard = 0x0;
pub const FULL: Bitboard = 0xffffffffffffffff;
pub const NOT_FILE_A: Bitboard = 0xfefefefefefefefe;
pub const NOT_FILE_H: Bitboard = 0x7f7f7f7f7f7f7f7f;
pub const NOT_FILE_AB: Bitboard = 0xfcfcfcfcfcfcfcfc;

View File

@@ -153,7 +153,7 @@ impl Board {
}
}
pub fn set_piece(&mut self, piece: Piece) {
pub fn set_piece(&mut self, piece: &Piece) {
match piece.color {
Color::Black => self.black_pieces[piece.piece_type].bitboard |= piece.bitboard,
Color::White => self.white_pieces[piece.piece_type].bitboard |= piece.bitboard,
@@ -211,7 +211,7 @@ pub enum PieceType {
}
impl PieceType {
const fn idx(&self) -> usize {
const fn idx(self) -> usize {
match self {
Self::Pawn => 0,
Self::Knight => 1,
@@ -247,7 +247,7 @@ pub enum Color {
}
impl Color {
pub const fn opponent(&self) -> Self {
pub const fn opponent(self) -> Self {
match self {
Self::White => Self::Black,
Self::Black => Self::White,

View File

@@ -62,7 +62,7 @@ pub fn piece_placement(pieces: &str) -> Result<Board, FenError> {
))
}
} {
board.set_piece(Piece::new(1 << square, piece_type, color));
board.set_piece(&Piece::new(1 << square, piece_type, color));
file += 1;
};
}

View File

@@ -19,7 +19,7 @@ impl Game {
from_fen(fen)
}
pub const fn run(&self) {
pub const fn run() {
Board::new();
}

View File

@@ -17,7 +17,7 @@ impl History {
}
pub fn push_move_parameters(&mut self, move_parameters: MoveParameters) {
self.move_parameters.push(move_parameters)
self.move_parameters.push(move_parameters);
}
pub fn pop_move_parameters(&mut self) -> Option<MoveParameters> {
@@ -56,7 +56,7 @@ impl MoveParameters {
}
fn add_move(&mut self, mv: Move) {
self.mv = Some(mv)
self.mv = Some(mv);
}
fn add_captured_piece(&mut self, board: &Board, dst: usize, color: Color) {
@@ -64,13 +64,13 @@ impl MoveParameters {
}
fn add_promoted_piece(&mut self, promote: Promote) {
self.promoted_piece = Some(promote.into_piece_type())
self.promoted_piece = Some(promote.into_piece_type());
}
pub fn add_irreversible_parameters(&mut self, state: State) {
self.castling_ability = Some(state.castling_ability);
self.en_passant_square = state.en_passant_square;
self.halfmove_clock = Some(state.halfmove_clock)
self.halfmove_clock = Some(state.halfmove_clock);
}
pub fn add_capture_and_promotion_piece(&mut self, board: &Board, mv: Move, color: Color) {
@@ -107,7 +107,7 @@ mod tests {
move_parameters.add_capture_and_promotion_piece(&game.board, mv, game.current_player());
game.board.make_move(&mv);
game.board.unmake_move(move_parameters);
game.board.unmake_move(&move_parameters);
assert_eq!(board_before_make, game.board);
@@ -118,7 +118,7 @@ mod tests {
move_parameters.add_capture_and_promotion_piece(&game.board, mv, game.current_player());
game.board.make_move(&mv);
game.board.unmake_move(move_parameters);
game.board.unmake_move(&move_parameters);
assert_eq!(board_before_make, game.board);
@@ -137,7 +137,7 @@ mod tests {
move_parameters.add_capture_and_promotion_piece(&game.board, mv, game.current_player());
game.board.make_move(&mv);
game.board.unmake_move(move_parameters);
game.board.unmake_move(&move_parameters);
assert_eq!(board_before_make, game.board);
@@ -148,7 +148,7 @@ mod tests {
move_parameters.add_capture_and_promotion_piece(&game.board, mv, game.current_player());
game.board.make_move(&mv);
game.board.unmake_move(move_parameters);
game.board.unmake_move(&move_parameters);
assert_eq!(board_before_make, game.board);
@@ -163,7 +163,7 @@ mod tests {
move_parameters.add_capture_and_promotion_piece(&game.board, mv, game.current_player());
game.board.make_move(&mv);
game.board.unmake_move(move_parameters);
game.board.unmake_move(&move_parameters);
assert_eq!(board_before_make, game.board);
@@ -184,7 +184,7 @@ mod tests {
move_parameters.add_capture_and_promotion_piece(&game.board, mv, game.current_player());
game.board.make_move(&mv);
game.board.unmake_move(move_parameters);
game.board.unmake_move(&move_parameters);
assert_eq!(board_before_make, game.board);
@@ -203,7 +203,7 @@ mod tests {
move_parameters.add_capture_and_promotion_piece(&game.board, mv, game.current_player());
game.board.make_move(&mv);
game.board.unmake_move(move_parameters);
game.board.unmake_move(&move_parameters);
assert_eq!(board_before_make, game.board);

View File

@@ -62,8 +62,9 @@ impl State {
self.update_castling_state_capture(src, color);
match (src, color) {
(4, Color::White) => self.set_castling_ability(color, Castle::None),
(60, Color::Black) => self.set_castling_ability(color, Castle::None),
(4, Color::White) | (60, Color::Black) => {
self.set_castling_ability(color, Castle::None)
}
_ => (),
}
}