Code: Select all
if cellstate 0 has 3 neighbors of cellstate 1, change to cellstate 2
else stay at cellstate 0
end
if cellstate 1 has 0 neighbors of cellstate 1, change to cellstate 2
elseif cellstate 1 has 1 neighbor of cellstate 1, change to cellstate 2
elseif cellstate 1 has 2 neighbors of cellstate 1, change to cellstate 2
elseif cellstate 1 has 3 neighbors of cellstate 1, change to cellstate 2
elseif cellstate 1 has 4 neighbors of cellstate 1, change to cellstate 2
elseif cellstate 1 has 5 neighbors of cellstate 1, change to cellstate 2
elseif cellstate 1 has 6 neighbors of cellstate 1, change to cellstate 2
elseif cellstate 1 has 7 neighbors of cellstate 1, change to cellstate 2
elseif cellstate 1 has 8 neighbors of cellstate 1, change to cellstate 2
else change to cellstate 0
end
(a.k.a. cellstate 1 changes to cellstate 2 no matter how many neighbors it has)
if cellstate 2 has 3 neighbors of cellstate 2, change to cellstate 1
elseif cellstate 2 has 2 neighbors of cellstate 2, change to cellstate 1
else change to cellstate 0
end
(cellstate 0 only counts cellstate 1 neighbors, and cellstate 2 only counts cellstate 2 neighbors)