Timeline for Optimize Conway's Game of Life
Current License: CC BY-SA 3.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 13, 2017 at 12:40 | history | edited | CommunityBot |
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
|
|
| Sep 7, 2014 at 10:10 | history | edited | Ilmari Karonen | CC BY-SA 3.0 |
+addendum
|
| Feb 26, 2014 at 21:03 | comment | added | Adam Arold | You definitely need more upvotes. The preliminary implementation resulted in a 10x speedup! | |
| Feb 26, 2014 at 21:00 | comment | added | Adam Arold | And I can create the lookup by simply converting the numbers from 0 to 511 to a binary arrays and applying the game of life rules to them. | |
| Feb 26, 2014 at 20:52 | comment | added | Ilmari Karonen |
Right. To be a bit more specific, the statement environment = ... in the inner loop modifies the environment variable so that it encodes the pattern of live/dead cells around cell (x, y), assuming that it previously encoded the pattern around cell (x-1, y). Since, on the first iteration, x = 1, to satisfy this assumption we need to initialize environment (or at least the lowest six bits of it) to the value it should've had at x = 0.
|
|
| Feb 26, 2014 at 20:43 | comment | added | Adam Arold |
Oh I get it. We can pre-calculate it because x will start at 0. I tend to forget that my computer speaks binary.
|
|
| Feb 26, 2014 at 20:36 | comment | added | Adam Arold |
But why would I use columns 0 and 1 if I don't know x yet? Sorry, I've only used bit vectors once (with SWT) and I don't really get this.
|
|
| Feb 26, 2014 at 20:25 | comment | added | Ilmari Karonen |
((environment % 64) * 8) strips away all but the lowest six bits of the environment pattern, and then shifts the remaining bits left by three. You could equally well write it with bit operators as ((environment & 0b111111) << 3). The initial value is, in effect, the environment for x = 0, consisting of the states of the six cells in rows y-1, y and y+1 and columns 0 and 1. It doesn't include the (non-existent) column -1, since the bits that would encode those cell states will just get shifted out of the environment in the inner loop anyway.
|
|
| Feb 26, 2014 at 20:20 | comment | added | Adam Arold |
Can you please explain the environment variable's calculation? I don't understand how you calculate its initial value without knowing about x. The ((environment % 64) * 8) part is not clear either.
|
|
| Feb 26, 2014 at 19:48 | comment | added | Adam Arold | Thanks for the thorough explanation! For some reason using a bitvector(like) structure did not came into mind. | |
| Feb 26, 2014 at 11:09 | vote | accept | Adam Arold | ||
| Feb 25, 2014 at 18:00 | history | answered | Ilmari Karonen | CC BY-SA 3.0 |