aboutsummaryrefslogtreecommitdiff
path: root/src/attacks.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/attacks.rs')
-rw-r--r--src/attacks.rs49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/attacks.rs b/src/attacks.rs
index 73f3d73..d5bc8a3 100644
--- a/src/attacks.rs
+++ b/src/attacks.rs
@@ -307,14 +307,21 @@ mod tests {
use super::*;
+ static DEFAULT_OCCUPANCY: Bitboard =
+ 1 << Square::B7 as usize |
+ 1 << Square::B1 as usize |
+ 1 << Square::C2 as usize |
+ 1 << Square::F3 as usize;
+
#[test]
fn test_pawn_attacks() {
let attacks = Attacks::precompute_pawn_attacks();
let square = Square::E4 as usize;
-
let white_attacks = attacks[Color::White as usize][square];
+
+ print(white_attacks, "Pawn e4");
+
assert_eq!(white_attacks, 1 << Square::D5 as usize | 1 << Square::F5 as usize);
- print(white_attacks);
assert_eq!(attacks[Color::White as usize][Square::H4 as usize], 1 << Square::G5 as usize);
assert_eq!(attacks[Color::White as usize][Square::A4 as usize], 1 << Square::B5 as usize);
@@ -337,6 +344,8 @@ mod tests {
let attacks = Attacks::precompute_knight_attacks();
let e4_attacks = attacks[Square::E4 as usize];
+ print(e4_attacks, "Knight e4");
+
assert_ne!(e4_attacks & 1 << Square::G5 as usize, 0);
assert_ne!(e4_attacks & 1 << Square::G3 as usize, 0);
assert_ne!(e4_attacks & 1 << Square::C5 as usize, 0);
@@ -352,12 +361,14 @@ mod tests {
assert_eq!(pop_count(attacks[Square::G1 as usize]), 3);
assert_eq!(pop_count(attacks[Square::H8 as usize]), 2);
- print(e4_attacks);
}
#[test]
fn test_king_attacks() {
let attacks = Attacks::precompute_king_attacks();
+
+ print(attacks[Square::E4 as usize], "King e4");
+
assert_eq!(pop_count(attacks[Square::E4 as usize]), 8);
assert_eq!(pop_count(attacks[Square::A1 as usize]), 3);
@@ -369,7 +380,6 @@ mod tests {
assert_eq!(pop_count(attacks[Square::E8 as usize]), 5);
assert_eq!(pop_count(attacks[Square::A4 as usize]), 5);
assert_eq!(pop_count(attacks[Square::H4 as usize]), 5);
- print(attacks[Square::E4 as usize]);
}
#[test]
@@ -402,19 +412,17 @@ mod tests {
attacks[5][square] |
attacks[6][square] |
attacks[7][square];
- print(bitboard);
+ print(bitboard, "Rays from e4");
}
#[test]
fn test_bishop_attacks() {
let attacks = Attacks::new();
let square = Square::E4 as u8;
- let occupancy =
- 1 << Square::B7 as usize |
- 1 << Square::B1 as usize |
- 1 << Square::C2 as usize |
- 1 << Square::F3 as usize;
- let bb = attacks.bishop(occupancy, square);
+ let bb = attacks.bishop(DEFAULT_OCCUPANCY, square);
+
+ print(DEFAULT_OCCUPANCY, "Occupancy");
+ print(bb, "Bishop e4");
assert_ne!(bb & 1 << Square::C2 as u8, 0);
assert_eq!(bb & 1 << Square::B1 as u8, 0);
@@ -423,8 +431,6 @@ mod tests {
assert_ne!(bb & 1 << Square::H7 as u8, 0);
assert_ne!(bb & 1 << Square::B7 as u8, 0);
assert_eq!(bb & 1 << Square::A8 as u8, 0);
-
- print(bb);
}
#[test]
@@ -439,6 +445,9 @@ mod tests {
1 << Square::F3 as usize;
let bb = attacks.rook(occupancy, square);
+ print(occupancy, "Occupancy");
+ print(bb, "Rook e4");
+
assert_ne!(bb & 1 << Square::E8 as u8, 0);
assert_ne!(bb & 1 << Square::E7 as u8, 0);
assert_ne!(bb & 1 << Square::E6 as u8, 0);
@@ -449,22 +458,14 @@ mod tests {
assert_ne!(bb & 1 << Square::A4 as u8, 0);
assert_ne!(bb & 1 << Square::H4 as u8, 0);
assert_eq!(bb & 1 << Square::E4 as u8, 0);
-
- print(bb);
}
#[test]
fn test_queen_attacks() {
let attacks = Attacks::new();
let square = Square::E4 as u8;
- let occupancy =
- 1 << Square::B7 as usize |
- 1 << Square::B1 as usize |
- 1 << Square::C2 as usize |
- 1 << Square::E3 as usize |
- 1 << Square::F3 as usize;
- let bb = attacks.queen(occupancy, square);
- print(occupancy);
- print(bb);
+ let bb = attacks.queen(DEFAULT_OCCUPANCY, square);
+ print(DEFAULT_OCCUPANCY, "Occupancy");
+ print(bb, "Queen e4");
}
}