Compare commits

...

3 commits

Author SHA1 Message Date
TheLie0
07f3f9f3bc
Made code more understandable.
Commented the get_movement_score function to be more understandable.
2019-03-08 12:53:12 +01:00
TheLie0
58b589af13
Slowed things down
made the program sleep for 70 ms after every draw so it is more aesthetic to look at.
2019-03-08 12:40:32 +01:00
TheLie0
4a4edfdf51
Merge pull request #1 from TheLie0/TheLie0-genesis
The lie0 genesis
2019-03-08 12:23:19 +01:00

View file

@ -2,18 +2,25 @@ extern crate console;
extern crate rand; extern crate rand;
use console::Term; use console::Term;
use std::thread::sleep;
use std::time::{Duration, Instant};
fn main() { fn main() {
let cutoff: f32 = 0.3; let cutoff: f32 = 0.3;
let frame_wait_time = Duration::from_millis(70);
let term = Term::stdout(); let term = Term::stdout();
let mut game = GameOfLife::new(255, 255, cutoff); let mut game = GameOfLife::new(255, 255, cutoff);
game.print_to_console(&term); game.print_to_console(&term);
let mut now = Instant::now();
sleep(frame_wait_time);
loop { loop {
game.update(); game.update();
if game.print_to_console(&term) == 0 { if game.print_to_console(&term) == 0 {
game = GameOfLife::new(255, 255, cutoff); game = GameOfLife::new(255, 255, cutoff);
} }
now = Instant::now();
sleep(frame_wait_time);
} }
} }
@ -112,6 +119,9 @@ fn random_one_or_zero_with_cutoff_point(cutoff: f32) -> u16 {
fn get_movement_score(cell: u16) -> usize { fn get_movement_score(cell: u16) -> usize {
if (cell & 0b0000000001111110) == ((cell & 0b0001111110000000) >> 6) { if (cell & 0b0000000001111110) == ((cell & 0b0001111110000000) >> 6) {
/*Checking the matching the last six states with the six before to find
out whether the cell is stagnant. The number six is chosen because it
encompasses all regular patterns of size 2, 3 and 6.*/
return 0; return 0;
} }
return 1; return 1;