mirror of
https://gitlab1.ptb.de/waltem01/Matrix
synced 2024-11-08 22:43:50 +00:00
updating to next generation
This commit is contained in:
parent
ca4b04723f
commit
ae5a15a5e2
32
src/cell.rs
32
src/cell.rs
@ -1,8 +1,12 @@
|
|||||||
use crate::BRIGHTNESS;
|
use crate::BRIGHTNESS;
|
||||||
|
use crate::G;
|
||||||
use crate::HEIGHT;
|
use crate::HEIGHT;
|
||||||
|
use crate::K1;
|
||||||
|
use crate::K2;
|
||||||
use crate::Q;
|
use crate::Q;
|
||||||
use crate::WIDTH;
|
use crate::WIDTH;
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
pub struct Cell {
|
pub struct Cell {
|
||||||
pub x: u32,
|
pub x: u32,
|
||||||
pub y: u32,
|
pub y: u32,
|
||||||
@ -93,3 +97,31 @@ pub fn display_grid(grid: &Vec<Vec<Cell>>) {
|
|||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_grid(grid: &mut Vec<Vec<Cell>>) {
|
||||||
|
let mut new_gen = init_grid(Some(grid));
|
||||||
|
for j in 0..HEIGHT {
|
||||||
|
for i in 0..WIDTH {
|
||||||
|
let x = i as usize;
|
||||||
|
let y = j as usize;
|
||||||
|
|
||||||
|
let current = &grid[y][x];
|
||||||
|
let next = &mut new_gen[y][x];
|
||||||
|
|
||||||
|
if current.state == Q - 1 {
|
||||||
|
next.state = 0;
|
||||||
|
} else if current.state == 0 {
|
||||||
|
let (inf, ill) = current.neighbor_count(&grid, StateOp::Types);
|
||||||
|
next.state = inf / K1 + ill / K2;
|
||||||
|
} else {
|
||||||
|
let (sum, states) = current.neighbor_count(&grid, StateOp::States);
|
||||||
|
next.state = sum / (9 - states) + G;
|
||||||
|
}
|
||||||
|
|
||||||
|
if next.state >= Q {
|
||||||
|
next.state = Q - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*grid = new_gen;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user