Hello friends, thank you for helping me with this issue...
I want to reproduce the animations of the Conway´s game of life in Mathematica. You can find the description and the rules in Wikipedia (http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)
I first started defining a grid with dimensions II vs JJ, being these values predefined in the sheet. The initial values in the sheet, a[ i,j ], are defined also (a[ i,j ]=1 is a "live" cell, and a[ i,j ]=0 is a "dead" cell). The values of a outside the grid are defined as zero, as follows:
Table[a[0, j] = 0, {j, 0, JJ+1, 1}]
Table[a[i, 0] = 0, {i, 0, II+1, 1}]
Table[a[II + 1, j] = 0, {j, 0, JJ+1, 1}]
Table[a[i, JJ + 1] = 0, {i,0, II+1, 1}]
a[II + 1, JJ + 1] = 0
The following values of a, denoted as s, are defined according to the game´s rules, and depends of the value of the eight neighbours (remember a value of 1 for a live cell and 0 for a dead cell); that is, the value of s[ i,j ], depends of the eight-term sum:
sum = a[i - 1, j - 1] + a[i - 1, j] + a[i - 1, j + 1] + a[i, j + 1] + a[i + 1, j + 1] + a[i + 1, j] + a[i + 1, j - 1] + a[i, j - 1]
the value of s[ i,j ] is then:
s[i_, j_] := If[1 <= a[i, j] <= 1, Which[sum <= 1, s[i, j] = 0, 2 <= sum <= 3, s[i, j] = 1, 4 <= sum, s[i, j] = 0], If[3 <= sum <= 3, s[i, j] = 1, s[i, j] = 0]]
In order to repeat the last command successively, I set the new values of a to be the values of s
Clear[a]
a=s
Table[a[0, j] = 0, {j, 0, JJ+1, 1}]
Table[a[i, 0] = 0, {i, 0, II+1, 1}]
Table[a[II + 1, j] = 0, {j, 0, JJ+1, 1}]
Table[a[i, JJ + 1] = 0, {i,0, II+1, 1}]
a[II + 1, JJ + 1] = 0
The problem appears when I try to recalculate the values of s, using the conditional functions: it gives me the same values of s obtained the last time the function was used. Why does this happen??
I tried to reset the values of s (Clear ) before evaluating the expression containing the conditional functions, but it also resets the values of a. Can I avoid this situation, and reset only the values of s, maintaining the values of a unaffected??
Thank you so much, and dont hesitate to email me if you need further information, or a copy of the sheet. Thanksss
Daniel
cricricombowino@gmail.com