showSites[sites_, opts___] :=
ArrayPlot[sites, opts, Mesh -> True, PixelConstrained -> 4]
makeConfiguration[n_, form_] := Module[{config, sites},
config = ConstantArray[0, {n, n}];
sites = form[Floor[n/2] + 1, Floor[n/2] + 1];
sites = {#[[2]], #[[1]]} & /@ sites;
Reverse[ReplacePart[config, 1, sites]]]
進化ルール
lifeGameSteps[board_, steps_ : 10] := With[{
rule = {
{{nw_, n_, ne_}, {w_, c_, e_}, {sw_, s_, se_}} :>
Which[
Plus[nw, n, ne, w, e, sw, s, se] == 3, 1,
c == 1 && Plus[nw, n, ne, w, e, sw, s, se] == 2, 1,
True, 0]},
init = board,
step = steps},
CellularAutomaton[rule, init, step]]
例 beehive
beehive[x_, y_] :=
{{x, y - 2}, {x, y - 1}, {x, y}, {x, y + 1}, {x, y + 2}};
config = makeConfiguration[21, beehive];
showSites[config]
showSites /@ lifeGameSteps[config]
例 glider
glider[x_, y_] :=
{{x, y}, {x + 1, y}, {x + 2, y}, {x + 2, y + 1}, {x + 1,
y + 2}};
config = makeConfiguration[21, glider];
showSites[config]
showSites /@ lifeGameSteps[config, 20]