Another day, another implementation. Today I have implemented Conway’s game of life. It is a very simple model that can show very complicated results. It is also a lot of fun. What are the rule to this game? Well, I will tell you. First, let us start with the components of the system, we have
- a 2-dimensional grid
- a set of rules
- alive and don’t have two or three alive neighbours -> dead
- dead and three alive neighbours -> alive
Now we only have to define neighbours. In a 2D grid these are the 8 squares around a particular square. I have drawn a little ASCII graphic.
|---+---+---| | O | O | O | |---+---+---| | O | X | O | |---+---+---| | O | O | O | |---+---+---|
The O’s mark the neighbours and the X the particular square in question. Now all we have to do is implement it.