Added generation count.
authorSiraaj Khandkar <siraaj@khandkar.net>
Mon, 23 Jul 2012 08:25:40 +0000 (04:25 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Mon, 23 Jul 2012 08:25:40 +0000 (04:25 -0400)
001/bin/life
001/src/time.erl

index 87edae8..cb64898 100755 (executable)
@@ -1,7 +1,7 @@
 #! /bin/sh
 
 
-Y=`expr \`stty size | awk '{print $1}'\` - 3`
+Y=`expr \`stty size | awk '{print $1}'\` - 5`
 X=`stty size | awk '{print $2}'`
 
 
index d710926..fb947e3 100644 (file)
@@ -29,6 +29,7 @@
                ,num_cells       :: integer()
                ,state_pairs     :: list(tuple(integer(), integer())) | []
                ,replies_pending :: integer()
+               ,gen_count = 0   :: integer()
                }).
 
 
@@ -82,6 +83,7 @@ handle_cast({tock, {ID, CellState}},
     #state{x=X
           ,state_pairs=StatePairs
           ,replies_pending=RepliesPending
+          ,gen_count=GenCount
           }=State) ->
 
     NewStatePairs = [{ID, CellState} | StatePairs],
@@ -90,14 +92,17 @@ handle_cast({tock, {ID, CellState}},
 
     case NewRepliesPending of
         0 ->
+            NewGenCount = GenCount + 1,
             SortedStatePairs = lists:sort(NewStatePairs),
             StateChars = [state_to_char(S) || {_, S} <- SortedStatePairs],
             ok = do_print_bar(X),
+            ok = io:format("GENERATIONS: ~b~n", [NewGenCount]),
+            ok = do_print_bar(X),
             ok = do_print_state_chars(X, StateChars),
             ok = do_print_bar(X),
             ok = timer:sleep(?INTERVAL),
             cast(next_tick),
-            {noreply, NewState#state{state_pairs=[]}};
+            {noreply, NewState#state{state_pairs=[], gen_count=NewGenCount}};
 
         _N ->
             {noreply, NewState#state{state_pairs=NewStatePairs}}
This page took 0.025839 seconds and 4 git commands to generate.