board: optimize propegate_from calls (+4.7% perf)
This commit is contained in:
parent
72dc7b9a48
commit
f84706ac40
@ -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<Self, &'static str> {
|
||||
@ -252,22 +247,17 @@ impl Board {
|
||||
return Err("position is occupied");
|
||||
}
|
||||
|
||||
if self.propegate_from(coord, piece) {
|
||||
self.place_unchecked(coord, piece);
|
||||
if !self.propegate_from(coord) {
|
||||
self.delete(coord);
|
||||
Err("move would not propegate")
|
||||
} else {
|
||||
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();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user