diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-02-23 13:21:57 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-02-23 14:01:19 +0300 |
commit | 43dc24718c442ef45f6cecf5790df0ab84a72cfc (patch) | |
tree | 16f446b1d5a3e0fdf638e0bcab16cf34ec338bd8 /src/attacks.rs | |
parent | f60c573ba71207c18a28413e3940a4e21b07c73f (diff) | |
download | chessnost-43dc24718c442ef45f6cecf5790df0ab84a72cfc.tar.gz |
refactor: apply clippy suggestions
Diffstat (limited to 'src/attacks.rs')
-rw-r--r-- | src/attacks.rs | 52 |
1 files changed, 30 insertions, 22 deletions
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 } |