![]() 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. Learning Scientific Programming with Python Maurer Roses QR Codes and the Game of Life The Weierstrass function Visualizing the Temperature in Cambridge, UK. 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. Only spaces which "have life" need to be divided into smaller subspaces - the empty ones can be skipped. 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. Whenever you find life, you mark these subspaces as "has life". The game is a zero-player game in which an initially configured 2D grid of cells evolves according to the Game of Life ruleset. 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%." Function 4: advance a grid one generation input: a grid return: a new grid. Function 3: load a pattern input: a file name, a grid return: nothing. ![]() Function 2: print a given grid input: a grid return: nothing. 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. These are the functions I am using to create Conways Game of Life: Function 1: create a blank grid input: nothing return: a blank grid. To make this work in Python 3, replace all xrange with range (3 replacements) and also replace length/2 with length//2. All gists Back to GitHub Sign in Sign up. GitHub Gist: instantly share code, notes, and snippets. What is the most efficient algo mainly depends on the initial state. Conways Game of Life in an IPython Notebook.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |