Art & Work
About
Deprecated: Function split() is deprecated in /var/www/web110/html/Joomla/plugins/system/jfrouter.php on line 591
Deprecated: Function split() is deprecated in /var/www/web110/html/Joomla/plugins/system/jfrouter.php on line 591
Introduction: A Cellular AutomatonConway's Game of Life is the ultimate toy for the mathematically inclined. It is a simple cellular automaton that simulates the life and death of cells using extremely simple rules. It's playground is an infinite, two-dimensional grid of discrete, square cells that can either be alive or dead. At each step of the simulation, the following rules are apllied to all cells at once:
So why am I telling you about all this here? A few years ago, I was playing around with flash and ActionScript 2.0. It was terrible to work with from a programmers point of view. However, Adobe recently released Actionscript 3.0 which is a big step forward for actionscript, and I decided to work myself into it again. I chose a Conway's Game of Life implementation for my first project, and well, here it is: The Program
Draw cells onto the plane with the mouse. Then click the play button to make a single step, or the fast forward button for continuous simulation. At the start, you are using the cursor tool to switch single cells on or off. You can also use the 'stamp' tool to edit a preset colony, and stamp it all over the board. Or you can use the 'presets' tool to bring very special formations onto the plane. Use the arrow keys or scrollbars to scroll and the plus and minus keys to zoom. Techniques: A Fast Computation Algorithm for Conway's Game of LifeThe most naive implementation is to simply form two two-dimensional arrays, one buffer and one field of play. Place the cells on the field of play, and for a step of the simulation, go over each square of the buffer and apply the rules to it based on the field of play's living cells. After that swap both boards, clear the buffer and repeat. This is obviously suboptimal, since each cell is queried eight times for it's status, and the complexity is near O(8n2). So 2D-Arrays don't seem to be optimal. There are hundreds articles on the Internet how to implement really fast algorithms for theGame of Life. Unfortunatley for me, each of those I found assumed that you wrote it in C++ or C. With enough knowledge, you can make predictions about how the register will be filled and use that to your advantage - Bitmasks are the magic word. Now that is all nice and well, but Actionscript is a script. It does compile to bytecode, okay, but I couldn't use the approach learned from other algorithms. So I had to find my own one. The requirements were as follows:
I did not want to find and implement something too complex either, since that was not the focus of my work. Based on some other ideas I came up with the following data structure:
I will have to throw in a short explanation here. The biggest problem of a 2D-array is it's initialisation. We usually need to iterate it and fill it with a standard value, because otherwise queries to the array will return a random value. This process already results in a complexity of O(n2). BUT (you saw that coming) arrays in Actionscript 3 are sparse. They do work a little like linked lists, only that indexes are still absolute. An index that has not been written to does not use up memory, and querying a field that does not have a number assigned to it returns "undefined". We can work with that now... How the algorithm works:
Source CodeI will make the Actionscript Files that correspond to the model of the program available. They contain the most interesting code anyway. The control and view components have suffered from my initially clumsy attempts to make Flex and Flash work together, since flash did the view part whereas the controls were written in flex. They should not be used as a template. The files will be posted here in the near future. Credit where Credit is dueThe predefined shapes and descriptions are taken from the Lexicon of Life by Edwin Martin, who in turn recompiled it from Steven A. Silver's Life Lexicon. Here you can find the full credits. Their work allowed me to import descriptions and cell-formations very convieniently for which I am very thankful. My edited version can be downloaded here. You are free to copy and distribute it as long as proper credit is given. And Mr. Martin and Mr. Silver deserve it more so than I. If you got interested in the Game you should also check out Martin Edwins Game of Life Program. It is written in Java and far more perfomant than my implementation. It can be downloaded here. ConclusionIt was nice to program in Flash again. It is a bit unfortunate that Adobe decided against a proper coding environment in the Flash IDE, but there are ways to get around this. I personally recommend using Flex Builder for programming and Flash for design only. The outcome is little more than a toy, but I strived for accessibility rather than complexity - and as such I am quite satisfied with the outcome. |

