gameoflife

Created: 2011-07-13 19:07
Updated: 2013-01-03 21:24

README.md

Background

On July 9 in Berlin at the Scout-lounge a code-retreat took place where a solution to the Conway's game of life was sought. This is a snapshot of the activities preceding the event and pairings during the event.

Needed software

Git

Download and install git.

Simple build tool

Setup sbt. This readme assumes that the sbt start script is named sbt10. Some commands that you can use are test, compile, and run.

Clone this repo

To clone this repo and fetch all the branches invoke

git clone https://github.com/ppurang/gameoflife

cd gameoflife

git fetch

You should be on the master branch. Invoke the following to test that things are in order

sbt10 test

This makes sbt compile things and run all the tests. Note: First attempt always takes a significant amount of time if this is the first invocation of sbt. It downloads scala libs, test libs etc.

An excellent time to have a break.

If you want to play around with sbt just invoke sbt10 and you get a sbt console to play with.

Branches and their significance

The following command shows you all the various branches

git branch -v

BLANK    6007f36 some more sekeletons

Patricia 6661e04 works

SEB      4527679 ~

Stefan   53e0210 works

Wolf     5c32da3 works

*master   5ac44db refactored to drop skeletons and made it a bit more testable

miro     ae2d87d works

Note: if you just see master and nothing else perhaps you forgot git fetch. The asterisk * indicates the present checked out branch.

To checkout a branch say BLANK

git checkout BLANK

and then you can rerun sbt10 to see the effects of the changes in that branch. Now to the branches:

BLANK  -  is a blank state supposed to be used as the starting point.

master -  has a runnable demo of a possible implementation of game of life.

Other branches are results of pairing with different participants.

Collaboration

As each pair has just 45 minutes I decided to just concentrate on the most important aspect of the game; the logic of when and how cells live or die.

I decided to call it the StateTransition: a function that given a 'State' returns a function that in turn given a sequence of neighbouring states returns an end state. In haskell like notation

StateTransition :: State -> [State] -> State

An example run would be Dead -> [Alive, Alive, Alive, Dead] -> Alive. The number of neighbouring states doesn't matter. For an average square cell in the game it would be 8.

The effort always was to use function composition to accomplish correct, concise and readable code.

Note: Readability is always in a beholders eyes. What might be too terse and unreadable to some turns to be very readable to others. For the devs coming from a very imperative/procedural part of the programming world the results of these collaborations might appear very unreadable. But do give it a second chance. And compare the results to how you would have done it in say Ruby or Java or some such.

Taking it for a run

To simulate game of life on the command line

git checkout master

sbt10

run 10 10 20

The above will run a colony of size 10x10 through 20 generations.

Taking it further

Here are some nice things to have

  1. A proper GUI (different colors for clans)
  2. Recognizing if a colony lives for ever a. if history is repeated then i'd say yes b. some patterns like the following never die
     **    *      **
     **   * *    *  *
          * *    *  *
           *      **
     
    Can you predict the next one?
  3. Replicating the patterns like Gosper's glider gun
  4. Better algos like quad tree with memoization
  5. Concept of signalling (something like biochemical signal/interaction between cell). for example take any cell and ask it to transform into the next generation this has a cascading effect on the neighbours and so forth
  6. Ever expanding universe - starts small, expands for ever
  7. Spontaneous eruption of life
  8. Cells that have different behaviour, i.e mutation and survival of the fittest (some are hardier than the others) (one idea: offsprings of different clans are hardier while genetically isolated generations wither faster)
  9. hexagonal cells
  10. more dimensions

xx. All the above rolled into one :)

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more