homework is completed
This commit is contained in:
1 parent
6ffbfbb7bf
commit
f235fdcea6
3 files changed
+68
-20
No files matched your search
+56
-14
@@ -4,22 +4,63 @@ mod render;
|
||||
|
||||
use grid::*;
|
||||
use input::*;
|
||||
use rand::Rng;
|
||||
use render::*;
|
||||
//use std::clone;
|
||||
use std::{clone, sync::atomic::AtomicI32};
|
||||
|
||||
fn step(g: &mut Grid, rez: &(usize, usize)) {
|
||||
let mut rng = rand::thread_rng();
|
||||
let a = g.clone();
|
||||
for i in 0..rez.0 as i32 {
|
||||
for j in 0..(rez.1 - 1) as i32 {
|
||||
if !a.who_in(&(i as usize, (j + 1) as usize)) {
|
||||
g.push_in(false, &(i as usize, j as usize));
|
||||
g.push_in(true, &(i as usize, (j + 1) as usize));
|
||||
} else if !a.who_in(&((i + 1) as usize, (j + 1) as usize)) && i < rez.1 as i32 {
|
||||
g.push_in(false, &(i as usize, j as usize));
|
||||
g.push_in(true, &((i + 1) as usize, (j + 1) as usize));
|
||||
} else if !a.who_in(&((i - 1) as usize, (j + 1) as usize)) && i > 0 {
|
||||
g.push_in(false, &(i as usize, j as usize));
|
||||
g.push_in(true, &((i - 1) as usize, (j + 1) as usize));
|
||||
for i in 0..rez.0 {
|
||||
for j in 0..(rez.1 - 1) {
|
||||
if let Some(k) = a.who_in(&(i, j)) {
|
||||
match k {
|
||||
true => {
|
||||
let v = rng.gen_range(0..=3);
|
||||
match v {
|
||||
0 => {
|
||||
if let Some(k) = a.who_in(&(i, j + 1)) {
|
||||
match k {
|
||||
false => {
|
||||
g.push_in(false, &(i, j));
|
||||
g.push_in(true, &(i, j + 1));
|
||||
}
|
||||
true => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1 => {
|
||||
if (i + 1) < rez.0 {
|
||||
if let Some(k) = a.who_in(&(i + 1, j + 1)) {
|
||||
match k {
|
||||
false => {
|
||||
g.push_in(false, &(i, j));
|
||||
g.push_in(true, &(i + 1, j + 1));
|
||||
}
|
||||
true => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3 => {
|
||||
if i != 0 {
|
||||
if let Some(k) = a.who_in(&(i - 1, j + 1)) {
|
||||
match k {
|
||||
false => {
|
||||
g.push_in(false, &(i, j));
|
||||
g.push_in(true, &(i - 1, j + 1));
|
||||
}
|
||||
true => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
false => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,10 +79,11 @@ fn main() {
|
||||
let rez: (usize, usize) = (40, 80);
|
||||
_ = r.resize(&rez);
|
||||
let mut space = Grid::init(&rez);
|
||||
space.rand();
|
||||
//space.rand();
|
||||
loop {
|
||||
_ = r.frame(&space);
|
||||
step(&mut space, &rez);
|
||||
space.push_in(true, &(rez.0 / 2, 0));
|
||||
match it {
|
||||
InputType::comand => {
|
||||
_ = r.print("print comand:");
|
||||
|
||||
Reference in new issue
Block a user