# Specify rules for 2D cellular automaton?

If I want my rule to affect cells in this way:

• dead $$\to$$ dead $$\iff$$ Cell has $$n$$ living neighbours, $$n\in A$$
• dead $$\to$$ alive$$\iff$$ Cell has $$n$$ living neighbours, $$n\in B$$
• alive $$\to$$ dead $$\iff$$ Cell has $$n$$ living neighbours, $$n\in C$$
• alive $$\to$$ alive $$\iff$$ Cell has $$n$$ living neighbours, $$n\in D$$

(where neighborhood of a cell consists of all closest surrounding cells)

Then, how do I specify my rule?

ArrayPlot[Last[CellularAutomaton[rule, board, step]]]


For example, if $$A=C=\{0,2,4,6,8\}, B=D=\{1,3,5,7\}$$, and

board = Table[If[i == j == 20, 1, 0], {i, 1, 41}, {j, 1, 41}]


and step goes from $$0$$ to $$15$$, then we should have this replicator pattern: Which was taken from Terrific Toothpick Patterns - at 14:51

So how to convert given $$A,B,C,D$$ to a rule that gives, for example the pattern above?

The example where $$A = C$$ and $$B = D$$ can be achieved using GrowthSurvivalCases option of CellularAutomata (as of Mathematica 11.1, I believe):

init = CenterArray[{30, 30}];

res = CellularAutomaton[<|
"Dimension" -> 2,
"GrowthSurvivalCases" -> {
{1, 3, 5, 7},
{1, 3, 5, 7}
}|>, init, 15];

Partition[ArrayPlot /@ res, 3] // Grid The following code worked for me:

a = {0, 2, 4, 6, 8};
b = {1, 3, 5, 7};
c = {0, 2, 4, 6, 8};
d = {1, 3, 5, 7};
Manipulate[
Row[{cell3 = CellularAutomaton[{
Which[
MemberQ[a,
Mod[Total[# - #[[2, 2]], \[Infinity]], 2]] \[And] #[[2,
2]] == 0, 0,
MemberQ[b,
Mod[Total[# - #[[2, 2]], \[Infinity]], 2]] \[And] #[[2,
2]] == 0, 1,
MemberQ[c,
Mod[Total[# - #[[2, 2]], \[Infinity]], 2]] \[And] #[[2,
2]] == 1, 0,
MemberQ[d,
Mod[Total[# - #[[2, 2]], \[Infinity]], 2]] \[And] #[[2,
2]] == 1, 1
] &,
{}, {1, 1}}, {{{1}}, 0}, {{{i}}}],
ArrayPlot[cell3, ImageSize -> 300, Mesh -> True,
MeshStyle -> Red]}],
{i, 0, 10, 1}] It's a bit clumsy as this is my first time working with cellular automata but I think it works. I may not be understanding the math behind the automata correctly, but I'm not sure if the "GrowthSurvivalCases" option will get you exactly what you want if we have $$A \neq C$$ and $$B \neq D$$.

The documentation states:

With "GrowthSurvivalCases"->{{Subscript[g, 1],[Ellipsis]},{Subscript[s, 1],[Ellipsis]}}, a cell goes from value 0 to value 1 if it has Subscript[g, i] neighbors that are 1, maintains value 1 if it has Subscript[s, i] neighbors that are 1, and otherwise gets value 0.

In this case, the $$g_i$$ correspond to $$B$$ and the $$s_i$$ correspond to $$D$$, but regardless of whether a cell was previously dead or alive, it will be switched to dead if the number is not listed in $$B$$ or $$D$$, which is why I used the Which to test all 4 cases instead.