From 69ad75816b3af383567130aa864da83b66cf763c Mon Sep 17 00:00:00 2001 From: fabolous005 Date: Thu, 25 Apr 2024 22:37:59 +0200 Subject: [PATCH] unfinished threatened_by function --- src/chess/board.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/chess/board.rs b/src/chess/board.rs index 8a4835b..282a7d2 100644 --- a/src/chess/board.rs +++ b/src/chess/board.rs @@ -340,6 +340,7 @@ impl Board { false } + // TODO: fix this pub fn threatened_by(&self, square: Square) -> Vec { let mut changes; let to_move = self.whites_turn; @@ -351,10 +352,21 @@ impl Board { let mut multiplier = 1; loop { - multiplier += 1; if square.x() as i8 + change.ref_x() * multiplier < 0 || square.x() as i8 + change.ref_x() * multiplier > 7 || square.y() as i8 + change.ref_y() * multiplier < 0 || square.y() as i8 + change.ref_y() * multiplier > 7 || - self.used(Square::new((square.x() as i8 + change.ref_x() * multiplier) as u8, (square.y() as i8 + change.ref_y() * multiplier) as u8)) { + { + multiplier >= 2 && + !self.used(Square::new((square.x() as i8 + change.ref_x() * multiplier) as u8, (square.y() as i8 + change.ref_y() * multiplier) as u8)) + } + { + + trace!( + "{:?}:{:?}x{:?} => {:?}", + {square.x() as i8 + change.ref_x() * multiplier}, + {square.y() as i8 + change.ref_y() * multiplier}, + multiplier, + variant.as_piece_variant() + ); break; } @@ -370,6 +382,7 @@ impl Board { if !variant.iterable() { break; } + multiplier += 1; } } }