Page 1 of 1

Doubts conway's game of life

Posted: March 4th, 2017, 5:34 am
by virginialuther12
Hi guys,
I am writing a macro that is mostly an excel based version of Conway's game of life if you know about Conway's game of life?The trouble is, both birth and death are invented to occur concurrently, and the way I am presently doing it they occur successively so births and deaths that happen earlier in the for loop...next loop affect the results of calculation later on.To solve this, in its place of calculating the fate of a cell based on the value of the 8 cells presently surrounding it, I would like to store the cell values at the end of each loop, and then make a calculation that refers back to these values. so the fate of each cell would then be determined by the 8 subsequent saved values and not the 8 current values.I hope I have explained myself obviously sufficient mostly what I am asking is, how to save the values of each of the cell in the sort at the end of each loop, if the statement within a loop can refer back to these values, in its place of referring to the present values.

Re: Doubts conway's game of life

Posted: March 4th, 2017, 7:08 am
by blah
If I understand your question right, the simple solution is to have two arrays; one containing the state of all the cells, and another containing what their states will be in the future. You iterate through the first array while writing to the second array, and then you go through and copy the second array into the first. I'm not sure about how Excel works, but if you can only have one array I guess you could have each cell be able to contain two values, one being its state, and another being what it will become. Does that make sense?

Re: Doubts conway's game of life

Posted: March 4th, 2017, 8:38 am
by dvgrn
blah wrote:I'm not sure about how Excel works, but if you can only have one array I guess you could have each cell be able to contain two values, one being its state, and another being what it will become. Does that make sense?
The classic trick is to use two arrays -- two different sheets in an Excel workbook, in this case -- and swap back and forth between them.

Use Sheet A to calculate the new states and store them in the corresponding cells in Sheet B, and then on the next tick use Sheet B to figure out the next generation and put the results back in Sheet A, overwriting all the old cell states there.

If you want everything to happen in one sheet, just copy all of Sheet B's contents back into Sheet A after every cycle instead of switching back and forth. It's a little slower, but Excel macros aren't going to be setting any Life simulation speed records anyway...!

Re: Doubts conway's game of life

Posted: March 4th, 2017, 11:19 am
by rowett
You can do it in Excel without any macros by using Array Formula. See here for an introduction.

Re: Doubts conway's game of life

Posted: March 4th, 2017, 3:00 pm
by Mr. Missed Her
Maybe it helps to think about it this way:
Simulate a CA with six states, three off states, 0, 0s, 0t, and three on states, 1, 1s, 1t. Start out with only 0 and 1 states, no s's or t's. Every 0 with 3 of any 1 states adjacent becomes a 0t in the next gen, otherwise it becomes 0s. Every 1 with 2 or 3 of any 1 states adjacent becomes a 1s in the next gen, otherwise it becomes 1t. And every 0t and 1s will become a 1, and every 0s and 1t will become a 0. This should simulate life with every 2 gens = 1 life gen, no matter how you check and set the cells. (Unless you check some twice!) It'd also be interesting to see what happens if you simulate this incorrectly, starting out with some s's and t's and some non- s's and t's.