home
/
code
/
cellular-automata.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added generation count to time and cell states.
[cellular-automata.git]
/
001
/
src
/
life_time.erl
diff --git
a/001/src/life_time.erl
b/001/src/life_time.erl
index
6f9d859
..
dfcec8a
100644
(file)
--- a/
001/src/life_time.erl
+++ b/
001/src/life_time.erl
@@
-30,7
+30,7
@@
,num_cells :: integer()
,state_pairs :: list(tuple(integer(), integer())) | []
,replies_pending :: integer()
,num_cells :: integer()
,state_pairs :: list(tuple(integer(), integer())) | []
,replies_pending :: integer()
- ,gen
_count = 0
:: integer()
+ ,gen
eration = 0
:: integer()
}).
}).
@@
-81,17
+81,19
@@
handle_cast(next_tick,
#state{cells=Cells
,num_cells=NumCells
,state_pairs=[]
#state{cells=Cells
,num_cells=NumCells
,state_pairs=[]
+ ,generation=Generation
}=State) ->
}=State) ->
- ok = cast_all(Cells, tick),
- {noreply, State#state{replies_pending=NumCells}};
+ NewGeneration = Generation + 1,
+ ok = cast_all(Cells, {tick, NewGeneration}),
+ {noreply, State#state{replies_pending=NumCells, generation=NewGeneration}};
handle_cast({tock, {ID, CellState}},
#state{x=X
,y=Y
,state_pairs=StatePairs
,replies_pending=RepliesPending
handle_cast({tock, {ID, CellState}},
#state{x=X
,y=Y
,state_pairs=StatePairs
,replies_pending=RepliesPending
- ,gen
_count=GenCount
+ ,gen
eration=Generation
,num_cells=NumCells
}=State) ->
,num_cells=NumCells
}=State) ->
@@
-101,7
+103,6
@@
handle_cast({tock, {ID, CellState}},
case NewRepliesPending of
0 ->
case NewRepliesPending of
0 ->
- NewGenCount = GenCount + 1,
SortedStatePairs = lists:sort(
fun({A, _}, {B, _}) -> A < B end,
NewStatePairs
SortedStatePairs = lists:sort(
fun({A, _}, {B, _}) -> A < B end,
NewStatePairs
@@
-109,8
+110,8
@@
handle_cast({tock, {ID, CellState}},
StateChars = [state_to_char(S) || {_, S} <- SortedStatePairs],
ok = io:format(
StateChars = [state_to_char(S) || {_, S} <- SortedStatePairs],
ok = io:format(
- "X: ~b Y: ~b CELLS: ~b GENERATION
S
: ~b~n",
- [X, Y, NumCells,
NewGenCount
]
+ "X: ~b Y: ~b CELLS: ~b GENERATION: ~b~n",
+ [X, Y, NumCells,
Generation
]
),
ok = do_print_bar(X),
),
ok = do_print_bar(X),
@@
-118,7
+119,7
@@
handle_cast({tock, {ID, CellState}},
ok = timer:sleep(?INTERVAL),
schedule_next_tick(),
ok = timer:sleep(?INTERVAL),
schedule_next_tick(),
- {noreply, NewState#state{state_pairs=[]
, gen_count=NewGenCount
}};
+ {noreply, NewState#state{state_pairs=[]}};
_N ->
{noreply, NewState#state{state_pairs=NewStatePairs}}
_N ->
{noreply, NewState#state{state_pairs=NewStatePairs}}
This page took
0.026776 seconds
and
4
git commands to generate.