Hi,
I’m trying to reproduce the game of life but I have several problems:
thread 'main' panicked at 'attempt to subtract with overflow'
with the line if grid[x1][y1] == 1 {

Is there a simple way to detect if a cell exist (something like isset() in PHP for example) ? I’d like to avoid the verification of x and y for every step.

How can I use
match
for the grid verification in order to avoid theif
?extern crate rand; use rand::Rng; fn main() { const MAX:usize = 10; let mut grid: [[i32; MAX]; MAX] = [[0; MAX]; MAX]; for row in grid.iter_mut() { for cell in row.iter_mut() { *cell = rand::thread_rng().gen_range(0,2); print!("{}",cell); } print!("\n"); } //println!("{:?}", grid) let mut alive: i32 = 0; for x in 0..9 { for y in 0..9 { if grid[x1][y1] == 1 { alive += 1; } //left if grid[x1][y] == 1 { alive += 1; } //topleft if grid[x1][y+1] == 1 { alive += 1; } //bottom if grid[x][y1] == 1 { alive += 1; } //right if grid[x][y+1] == 1 { alive += 1; } //bottomright if grid[x+1][y1] == 1 { alive += 1; } //right if grid[x+1][y] == 1 { alive += 1; } //topright if grid[x+1][y+1] == 1 { alive += 1; } //alive if alive == 3 && grid[x][y] == 0 { grid[x][y] = 1; } //alive if (alive == 3  alive == 2) && grid[x][y] == 1 { grid[x][y] = 1; } //dead else{ grid[x][y] = 0; } } } }