optionally reuse old values

This commit is contained in:
Baipyrus 2024-05-07 11:35:31 +02:00
parent c9005a9150
commit ef52dcfd7d

View File

@ -9,15 +9,20 @@ pub struct Cell {
pub state: u32, pub state: u32,
} }
pub fn init_grid() -> Vec<Vec<Cell>> { pub fn init_grid(option: Option<&Vec<Vec<Cell>>>) -> Vec<Vec<Cell>> {
let mut grid: Vec<Vec<Cell>> = Vec::new(); let mut grid: Vec<Vec<Cell>> = Vec::new();
for j in 0..HEIGHT { for j in 0..HEIGHT {
let mut row: Vec<Cell> = Vec::new(); let mut row: Vec<Cell> = Vec::new();
for i in 0..WIDTH { for i in 0..WIDTH {
let mut value = rand::random::<u32>() % Q;
if let Some(g) = option {
value = g[j as usize][i as usize].state;
}
row.push(Cell { row.push(Cell {
x: i, x: i,
y: j, y: j,
state: 0, state: value,
}); });
} }
grid.push(row); grid.push(row);