diff --git a/src/repr/board.rs b/src/repr/board.rs index f0c2f5b..7d06eb0 100644 --- a/src/repr/board.rs +++ b/src/repr/board.rs @@ -225,11 +225,6 @@ impl Board { get_board!(self, Piece::Black).set(coord, !is_white); } - const fn delete(&mut self, coord: CoordPair) { - get_board!(self, Piece::White).set(coord, false); - get_board!(self, Piece::Black).set(coord, false); - } - /// Return a modified [`Board`] with the piece placed at a position /// Returns None if the move was invalid pub fn what_if(&self, coord: CoordPair, piece: Piece) -> Result { @@ -252,22 +247,17 @@ impl Board { return Err("position is occupied"); } - self.place_unchecked(coord, piece); - if !self.propegate_from(coord) { - self.delete(coord); - Err("move would not propegate") - } else { + if self.propegate_from(coord, piece) { + self.place_unchecked(coord, piece); Ok(()) + } else { + Err("move would not propegate") } } /// Propegate the board and captures starting from a specific position /// returns true if flips occurred - fn propegate_from(&mut self, coord: CoordPair) -> bool { - let Some(starting_color) = self.get(coord) else { - return false; - }; - + fn propegate_from(&mut self, coord: CoordPair, starting_color: Piece) -> bool { let flip_mask = self.propegate_from_dry(coord, starting_color); let did_flip = !flip_mask.is_empty();