diff --git a/src/sweep.rs b/src/sweep.rs index 47ac5088..9206fc87 100644 --- a/src/sweep.rs +++ b/src/sweep.rs @@ -121,10 +121,13 @@ impl Board { } pub(crate) fn won(&self) -> bool { - let exposed_or_correctly_flagged = self.seen.len() + self.correctly_flagged_mines; + let nseen = self.seen.len(); + let exposed_or_correctly_flagged = nseen + self.correctly_flagged_mines; let ntiles = self.rows * self.columns; + assert!(exposed_or_correctly_flagged <= ntiles); - ntiles == exposed_or_correctly_flagged + + ntiles == exposed_or_correctly_flagged || (self.tiles.len() - nseen) == self.mines } fn index_from_coord(&self, (r, c): Coordinate) -> usize { @@ -181,6 +184,12 @@ impl Board { self.tiles.get_mut(index).ok_or(Error::GetTile((i, j))) } + pub(crate) fn flag_all(&mut self) { + for tile in self.tiles.iter_mut() { + tile.flagged = !tile.exposed && tile.mine; + } + } + pub(crate) fn flag(&mut self, i: usize, j: usize) -> Result { let nflagged = self.flagged_cells; let tile = self.tile(i, j)?; diff --git a/src/ui.rs b/src/ui.rs index 633f7b9b..07237608 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -61,7 +61,7 @@ fn align_strings_to_char(strings: &[&str], c: char) -> Vec { let max_rests = rests.iter().map(|&r| r.len()).max().unwrap(); firsts .into_iter() - .zip(rests.into_iter()) + .zip(rests) .map(|(first, rest)| format!("{first:>max_firsts$}{rest: