From f7349482eecfd0f58668b13a8bdf147b0bcf877f Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Mon, 23 Jul 2012 04:25:40 -0400 Subject: [PATCH] Added generation count. --- 001/bin/life | 2 +- 001/src/time.erl | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/001/bin/life b/001/bin/life index 87edae8..cb64898 100755 --- a/001/bin/life +++ b/001/bin/life @@ -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}'` diff --git a/001/src/time.erl b/001/src/time.erl index d710926..fb947e3 100644 --- a/001/src/time.erl +++ b/001/src/time.erl @@ -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}} -- 2.20.1