aboutsummaryrefslogtreecommitdiff
path: root/src/attacks.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/attacks.rs')
-rw-r--r--src/attacks.rs52
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
}