From ef52dcfd7df7b103cac2ec144c4419d6a2d8ce6c Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Tue, 7 May 2024 11:35:31 +0200 Subject: [PATCH] optionally reuse old values --- src/cell.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cell.rs b/src/cell.rs index 02fcf57..46fc530 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -9,15 +9,20 @@ pub struct Cell { pub state: u32, } -pub fn init_grid() -> Vec> { +pub fn init_grid(option: Option<&Vec>>) -> Vec> { let mut grid: Vec> = Vec::new(); for j in 0..HEIGHT { let mut row: Vec = Vec::new(); for i in 0..WIDTH { + let mut value = rand::random::() % Q; + if let Some(g) = option { + value = g[j as usize][i as usize].state; + } + row.push(Cell { x: i, y: j, - state: 0, + state: value, }); } grid.push(row);