Programming Cellular Automata - Life in 3d
This post covers the basics of cellular automata via Conway's game of life and a 3-dimensional derivative of it that I programmed. The images below are a couple frames extracted from that program.
While at community college, I attended a night class in C-programming where I had the opportunity to develop Conway's game of life as a text program. It initiated a deep fascination for cellular automata and the idea that a computer could generate an entire world given a basic set of rules. Interestingly enough, Conway was not actually the founder of cellular automata. it was theorized 30 years earlier by John von Neumann & Stanislaw Ulam. von Neumann was interested in different methods of colonizing mars, and one of them involved self-replicating robots to setup living environments for humans. As a result of breaking that concept down to its foundations, Neumann was able to extract the theory of cellular automata.
Conway popularized cellular automata with his game of life. He often claimed it wasn't one of his greatest achievements, and actually overshadowed some of his other work. It's a shame we lost him to covid-19. His game is played on a 2-dimensional grid, and an initial state is set with live and dead cells. The game has a single player - in this case, a computer - and the player must follow the rules, Which are as follows:
- Any live cell with two or three live neighbors survives.
- Any dead cell with three live neighbors becomes a live cell.
- All other live cells die in the next generation. Similarly, all other dead cells stay dead.
Conway's game of life - "life breeder".
Conway found an interesting balance where the final results of the game are not clearly declared by the initial state. The game may reach a state of oscillations or a static state, or it may continue on forever. I don't know of any algorithms that are able to predict the final state.
I later wrote Conway's game in processing with a much more user-friendly, graphical interface. During the writing process, I became interested in further developing the project into 3-dimensions. I continued to use Moore's neighbor rules where all boxes touching the center square are considered (as opposed to von Neumann's rules where the diagonally touching square are not considered "neighbors)
Moore's neighbors - from Wikipedia (https://en.wikipedia.org/wiki/Moore_neighborhood)
Moore's Neighbors in 3d - All the black cells are considered when counting neighbors
Using the same life/death rules resulted in octohedron increasing in size - which isn't very interesting; however, after playing around with the rules I found some growth structures that were much more complex. The uniformity is amazing. The program was designed to operate inside a 30x30 grid with edges that repeat on the other side - I might consider removing this feature in the future in order to observe more organic growth. I might also consider increasing the size of the grid; however, I'll need to figure out some way of allowing it to operate more efficiently. My frame rate does take a hit with the current program, not sure why.
In the video below the death rule is set to 1<neighbrors < 20 and the life rules are set to neighbors = 4. In other words, a cell that is dead will become alive if there are 4 live neighbors, and a cell that is alive will die if there are between 1 and 20 neighbors.
Those rules were somewhat arbitrary; however, the resulting pattern is orderly and neat. It still blows my mind. The code for this program can be found on my GitHub repository: Cellular automita
There have been loads of applications for CA's, especially in the biological world. This fascinating study on Distl explored differentiable CA models and their applications in morphogenesis. I would love to see some practical applications for cellular automata mixed with machine learning or AI in the future.
Comments
Post a Comment