pub fn tick(&self) -> Self {
        let mut new = self.clone();
        for index in &self.living {
            let neighbors = self.living_neighbors(*index);
            if neighbors < 2 || neighbors > 3 {
                new.kill(*index);
            }
        }
        // Dead cells can only have three living neighbors if they have at least one living
        // neighbor.
        for index in self.living
            .iter()
            .flat_map(|index| index.neighbors_vec().into_iter())
            .filter(|n| !self.is_living(n))
        {
            if self.living_neighbors(index) == 3 {
                new.unkill(index);
            }
        }
        new
    }
/// Runs the next tick of the simulation, returning a copy of the grid with updated state.
///
/// Looking at this pseudo-mathematically, this applies the next iteration of the *Life* function.
///
/// ### Rules
/// On each tick:
/// 1) Living cells with fewer than two living neighbors die.
/// 2) Living cells with two or three living neighbors live on.
/// 3) Living cells with more than three living neighbors die.
/// 4) Dead cells with exactly three living neighbors become living cells.
Runs the next tick of the simulation, returning a copy of the grid with updated state.
Looking at this pseudo-mathematically, this applies the next iteration of the *Life* function.
Runs the next tick of the simulation returning a copy of the grid with updated state . Looking at this pseudo - mathematically this applies the next iteration of the * Life * function .
pub fn tick(&self) -> Self {
        let mut new = self.clone();
        for index in &self.living {
            let neighbors = self.living_neighbors(*index);
            if neighbors < 2 || neighbors > 3 {
                new.kill(*index);
            }
        }
        // Dead cells can only have three living neighbors if they have at least one living
        // neighbor.
        for index in self.living
            .iter()
            .flat_map(|index| index.neighbors_vec().into_iter())
            .filter(|n| !self.is_living(n))
        {
            if self.living_neighbors(index) == 3 {
                new.unkill(index);
            }
        }
        new
    }
pub fn tick ( & self ) -> Self { let mut new = self . clone ( ) ; for index in & self . living { let neighbors = self . living_neighbors ( * index ) ; if neighbors < 2 || neighbors > 3 { new . kill ( * index ) ; } } // Dead cells can only have three living neighbors if they have at least one living // neighbor. for index in self . living . iter ( ) . flat_map ( | index | index . neighbors_vec ( ) . into_iter ( ) ) . filter ( | n | ! self . is_living ( n ) ) { if self . living_neighbors ( index ) == 3 { new . unkill ( index ) ; } } new }
Runs the next tick of the simulation, returning a copy of the grid with updated state.
Runs the next tick of the simulation returning a copy of the grid with updated state .
&self
&self
rules
On each tick:
1) Living cells with fewer than two living neighbors die.
2) Living cells with two or three living neighbors live on.
3) Living cells with more than three living neighbors die.
4) Dead cells with exactly three living neighbors become living cells.
On each tick : 1 ) Living cells with fewer than two living neighbors die . 2 ) Living cells with two or three living neighbors live on . 3 ) Living cells with more than three living neighbors die . 4 ) Dead cells with exactly three living neighbors become living cells .