Added generation count to time and cell states.
[cellular-automata.git] / 001 / src / life_cell.erl
index 227f673..3f4669d 100644 (file)
@@ -1,4 +1,4 @@
--module(cell).
+-module(life_cell).
 -behaviour(gen_server).
 
 
@@ -22,6 +22,7 @@
                ,live_neighbors  :: integer()
                ,num_neighbors   :: integer()
                ,replies_pending :: integer()
+               ,generation      :: integer()
                }).
 
 
@@ -64,13 +65,13 @@ handle_call(_Msg, _From, State) ->
     {reply, ok, State}.
 
 
-handle_cast(tick,
+handle_cast({tick, Generation},
     #state{name=Name
           ,neighbors=Neighbors
           ,num_neighbors=NumNeighbors
           }=State) ->
     ok = cast_all(Neighbors, {request_state, Name}),
-    {noreply, State#state{replies_pending=NumNeighbors}};
+    {noreply, State#state{replies_pending=NumNeighbors, generation=Generation}};
 
 
 handle_cast({request_state, Requester}, State) ->
@@ -95,7 +96,7 @@ handle_cast({response_state, NeighborState},
     case NewPending of
         0 ->
             NewCellState = new_state(CellState, NewLiveNeighbors),
-            ok = time:tock(ID, NewCellState),
+            ok = life_time:tock(ID, NewCellState),
 
             {noreply, NewState#state{live_neighbors=0
                                     ,cell_state=NewCellState
This page took 0.026964 seconds and 4 git commands to generate.