I want to modify Game of Life code so that the lattice can be seeded with one or two new life forms like:
glider[x_, y_] := {{x, y}, {x+1, y}, {x+2, y}, {x+2, y+1}, {x+1, y+2}}
snake[x_, y_] := {{x, y}, {x, y+1}, {x+1, y}, {x+2, y+1}, {x+3, y+1}, {x+3, y}}
I don't know how to modify my code to put above code! I'd be grateful if you could help.
Here is my code:
Life[n_, t_] :=
Module[{initConfig, Moore, update, LiveConfigs, DieConfigs},
initConfig = Table[Random[Integer], {n}, {n}];
LiveConfigs =
Join[Map[Join[{0}, #] &, Permutations[{1, 1, 1, 0, 0, 0, 0, 0}]],
Map[Join[{1}, #] &, Permutations[{1, 1, 1, 0, 0, 0, 0, 0}]],
Map[Join[{1}, #] &, Permutations[{1, 1, 0, 0, 0, 0, 0, 0}]]];
DieConfigs =
Complement[Flatten[Map[Permutations,
Map[Join[Table[1, {#}], Table[0, {(9 - #)}]] &, Range[0, 9]]], 1], LiveConfigs];
Apply[(update[##] = 1) &, LiveConfigs, 1];
Apply[(update[##] = 0) &, DieConfigs, 1];
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];
FixedPointList[Moore[update, #] &, initConfig, t]]