You might think that dividn up a 10,000*10,000 spae into subspaces of 8*8 is a lot os tasks - but accumulating their states values is in fact much, much less computing work than performing the GoL algo to each cell plus their 8 neighbours plus comparing the number and storing the new state for the net iteration somewhere.īut like i said above, for a random init state with 30% population this wont make much sense, as there will be not many completely dead 8*8 subspaces to find (leave alone dead 256*256 subpaces)Īnd of course, the way of perfect optimisation will last but not least depend on your language. Built using Python 3.5, this implementation of Conway's Game of Life allows the user to easily run the Game of Life using a 2D grid of choosen number of rows and columns in either a Linux or Windows terminal/console. Any live cell with two or three live neighbors lives on to the. With the elementary CA, we were able to look at all the generations next to each other, stacked as rows in a 2D grid. However, the bug that's causing your error is that you don't reset a cell's neighbour count to zero after you've determined whether it'll be alive or dead in the next generation. I have a few more comments about your code. 1 Answer Sorted by: 4 I don't have pygame installed, so I can't run your code. When you are finished assigning the "has life" attribute to all possible subspaces, you end up with a list of subspaces which you now simply extend by +1 to each direction - with empty cells - and perform the regular (or modified) game of life rules to them. The game is a zero-player game in which an initially configured 2D grid of cells evolves according to the Game of Life ruleset. dead Any live cell with fewer than two live neighbors dies as if caused by under-population. Heres a more compact version of that method: def breed (self): self.alive self.neighbours 3 or self.alive and self.neighbours 2 self.neighbours 0. Only spaces which "have life" need to be divided into smaller subspaces - the empty ones can be skipped. Whenever you find life, you mark these subspaces as "has life". You could go down to subframes of 8*8 or 10*10 (not sure what makes the most sense here) now. If its sum of states is >0, you will now divide up the second quarter into 4 pieces again - and repeat this check for life for each of these subspaces. So if you have a field of 10,000 * 10,000, you´d first accumulate the states of the upper left quarter of 5,000 * 5,000.Īnd if the sum of states is zero in the first quarter, you can ignore this first quarter completely now and check the upper right 5,000 * 5,000 for life next. I would just divide the matrix up into halves and start checking the bigger ones first. Im my opinion it can make sense to check for completely dead spaces first, when your initial state is something like "random, but with chance for life lower than 5%." If the majority of cells is dead, you could save a lot of CPU time by skipping empty parts and not calculating stuff cell by cell. What is the most efficient algo mainly depends on the initial state.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |