Board::what_if use Result
This commit is contained in:
parent
6f51c31752
commit
d7a94c2d57
@ -234,14 +234,14 @@ 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> {
|
||||
pub fn what_if(&self, i: usize, j: usize, piece: Piece) -> Result<Self, &'static str> {
|
||||
// extract check here to avoid copy
|
||||
if self.get(i, j).is_some() {
|
||||
return None;
|
||||
return Err("position is occupied");
|
||||
}
|
||||
|
||||
let mut self_copy = *self;
|
||||
self_copy.place(i, j, piece).ok().map(|_| self_copy)
|
||||
self_copy.place(i, j, piece).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