@@ -15,19 +15,24 @@ impl MineField {
1515 }
1616
1717 pub fn annotate ( & mut self ) {
18- self . enumerate_positions ( | col, row| {
18+ for ( col, row) in self . enumerate_positions ( ) {
1919 if self . is_mine ( col, row) == 1 {
20- return ;
20+ continue ;
2121 }
2222 let mines_around = self . compute_mines_around ( col, row) ;
23+ if mines_around == 0 {
24+ continue ;
25+ }
2326 match (
24- self . grid . get_mut ( col) . and_then ( |cell_row| cell_row. get_mut ( row) ) ,
27+ self . grid
28+ . get_mut ( col)
29+ . and_then ( |cell_row| cell_row. get_mut ( row) ) ,
2530 std:: char:: from_digit ( mines_around, 10 ) ,
2631 ) {
2732 ( Some ( cell) , Some ( digit) ) => * cell = digit,
2833 _ => ( ) ,
2934 }
30- } ) ;
35+ }
3136 }
3237
3338 pub fn get_annotated_rows ( self ) -> Vec < String > {
@@ -37,12 +42,14 @@ impl MineField {
3742 } )
3843 }
3944
40- fn enumerate_positions < F : FnMut ( usize , usize ) > ( & self , mut position : F ) {
45+ fn enumerate_positions ( & self ) -> Vec < ( usize , usize ) > {
46+ let mut positions = vec ! [ ] ;
4147 for column_idx in 0 ..self . grid . len ( ) {
4248 for row_idx in 0 ..self . grid [ column_idx] . len ( ) {
43- position ( column_idx, row_idx) ;
49+ positions . push ( ( column_idx, row_idx) ) ;
4450 }
4551 }
52+ positions
4653 }
4754
4855 fn compute_mines_around ( & self , column_idx : usize , row_idx : usize ) -> u32 {
0 commit comments