I'm also trying to model the Game of Life.
I've some problems to create a usefull pattern.
Some ideas:
-Use of matrixes
-to create squares and put them in lines and rows
Has someone some other ideas?
thx
I'm trying to model Conway's Game of Life and here's my code:
> f := proc (a, b, c, d, e, f, g, h)
local alivecount;
alivecount := b+c+d+e+f+g+h;
if a = 1 and alivecount < 2 then a := 0
elif a = 1 and 3 < alivecount then a := 1
elif a = 0 and alivecount = 3 then a := 1
end if;
end proc;
> run2dca := proc (n::integer, f:: procedure, S0:: (list(list(numeric))), m::integer) local S, x, y, q, i, j;
S := [S0];
x := Array(0 .. n-1, 0 .. n-1, S0);
y := Array(0 .. n-1, 0 .. n-1);
for q to m do
for i from 0 to n-1 do
for j from 0 to n-1 do
y[i][j] = f(x[i][j], x[i+1 mod n)][j], x[i-1 mod n)][j], x[i][j+1 mod n)], x[i][j-1 mod n], x[i+1 mod n)][j+1 mod n)], x[i+1 mod n)][j-1 mod n)], x[i-1 mod n)][j+1 mod n)], x[i-1 mod n)][j-1 mod n)])
end do;
end do;
S := [op(S), convert(y, list)];
x, y := y, x
end do;
S
end proc;
n:= number of rows/columns of the nxn list
f:= update function
S0 := 2 dimensional nxn list
m := number of iterations
Yet when I try and run my code:
> BLOCK := [[1,1],[1,1]];
> run2dca(2,f, BLOCK, 5);
Error, (in run2dca) bad index into Array
I get the above error, and I have no idea what it means. Any help would be appreciated
EDIT: I've narrowed down the error to this line of code, x := Array(0 .. n-1, 0 .. n-1, S0); I have no idea what is wrong thogh