From 847cdaf46737d2b914971177a4afa05bbe13243b Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 2 Feb 2023 01:30:27 +0300 Subject: perf: improve is_square_attacked --- src/board/mod.rs | 18 +++++++++--------- 1 file 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 } } -- cgit v1.2.3