In the book Modelling Cellular automata Simulations with mathematica , the author is using the following code to simulate cellular automata in a two dimensional lattice,
From the Moore Neighbourhood the update rule is
update[site, N, E, S, W, NE, SE, SW, NW]
where N =North, E= East , S=South, W=West, NE= North East, SE=South East, SW= South East, NW=North West. Those arguments represent the values of the nearest neigbours in the Moor Neighbourhood. To apply those rules it uses the code below,
Moore[func_, lat_]:= MapThread[func,Map[RotateRight[lat,#]&,
{{0,0},{1,0},{0,-1},{-1,0},{0,1},
{1,-1},{-1,-1},{-1,1},{1,1}}],2]
For a table like the following (page 144 from the book)
pasture= Table[Floor[Random[]+(preyDensity+predDensity)]*
Floor[1+Random[]+predDensity/(preyDensity+predDensity)],{n},{n}]/.
2:>{RND,Random[Integer, {1,3}],Random[Integer,{1,5}]}
RND:= Random[Integer, {1,4}]
he is using the following update rule
update[{_,0,0},_,_,_,_,_,_,_,_] := {RND, 3,5}
My question is: By using a four dimensional table like the following? Can I also apply the following update rule?
InitialMatrix[x_, y_, age_, disease_] :=
ReplacePart[
Table[3, {x}, {y}, {age}, {disease}], {{_, _, 1, _} ->
0, {_, _, 2, 1} ->
Floor[dogpopulation*0.2/cellsno], {_, _, 2, 3} ->
Floor[dogpopulation*0.05/cellsno], {_, _, 3, 1} ->
Floor[dogpopulation*0.58/cellsno], {_, _, 3, 3} ->
Floor[dogpopulation*0.15/cellsno]}] /.
3 :> If[RandomReal[] > 0.2, 0, RandomInteger[{1, 2}]];
update[{{x_,0,0},{y_,z_,w_},{a_,b_,c_}},_,_,_,_,_,_,_,_] :=
{{x-1,0,0},{y+z,0,w},{a,b,c}}
This is an example of how I think I can use my table to work with cellular automata. Can I do something like that? Or I am wrong?
Edit my table
By changing my table into the following code below can I use the update rule above?
MyMatrix[x_, y_, age_, disease_] :=
Table[0, {x}, {y}] /.
0 :> ReplacePart[
Table[3, {age}, {disease}], {{1, _} -> 0, {2, 1} ->
Floor[dogpopulation*0.2/cellsno], {2, 3} ->
Floor[dogpopulation*0.05/cellsno], {3, 1} ->
Floor[dogpopulation*0.58/cellsno], {3, 3} ->
Floor[dogpopulation*0.15/cellsno]}] /.
3 :> If[RandomReal[] > 0.2, 0, RandomInteger[{1, 2}]];