aboutsummaryrefslogtreecommitdiff
path: root/src/attacks.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-02-21 05:22:54 +0300
committereug-vs <eugene@eug-vs.xyz>2023-02-21 05:28:45 +0300
commit46e9fcdcce5730827355db9449c41dc0a0e42b1f (patch)
tree7b9903446bd7884df6a22ddd2c6a2b8a6dcc3d44 /src/attacks.rs
parent02ebad55af6c76ac9e36832f9be041f547f63b7c (diff)
downloadchessnost-46e9fcdcce5730827355db9449c41dc0a0e42b1f.tar.gz
refactor: use bitboard trait
Diffstat (limited to 'src/attacks.rs')
-rw-r--r--src/attacks.rs48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/attacks.rs b/src/attacks.rs
index eafaf01..d32ac64 100644
--- a/src/attacks.rs
+++ b/src/attacks.rs
@@ -307,7 +307,7 @@ impl Attacks {
#[cfg(test)]
mod tests {
- use crate::{bitboard::{pop_count, print}, square::Square};
+ use crate::{bitboard::BitboardFns, square::Square};
use super::*;
@@ -323,15 +323,15 @@ mod tests {
let square = Square::E4 as usize;
let white_attacks = attacks[Color::White as usize][square];
- print(white_attacks, "Pawn e4");
+ white_attacks.print("Pawn e4");
assert_eq!(white_attacks, Square::D5.to_bitboard() | Square::F5.to_bitboard());
assert_eq!(attacks[Color::White as usize][Square::H4 as usize], Square::G5.to_bitboard());
assert_eq!(attacks[Color::White as usize][Square::A4 as usize], Square::B5.to_bitboard());
- assert_eq!(pop_count(attacks[Color::White as usize][Square::E8 as usize]), 0);
- assert_eq!(pop_count(attacks[Color::Black as usize][Square::E1 as usize]), 0);
+ assert_eq!(attacks[Color::White as usize][Square::E8 as usize].pop_count(), 0);
+ assert_eq!(attacks[Color::Black as usize][Square::E1 as usize].pop_count(), 0);
}
#[test]
@@ -353,7 +353,7 @@ mod tests {
let attacks = Attacks::precompute_knight_attacks();
let e4_attacks = attacks[Square::E4 as usize];
- print(e4_attacks, "Knight e4");
+ e4_attacks.print("Knight e4");
assert_ne!(e4_attacks & Square::G5.to_bitboard(), 0);
assert_ne!(e4_attacks & Square::G3.to_bitboard(), 0);
@@ -368,27 +368,27 @@ mod tests {
assert_eq!(e4_attacks & Square::D4.to_bitboard(), 0);
assert_eq!(e4_attacks & Square::A1.to_bitboard(), 0);
- assert_eq!(pop_count(attacks[Square::G1 as usize]), 3);
- assert_eq!(pop_count(attacks[Square::H8 as usize]), 2);
+ assert_eq!(attacks[Square::G1 as usize].pop_count(), 3);
+ assert_eq!(attacks[Square::H8 as usize].pop_count(), 2);
}
#[test]
fn king_attacks() {
let attacks = Attacks::precompute_king_attacks();
- print(attacks[Square::E4 as usize], "King e4");
+ attacks[Square::E4 as usize].print("King e4");
- assert_eq!(pop_count(attacks[Square::E4 as usize]), 8);
+ assert_eq!(attacks[Square::E4 as usize].pop_count(), 8);
- assert_eq!(pop_count(attacks[Square::A1 as usize]), 3);
- assert_eq!(pop_count(attacks[Square::A8 as usize]), 3);
- assert_eq!(pop_count(attacks[Square::H1 as usize]), 3);
- assert_eq!(pop_count(attacks[Square::H8 as usize]), 3);
+ assert_eq!(attacks[Square::A1 as usize].pop_count(), 3);
+ assert_eq!(attacks[Square::A8 as usize].pop_count(), 3);
+ assert_eq!(attacks[Square::H1 as usize].pop_count(), 3);
+ assert_eq!(attacks[Square::H8 as usize].pop_count(), 3);
- assert_eq!(pop_count(attacks[Square::E1 as usize]), 5);
- 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);
+ assert_eq!(attacks[Square::E1 as usize].pop_count(), 5);
+ assert_eq!(attacks[Square::E8 as usize].pop_count(), 5);
+ assert_eq!(attacks[Square::A4 as usize].pop_count(), 5);
+ assert_eq!(attacks[Square::H4 as usize].pop_count(), 5);
}
#[test]
@@ -421,7 +421,7 @@ mod tests {
attacks[5][square] |
attacks[6][square] |
attacks[7][square];
- print(bitboard, "Rays from e4");
+ bitboard.print("Rays from e4");
}
#[test]
@@ -430,8 +430,8 @@ mod tests {
let square = Square::E4;
let bb = attacks.bishop(DEFAULT_OCCUPANCY, square);
- print(DEFAULT_OCCUPANCY, "Occupancy");
- print(bb, "Bishop e4");
+ DEFAULT_OCCUPANCY.print("Occupancy");
+ bb.print("Bishop e4");
assert_ne!(bb & Square::C2.to_bitboard(), 0);
assert_eq!(bb & Square::B1.to_bitboard(), 0);
@@ -454,8 +454,8 @@ mod tests {
Square::F3.to_bitboard();
let bb = attacks.rook(occupancy, square);
- print(occupancy, "Occupancy");
- print(bb, "Rook e4");
+ occupancy.print("Occupancy");
+ bb.print("Rook e4");
assert_ne!(bb & Square::E8.to_bitboard(), 0);
assert_ne!(bb & Square::E7.to_bitboard(), 0);
@@ -474,7 +474,7 @@ mod tests {
let attacks = Attacks::new();
let square = Square::E4;
let bb = attacks.queen(DEFAULT_OCCUPANCY, square);
- print(DEFAULT_OCCUPANCY, "Occupancy");
- print(bb, "Queen e4");
+ DEFAULT_OCCUPANCY.print("Occupancy");
+ bb.print("Queen e4");
}
}