fn initialize(&mut self, i: usize, j: usize) {
        self.cells[i][j].kind = CellKind::Free;
        for (i_nbr, j_nbr) in self.nbr_indices(i, j) {
            self.cells[i_nbr][j_nbr].kind = CellKind::Free;
        }
        let mut placed_mine = 0;
        let mut rng = rand::thread_rng();
        while placed_mine < self.mine_count {
            let i = rng.gen_range(0..self.height());
            let j = rng.gen_range(0..self.width());
            if let CellKind::Uninitialized = self.cells[i][j].kind {
                self.cells[i][j].kind = CellKind::Mine;
                placed_mine += 1;
            }
        }
        self.state = BoardState::Playing;
        self.cells.iter_mut().flatten().for_each(|cell| {
            if let CellKind::Uninitialized = cell.kind {
                cell.kind = CellKind::Free;
            }
        })
    }
/// Initially, the cells are all unitialized. After the first
/// Cell has been opened, the cell and all of its neighboring
/// cells are set as free cell.
Initially, the cells are all unitialized. After the first
Cell has been opened, the cell and all of its neighboring
cells are set as free cell.
Initially the cells are all unitialized . After the first Cell has been opened the cell and all of its neighboring cells are set as free cell .
fn initialize(&mut self, i: usize, j: usize) {
        self.cells[i][j].kind = CellKind::Free;
        for (i_nbr, j_nbr) in self.nbr_indices(i, j) {
            self.cells[i_nbr][j_nbr].kind = CellKind::Free;
        }
        let mut placed_mine = 0;
        let mut rng = rand::thread_rng();
        while placed_mine < self.mine_count {
            let i = rng.gen_range(0..self.height());
            let j = rng.gen_range(0..self.width());
            if let CellKind::Uninitialized = self.cells[i][j].kind {
                self.cells[i][j].kind = CellKind::Mine;
                placed_mine += 1;
            }
        }
        self.state = BoardState::Playing;
        self.cells.iter_mut().flatten().for_each(|cell| {
            if let CellKind::Uninitialized = cell.kind {
                cell.kind = CellKind::Free;
            }
        })
    }
fn initialize ( & mut self , i : usize , j : usize ) { self . cells [ i ] [ j ] . kind = CellKind :: Free ; for ( i_nbr , j_nbr ) in self . nbr_indices ( i , j ) { self . cells [ i_nbr ] [ j_nbr ] . kind = CellKind :: Free ; } let mut placed_mine = 0 ; let mut rng = rand :: thread_rng ( ) ; while placed_mine < self . mine_count { let i = rng . gen_range ( 0 .. self . height ( ) ) ; let j = rng . gen_range ( 0 .. self . width ( ) ) ; if let CellKind :: Uninitialized = self . cells [ i ] [ j ] . kind { self . cells [ i ] [ j ] . kind = CellKind :: Mine ; placed_mine += 1 ; } } self . state = BoardState :: Playing ; self . cells . iter_mut ( ) . flatten ( ) . for_each ( | cell | { if let CellKind :: Uninitialized = cell . kind { cell . kind = CellKind :: Free ; } } ) }
Initially, the cells are all unitialized.
Initially the cells are all unitialized .
&mut self
i
usize
j
usize
&mut self
i
usize
j
usize