/// Open a cell, propagate if all neighboring cell is a free cell.
/// Opening an opened cell will propagate if flagged cell count is
/// equal to surrounding mine count.
///
/// Propagation is stopped when propagation reached a mine cell.
Open a cell, propagate if all neighboring cell is a free cell.
Opening an opened cell will propagate if flagged cell count is
equal to surrounding mine count.

Propagation is stopped when propagation reached a mine cell.
Open a cell propagate if all neighboring cell is a free cell . Opening an opened cell will propagate if flagged cell count is equal to surrounding mine count . Propagation is stopped when propagation reached a mine cell .
fn open(&mut self, i: usize, j: usize) -> &CellKind {
        if let BoardState::Uninitialized = self.state {
            self.initialize(i, j);
        }
        match self.cells[i][j].state {
            CellState::Closed => {
                self.cells[i][j].state = CellState::Opened;
                self.closed_cell_count -= 1;
                if let CellKind::Mine = self.cells[i][j].kind {
                    self.state = BoardState::Finished(BoardResult::Lost);
                }
                if let BoardState::Playing = self.state {
                    if self.count_adjacent_mines(i, j) == 0 {
                        for (i_nbr, j_nbr) in self.nbr_indices(i, j) {
                            self.open(i_nbr, j_nbr);
                        }
                    }
                }
            }
            CellState::Opened => {
                let mine_count = self.count_adjacent_mines(i, j);
                if mine_count > 0 && self.count_surrounding_flags(i, j) == mine_count {
                    for (i_nbr, j_nbr) in self.nbr_indices(i, j) {
                        if let CellState::Closed = self.cells[i_nbr][j_nbr].state {
                            self.open(i_nbr, j_nbr);
                        }
                    }
                }
            }
            _ => (),
        }
        if let BoardState::Playing = self.state {
            if self.mine_count == self.closed_cell_count {
                self.state = BoardState::Finished(BoardResult::Win);
            }
        }
        &self.cells[i][j].kind
    }
fn open ( & mut self , i : usize , j : usize ) -> & CellKind { if let BoardState :: Uninitialized = self . state { self . initialize ( i , j ) ; } match self . cells [ i ] [ j ] . state { CellState :: Closed => { self . cells [ i ] [ j ] . state = CellState :: Opened ; self . closed_cell_count -= 1 ; if let CellKind :: Mine = self . cells [ i ] [ j ] . kind { self . state = BoardState :: Finished ( BoardResult :: Lost ) ; } if let BoardState :: Playing = self . state { if self . count_adjacent_mines ( i , j ) == 0 { for ( i_nbr , j_nbr ) in self . nbr_indices ( i , j ) { self . open ( i_nbr , j_nbr ) ; } } } } CellState :: Opened => { let mine_count = self . count_adjacent_mines ( i , j ) ; if mine_count > 0 && self . count_surrounding_flags ( i , j ) == mine_count { for ( i_nbr , j_nbr ) in self . nbr_indices ( i , j ) { if let CellState :: Closed = self . cells [ i_nbr ] [ j_nbr ] . state { self . open ( i_nbr , j_nbr ) ; } } } } _ => ( ) , } if let BoardState :: Playing = self . state { if self . mine_count == self . closed_cell_count { self . state = BoardState :: Finished ( BoardResult :: Win ) ; } } & self . cells [ i ] [ j ] . kind }
Open a cell, propagate if all neighboring cell is a free cell.
Open a cell propagate if all neighboring cell is a free cell .
&mut self
i
usize
j
usize