aboutsummaryrefslogtreecommitdiff
path: root/src/board/mod.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-02-02 01:30:27 +0300
committereug-vs <eugene@eug-vs.xyz>2023-02-02 01:30:27 +0300
commit847cdaf46737d2b914971177a4afa05bbe13243b (patch)
tree2c28c6155fa3aa7fe0b1af3db4c25b2a26ed6528 /src/board/mod.rs
parent46abb37e60667445d10791553bdb307d52661180 (diff)
downloadchessnost-847cdaf46737d2b914971177a4afa05bbe13243b.tar.gz
perf: improve is_square_attacked
Diffstat (limited to 'src/board/mod.rs')
-rw-r--r--src/board/mod.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/board/mod.rs b/src/board/mod.rs
index 3f37d62..2bb1147 100644
--- a/src/board/mod.rs
+++ b/src/board/mod.rs
@@ -794,13 +794,8 @@ impl Board {
fn is_square_attacked(&self, square: Square, attacker_color: Color) -> bool {
for (piece_type, piece) in self.pieces_by_color(attacker_color).iter().enumerate() {
match PieceType::from(piece_type) {
- PieceType::Pawn => {
- if self.attacks.pawn[attacker_color.flip() as usize][square as usize] & piece > 0 {
- return true
- }
- }
- PieceType::King => {
- if self.attacks.king[square as usize] & piece > 0 {
+ PieceType::Queen => {
+ if self.attacks.queen(self.occupancy, square) & piece > 0 {
return true
}
}
@@ -819,8 +814,13 @@ impl Board {
return true
}
}
- PieceType::Queen => {
- if self.attacks.queen(self.occupancy, square) & piece > 0 {
+ PieceType::Pawn => {
+ if self.attacks.pawn[attacker_color.flip() as usize][square as usize] & piece > 0 {
+ return true
+ }
+ }
+ PieceType::King => {
+ if self.attacks.king[square as usize] & piece > 0 {
return true
}
}