start paused and randomize arg
1 files changed, 15 insertions(+), 5 deletions(-)

M src/main.rs
M src/main.rs +15 -5
@@ 11,6 11,8 @@ extern crate getopts;
 use ncurses::*;
 
 fn main() {
+    const START_PAUSED: bool = true;
+
     const BG_COLORS: i16 = 0;
     const CURSOR_COLORS: i16 = 1;
 

          
@@ 18,7 20,7 @@ fn main() {
         initscr();
         cbreak();
         noecho();
-        nodelay(stdscr, true);
+        nodelay(stdscr, !START_PAUSED);
         keypad(stdscr, true);
         curs_set(CURSOR_VISIBILITY::CURSOR_INVISIBLE);
         start_color();

          
@@ 42,6 44,7 @@ fn main() {
     const ARG_DEAD: &'static str = "dead";
     const ARG_ALIVE: &'static str = "alive";
     const ARG_BORDER: &'static str = "border";
+    const ARG_RAND: &'static str = "randomize";
 
     let mut options = getopts::Options::new();
     options.optflag("h", ARG_HELP, "display help and exit");

          
@@ 51,6 54,7 @@ fn main() {
     options.optopt("d", ARG_DEAD, "the character to display for dead cells", "CHAR");
     options.optopt("a", ARG_ALIVE, "the character to display for living cells", "CHAR");
     options.optopt("b", ARG_BORDER, "Draw a border around the grid. Valid TYPEs are: blank, single (default), double, strong, thin, thick, solid", "TYPE");
+    options.optopt("x", ARG_RAND, "initialize the grid randomly with CHANCE for life in each cell ([0..1], default 0.5)", "CHANCE");
 
     let print_help = |short: bool| {
         const TITLE: &'static str = "cursedlife\nCopyright 2015 Robin Stumm\nhttp://dermetfan.net";

          
@@ 160,15 164,21 @@ fn main() {
     };
 
     let mut cells = vec![vec![false; cols]; rows];
-    for row in &mut cells[..] {
-        for col in &mut row[..] {
-            *col = rand::random::<bool>();
+    if matches.opt_present(ARG_RAND) {
+        let chance = match matches.opt_str(ARG_RAND) {
+            Some(chance) => chance.parse::<f32>().unwrap_or(0f32),
+            None => 0.5f32
+        };
+        for row in &mut cells[..] {
+            for col in &mut row[..] {
+                *col = rand::random::<f32>() < chance;
+            }
         }
     }
     let mut game = Game { cells: cells, dead: dead, alive: alive, border: border, color_pair: BG_COLORS, window: newwin(rows as i32, cols as i32, maxy / 2 - rows as i32 / 2, maxx / 2 - cols as i32 / 2) };
     let mut cursor = Cursor { y: 0, x: 0, color_pair: CURSOR_COLORS };
 
-    let mut paused = false;
+    let mut paused = START_PAUSED;
     'game_loop: loop {
         let before_render = time::precise_time_s();