what_if: only return Some if how_many_prop is above 0

This commit is contained in:
Simon Gardling 2025-01-29 10:07:05 -05:00
parent 45e1a05839
commit 7aebdc3c78
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -70,12 +70,14 @@ impl Board {
}
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, how_many_prop))
}
pub fn place(&mut self, i: usize, j: usize, piece: Piece) -> Result<(), String> {
let what_if_result = self.what_if(i, j, piece);
if let Some(what_if_result) = what_if_result {
if let Some(what_if_result) = self.what_if(i, j, piece) {
if what_if_result.1 > 0 {
*self = what_if_result.0;
return Ok(());