dedup code in Board::what_if
This commit is contained in:
parent
876d829e5e
commit
fef4f64ecd
@ -234,18 +234,13 @@ impl Board {
|
||||
/// Return a modified [`Board`] with the piece placed at a position
|
||||
/// Returns None if the move was invalid
|
||||
pub fn what_if(&self, i: usize, j: usize, piece: Piece) -> Option<Self> {
|
||||
// extract check here to avoid copy
|
||||
if self.get(i, j).is_some() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut self_copy = *self;
|
||||
self_copy.place_unchecked(i, j, piece);
|
||||
let how_many_prop = self_copy.propegate_from(i, j);
|
||||
if how_many_prop == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(self_copy)
|
||||
self_copy.place(i, j, piece).ok().map(|_| self_copy)
|
||||
}
|
||||
|
||||
/// Returns a bool which represents whether or not a move would propegate and be valid
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user