From 43dc24718c442ef45f6cecf5790df0ab84a72cfc Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 23 Feb 2023 13:21:57 +0300 Subject: refactor: apply clippy suggestions --- src/attacks.rs | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'src/attacks.rs') diff --git a/src/attacks.rs b/src/attacks.rs index d0f2ddd..f666bae 100644 --- a/src/attacks.rs +++ b/src/attacks.rs @@ -49,6 +49,12 @@ pub struct Attacks { pub ray_attacks: [AttackTable; 8], } +impl Default for Attacks { + fn default() -> Self { + Self::new() + } +} + #[allow(unused)] impl Attacks { pub fn new() -> Self { @@ -97,34 +103,36 @@ impl Attacks { fn precompute_knight_attacks() -> AttackTable { let mut attacks = [0; 64]; - for index in 0..64 { - let square = 1u64 << index; - attacks[index] = - ((square & NOT_A_FILE & NOT_B_FILE) << 6) | - ((square & NOT_G_FILE & NOT_H_FILE) << 10) | - ((square & NOT_A_FILE) << 15) | - ((square & NOT_H_FILE) << 17) | - ((square & NOT_G_FILE & NOT_H_FILE) >> 6) | - ((square & NOT_A_FILE & NOT_B_FILE) >> 10) | - ((square & NOT_H_FILE) >> 15) | - ((square & NOT_A_FILE) >> 17); + + for (index, bitboard) in attacks.iter_mut().enumerate() { + let square_bb = Square::from(index as u8).to_bitboard(); + *bitboard = + ((square_bb & NOT_A_FILE & NOT_B_FILE) << 6) | + ((square_bb & NOT_G_FILE & NOT_H_FILE) << 10) | + ((square_bb & NOT_A_FILE) << 15) | + ((square_bb & NOT_H_FILE) << 17) | + ((square_bb & NOT_G_FILE & NOT_H_FILE) >> 6) | + ((square_bb & NOT_A_FILE & NOT_B_FILE) >> 10) | + ((square_bb & NOT_H_FILE) >> 15) | + ((square_bb & NOT_A_FILE) >> 17); } attacks } fn precompute_king_attacks() -> AttackTable { let mut attacks = [0; 64]; - for index in 0..64 { - let square = 1u64 << index; - attacks[index] = - ((square & NOT_A_FILE) >> 1) | - ((square & NOT_A_FILE) << 7) | - ((square & NOT_A_FILE) >> 9) | - ((square & NOT_H_FILE) << 1) | - ((square & NOT_H_FILE) >> 7) | - ((square & NOT_H_FILE) << 9) | - (square << 8) | - (square >> 8); + + for (index, bitboard) in attacks.iter_mut().enumerate() { + let square_bb = Square::from(index as u8).to_bitboard(); + *bitboard = + ((square_bb & NOT_A_FILE) >> 1) | + ((square_bb & NOT_A_FILE) << 7) | + ((square_bb & NOT_A_FILE) >> 9) | + ((square_bb & NOT_H_FILE) << 1) | + ((square_bb & NOT_H_FILE) >> 7) | + ((square_bb & NOT_H_FILE) << 9) | + (square_bb << 8) | + (square_bb >> 8); } attacks } -- cgit v1.2.3