X-Git-Url: https://git.xandkar.net/?p=cellular-automata.git;a=blobdiff_plain;f=003%2Fsrc%2Flife.erl;h=5f91d2681430aecd29ccc47b50f14eb1224dc9bd;hp=ebb1a2e71b45df7302c0347f23aa9c3352d4dace;hb=160a4566dcc36d03f6af95e7c588cc7453fdd905;hpb=6fc17e920136ef93fe8f4b2e65188ec7e7e882f0 diff --git a/003/src/life.erl b/003/src/life.erl index ebb1a2e..5f91d26 100644 --- a/003/src/life.erl +++ b/003/src/life.erl @@ -10,14 +10,14 @@ -define(INTERVAL, 100). --record(state, {x :: non_neg_integer() - ,y :: non_neg_integer() - ,n :: non_neg_integer() - ,bar :: string() - ,board=array:new() :: array() - ,gen_count :: non_neg_integer() - ,gen_duration :: non_neg_integer() - ,print_time :: non_neg_integer() +-record(state, {x :: non_neg_integer() + ,y :: non_neg_integer() + ,n :: pos_integer() + ,bar :: nonempty_string() + ,board :: array() + ,gen_count :: pos_integer() + ,gen_duration :: non_neg_integer() + ,print_time :: non_neg_integer() }). @@ -33,9 +33,9 @@ bang(Args) -> ,n = X * Y ,bar = [?CHAR_BAR || _ <- lists:seq(1, X)] ,board = Board - ,gen_count = 1 + ,gen_count = 1 % Consider inital state to be generation 1 ,gen_duration = Time - ,print_time = 0 + ,print_time = 0 % There was no print time yet }, life_loop(State). @@ -61,7 +61,12 @@ life_loop( end ), - {NewTime, NewBoard} = timer:tc(fun() -> next_generation(X, Y, Board) end), + {NewTime, NewBoard} = timer:tc( + fun() -> + next_generation(X, Y, Board) + end + ), + NewState = State#state{board = NewBoard ,gen_count = GenCount + 1 ,gen_duration = NewTime @@ -89,7 +94,7 @@ do_print_status(Bar, X, Y, N, GenCount, TimeMic, PrintTimeMic) -> do_print_board(Board) -> - CharLists = array:to_list( + RowStrings = array:to_list( array:map( fun(_, Row) -> array:to_list( @@ -106,10 +111,10 @@ do_print_board(Board) -> ), ok = lists:foreach( - fun(CharList) -> - ok = io:format("~s~n", [CharList]) + fun(RowString) -> + ok = io:format("~s~n", [RowString]) end, - CharLists + RowStrings ).