fn scan_vicinity(&mut self, x: usize, y: usize) -> i32 {
        // Declare a counter
        let mut count = 0;
        
        // Check if the cell grid exists
        if let Some(grid) = &self.grid.vector {

            // Iterate over the cells in the vicinity of the cell at (x, y).
            // The [-1,0,1] vectors represent the vicinity offsets for the x and y axis each.
            for x_off in vec![-1, 0, 1] {
                for y_off in vec![-1, 0, 1] {
                    // Create the position of the cell in the 
                    // grid based on the vicinity offsets
                    let nx = x as i32 + x_off;
                    let ny = y as i32 + y_off;
                    
                    // Check if position is out of grid bounds (x axis)
                    if nx < 0 || nx >= grid.len() as i32 {
                        continue;
                    }

                    // Check if position is out of grid bounds (y axis)
                    if ny < 0 || ny >= grid[nx as usize].len() as i32 {
                        continue;
                    }

                    // Check if position points to the cell itself i.e (0,0) offsets
                    if nx == x as i32 && ny == y as i32 {
                        continue;
                    }

                    // Check if the cell if alive
                    match grid[nx as usize][ny as usize].clone() {
                        // Increment the counter if the cell is alive
                        BinaryCell::Active => count = count+1,
                        _ => continue,
                    }
                }
            }
        }

        // Return the counter value
        return count
    }
// A function that retrieves the number of alive cells in 
// the neighbouring vicity of a given cell (x, y)
A function that retrieves the number of alive cells in
the neighbouring vicity of a given cell (x, y)
A function that retrieves the number of alive cells in the neighbouring vicity of a given cell ( x y )
fn scan_vicinity(&mut self, x: usize, y: usize) -> i32 {
        // Declare a counter
        let mut count = 0;
        // Check if the cell grid exists
        if let Some(grid) = &self.grid.vector {
            // Iterate over the cells in the vicinity of the cell at (x, y).
            // The [-1,0,1] vectors represent the vicinity offsets for the x and y axis each.
            for x_off in vec![-1, 0, 1] {
                for y_off in vec![-1, 0, 1] {
                    // Create the position of the cell in the 
                    // grid based on the vicinity offsets
                    let nx = x as i32 + x_off;
                    let ny = y as i32 + y_off;
                    // Check if position is out of grid bounds (x axis)
                    if nx < 0 || nx >= grid.len() as i32 {
                        continue;
                    }
                    // Check if position is out of grid bounds (y axis)
                    if ny < 0 || ny >= grid[nx as usize].len() as i32 {
                        continue;
                    }
                    // Check if position points to the cell itself i.e (0,0) offsets
                    if nx == x as i32 && ny == y as i32 {
                        continue;
                    }
                    // Check if the cell if alive
                    match grid[nx as usize][ny as usize].clone() {
                        // Increment the counter if the cell is alive
                        BinaryCell::Active => count = count+1,
                        _ => continue,
                    }
                }
            }
        }
        // Return the counter value
        return count
    }
fn scan_vicinity ( & mut self , x : usize , y : usize ) -> i32 { // Declare a counter let mut count = 0 ; // Check if the cell grid exists if let Some ( grid ) = & self . grid . vector { // Iterate over the cells in the vicinity of the cell at (x, y). // The [-1,0,1] vectors represent the vicinity offsets for the x and y axis each. for x_off in vec ! [ 1 0 1 ] { for y_off in vec ! [ 1 0 1 ] { // Create the position of the cell in the  // grid based on the vicinity offsets let nx = x as i32 + x_off ; let ny = y as i32 + y_off ; // Check if position is out of grid bounds (x axis) if nx < 0 || nx >= grid . len ( ) as i32 { continue ; } // Check if position is out of grid bounds (y axis) if ny < 0 || ny >= grid [ nx as usize ] . len ( ) as i32 { continue ; } // Check if position points to the cell itself i.e (0,0) offsets if nx == x as i32 && ny == y as i32 { continue ; } // Check if the cell if alive match grid [ nx as usize ] [ ny as usize ] . clone ( ) { // Increment the counter if the cell is alive BinaryCell :: Active => count = count + 1 , _ => continue , } } } } // Return the counter value return count }
A function that retrieves the number of alive cells in
the neighbouring vicity of a given cell (x, y)
A function that retrieves the number of alive cells in the neighbouring vicity of a given cell ( x y )
&mut self
x
usize
y
usize
&mut self
x
usize
y
usize