1
|
14351 Views
|
10 Replies
|
15 Total Likes
View groups...
Share
GROUPS:

# Problems defining conditional functions in Conway´s game of life

Posted 10 years ago
 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
10 Replies
Sort By:
Posted 10 years ago
 other than http://reference.wolfram.com/mathematica/ref/CellularAutomaton.htmlhttp://reference.wolfram.com/mathematica/ref/CellularAutomaton.html i can't gfind a lecture on using on using the function. can you tell me where to locate it it? thanks.but thanks for the explanation of CellularAutomaton. btw - as both an educator and scientist, i have found that the use of terms like Life, glider gun, etc. actually does indeed, have pedagogical value (the use of analogy is an important learning and thinking tool) and it is one of the reasons that the GoL is, without a doubt, the best known CA (much more so than rule 30 or 110) even amongst professional scientists  and it's really no worse for introducing  people to cellular automata than using the Bohr model of the atom  to introduce people to the concept of quantum behavior. it's a satrting point and a hook to get someone interested in a subject. there's nothing wrong with that.funally, here is a youtube video (https://www.youtube.com/watch?v=MYGJ9jrbpvg) that illustrates the difficulty in dfining 'life. it is not in fact, not true that "everyone knows what life is - . especually not biologists or robotics specialists (or people who work in artifical intelligence).
Posted 10 years ago
 The original CellularAutomaton lecture was given in 2004http://www.wolframscience.com/summerschool/resources/NKSCA-phillips-ss04.cdfSome of the other lectures from past summer schools can be found at http://www.wolframscience.com/summerschool/resources/
Posted 10 years ago
 thanks for the info, todd.btw - i entered that address in safari and it won't go there (in fact, the address imply dissapears from the address bar). so instead,  i went to http://www.wolframscience.com/summerschool/2006/faculty.html#Phillips and then clicked on presentations by Richard Phillips which bought up NKS Research Tools: CellularAutomaton and cicking on that downloads the cdf. i mention this for others who may want to get the lecture.
Posted 10 years ago
 Todd:in genreral, does the built-in CellularAutomaton function work? is it defined in terms of WL or in another language, e.g. C? does it use Gosper's algortihm or what? it's concerning to use built-in functions if you don't know the underlying algorithm or see the code. the GoL rules are easy to write down and the b.c. explained. how can someone possibly know that CellularAutomaton[{224, {2, {{2, 2, 2}, {2, 1, 2}, {2, 2, 2}}}, {1, 1}}, RandomInteger[1, {20, 20}], 30]is in fact, implementing the GoL correctly? i can't figure out what b.c. are being used or what the GoL rules are from looking at the arguments of Cellular Automaton. and isn't this function, limited to totalistic rules where the site values are integers? and what does one do for other CA's. e.g. how is CellularAutomaton function used for the forest fire CA?  i am unable to understand what the arguments 'mean'.  how do you discuss the GoL with anyone using CellularAutomaton? do you say 'here are the rules and the b.c. and now just trust me that CellularAutomaton[{224, {2, {{2, 2, 2}, {2, 1, 2}, {2, 2, 2}}}, {1, 1}}, RandomInteger[1, {20, 20}], 30] is implementing the GoL correctly, i don't see how one can teach the GoL to students if you can't show them the code. obviously at some point, you just say use this built-in function (e.g. Sort but even there you can tell them what Sort is doing even you don't explain that it might be doing it using a mergesort or bubblesort but CellularAutomaton[{224, {2, {{2, 2, 2}, {2, 1, 2}, {2, 2, 2}}}, {1, 1}},...]  is totally opaque.
Posted 10 years ago
Posted 10 years ago
 Thank yo Vitaliy, I´ll check the Demostrations Project... I´ll let you know if I find something....
Posted 10 years ago
 Thank you Todd and Vitaliy for your response....  Sorry for my delay in the discussion, but i was without net....  Todd: you are right about the "sum" definition, but it gave me no problem: the "sum" definition I used here was to simplify the explanation. I will check the references you suggested me. Thank you. Nevertheless, I think my approach can work, but I still need to solve the issue of the definition of the s function, or, instead, clear the values of s, after it is calculated in each step. Can you help me with that?? Thanks Vitaliy: I don´t want to use the demonstations posted on the wolfram website. I want to do it by myself ;-)
Posted 10 years ago
 Daniel, the reason I recommended the Demonstrations Project is to learn from the source code. I am not sure if you are aware of this, but demonstrations are not black-boxed, - any demonstration can be downloaded and the source code can be studied to understand how it works. There are quite a few experienced programmers that made an effort to develop effective code running GoL using Wolfram Language at Demonstrations Project, - I personally learned from that.
Posted 10 years ago
 Also, if you need an animation, take a look at Demonstrations Project. Those are basically advanced interactive animations. Code is freely available for download.
Posted 10 years ago
 Daniel,Before discussing your code, let me point out the implementation in the documentation http://reference.wolfram.com/mathematica/tutorial/CellularAutomata.htmlArrayPlot /@ CellularAutomaton[{224, {2, {{2, 2, 2}, {2, 1, 2}, {2, 2, 2}}}, {1, 1}}, RandomInteger[1, {20, 20}], 30]and the  implementation  in the NKS book (which was written before the CellularAutomaton function) is a good place to look to learn more about Wolfram Language.http://www.wolframscience.com/nksonline/page-949a-textThe code you have written is not a typical approach.  One thing going on is you have sum=... which will assign a value to sum.  More usual would be to writesum[i_,j_]:=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]There are probably some problems with the boundary.