fn advance(&mut self) {
        // Declare counter variables for the number of alive and dead cells
        let mut alive: u32 = 0;
        let mut dead: u32 = 0;

        // Check if the cell grid exists
        if self.grid.vector.is_some() {
            // Create a clone of the cell grid
            let mut newgrid = self.grid.vector.clone().unwrap();

            // Iterate over the grid
            for (x, y, cell) in self.grid.clone() {

                // Check the vicinity of the cell
                let cell = match (cell, self.scan_vicinity(x, y)) {
                    // If a cell is alive, and there are either too many live  
                    // neighbors or not enough live neighbors, kill it.
                    (BinaryCell::Active, n) if n < 2 || n > 3 => BinaryCell::Passive,

                    // If a cell is alive and has either 2 
                    // or 3 live neighbors, keep it alive
                    (BinaryCell::Active, n) if n == 3 || n == 2 => BinaryCell::Active,

                    // If a cell is dead and has exactly 3 live neighbors, revive it
                    (BinaryCell::Passive, 3) => BinaryCell::Active,

                    // Otherwise, keep the cell state
                    (c, _) => c,
                };

                // Add the new cell to the new grid
                newgrid[x][y] = cell.clone();

                // Increment the alive or dead counter
                match cell {
                    BinaryCell::Passive => dead += 1,
                    BinaryCell::Active => alive += 1
                }
            }

            // Assign the new grid to the grid struct
            self.grid.setgrid(newgrid);
        }

        // Update the alive and dead cell value in the grid struct
        self.alive = alive;
        self.dead = dead;
        // Increment the generation value in the grid struct
        self.generation += 1;
    }
/// A method that advances the game of life to the next generation.
A method that advances the game of life to the next generation.
A method that advances the game of life to the next generation .
fn advance(&mut self) {
        // Declare counter variables for the number of alive and dead cells
        let mut alive: u32 = 0;
        let mut dead: u32 = 0;
        // Check if the cell grid exists
        if self.grid.vector.is_some() {
            // Create a clone of the cell grid
            let mut newgrid = self.grid.vector.clone().unwrap();
            // Iterate over the grid
            for (x, y, cell) in self.grid.clone() {
                // Check the vicinity of the cell
                let cell = match (cell, self.scan_vicinity(x, y)) {
                    // If a cell is alive, and there are either too many live  
                    // neighbors or not enough live neighbors, kill it.
                    (BinaryCell::Active, n) if n < 2 || n > 3 => BinaryCell::Passive,
                    // If a cell is alive and has either 2 
                    // or 3 live neighbors, keep it alive
                    (BinaryCell::Active, n) if n == 3 || n == 2 => BinaryCell::Active,
                    // If a cell is dead and has exactly 3 live neighbors, revive it
                    (BinaryCell::Passive, 3) => BinaryCell::Active,
                    // Otherwise, keep the cell state
                    (c, _) => c,
                };
                // Add the new cell to the new grid
                newgrid[x][y] = cell.clone();
                // Increment the alive or dead counter
                match cell {
                    BinaryCell::Passive => dead += 1,
                    BinaryCell::Active => alive += 1
                }
            }
            // Assign the new grid to the grid struct
            self.grid.setgrid(newgrid);
        }
        // Update the alive and dead cell value in the grid struct
        self.alive = alive;
        self.dead = dead;
        // Increment the generation value in the grid struct
        self.generation += 1;
    }
fn advance ( & mut self ) { // Declare counter variables for the number of alive and dead cells let mut alive : u32 = 0 ; let mut dead : u32 = 0 ; // Check if the cell grid exists if self . grid . vector . is_some ( ) { // Create a clone of the cell grid let mut newgrid = self . grid . vector . clone ( ) . unwrap ( ) ; // Iterate over the grid for ( x , y , cell ) in self . grid . clone ( ) { // Check the vicinity of the cell let cell = match ( cell , self . scan_vicinity ( x , y ) ) { // If a cell is alive, and there are either too many live   // neighbors or not enough live neighbors, kill it. ( BinaryCell :: Active , n ) if n < 2 || n > 3 => BinaryCell :: Passive , // If a cell is alive and has either 2  // or 3 live neighbors, keep it alive ( BinaryCell :: Active , n ) if n == 3 || n == 2 => BinaryCell :: Active , // If a cell is dead and has exactly 3 live neighbors, revive it ( BinaryCell :: Passive , 3 ) => BinaryCell :: Active , // Otherwise, keep the cell state ( c , _ ) => c , } ; // Add the new cell to the new grid newgrid [ x ] [ y ] = cell . clone ( ) ; // Increment the alive or dead counter match cell { BinaryCell :: Passive => dead += 1 , BinaryCell :: Active => alive += 1 } } // Assign the new grid to the grid struct self . grid . setgrid ( newgrid ) ; } // Update the alive and dead cell value in the grid struct self . alive = alive ; self . dead = dead ; // Increment the generation value in the grid struct self . generation += 1 ; }
A method that advances the game of life to the next generation.
A method that advances the game of life to the next generation .
&mut self
&mut self