Game of life (update)

The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970. It is the best-known example of a cellular automaton. The “game” is a zero-player game, meaning that its evolution is determined by its initial state, requiring no further input from humans. One interacts with the Game of Life by creating an initial configuration and observing how it evolves.

Shortest code

While I like ActionScript the most, I decided to make a version in flash. It is also fine moment to introduce wonderfl project. Wonderfl is a service where you can build Flash(swf) online. Wonderfl is online, free and social. After registration you are able to write and build your own codes, follow people, favourtie theirs work or even fork other user’s code (improve, change).

My aim was to make the code shortest possible, so you may find it mess, hell yeah it is :). Try to fork my code on wonderfl to achieve shortest possible. Use some tricks to make your code shorter.

// Conway's Game of Life's_Game_of_Life
// field 38x38 px

    import flash.display.Sprite;
    public class GameOfLife extends Sprite{
        public function GameOfLife(){
            for each(i in w=h=38,a=new Array(w*h),b=[63,99,101,127,128,135,136,

Fastest code

Here is my attempt for the fastest code, I have used Pixel Bender to achieve best performance, it seems pretty smooth considering, it is capable of 12.000.000 pixels testing in 1 second. You can download gameoflife.pbk file from here. My first try was to use image1 input type, but image1 was not working correctly with sampleNearest() method – that seems to be the fastest sampler method in pixel bender. Then I switched to image4 and with sampleNearest() it resulted in much better performance compared to image1 and sample(). Other code optimizations were done to aviod as much if statements as possible.

Where to go next

Leave a comment

Please be polite and on topic. Your e-mail will never be published.