Thursday, August 20, 2015

Conway's Game Of Life - C#

I love Conway's Game Of Life, a fact that I can't deny. I implemented several rather unsophisticated simulators in various programming languages: MOS 6502 assembly, C64 BASIC, Apple Soft BASIC, C, C#. Today I'd like to write about my C# port.

Back in 2004 I started to learn C# and .NET. This process spawned several programming projects. The first was Game Of Life simulator. I recently brought that project back from hibernation. I originally developed the program under SharpDevelop IDE. That IDE is still being developed and supported. I downloaded the newest version 5 and Microsoft's .NET developer's pack for version 4.5 of .NET. I fixed few bugs and made some improvements and I built a new version. It performs nicely. It is so good to watch those colonies evolve again. There is something hypnotic about watching a running GOL colony simulation, any nerd can confirm that.

Anyway, few words about the game:

It was invented by mathematician John Horton Conway in 1970. It is a game that plays itself, since this is a cellular automaton, the evolution of the game is determined by initial state and the rules that govern the creation of subsequent generations of the colony created in each time tick.
The universe of a game is a 2-dimensional grid of cells which can be in 2 possible states: dead or alive. Each cell interacts with 8 adjacent neighbors and depending on the number of alive neighbors, the state of the cell may or may not change in the next generation.

The following rules govern the next state of the cell:

  • Each alive cell that has one or no alive neighbors will die from loneliness.
  • Each alive cell that has two or three alive neighbors will remain alive.
  • In each empty (dead) cell with exactly 3 neighbors will change the state to alive (reproduction).
  • Each alive cell with 4 or more neighbors will die from overcrowding.

My program allows to save the colony in disk file and load one from file. I developed my own colony file plain text format so for now unfortunately you can not download and use directly any popular on the internet colonies in common formats like 'plaintext' or RLE. This is something that you esteemed reader can perhaps do on your own if you are not afraid of doing some programming (write your own converter or alter my program) or you may need to wait until I add this feature in the future version.
Program lets the user to edit the colony by clicking on the colony view area directly. Click on the cell to flip its state. Clicking on the colony view area automatically stops the simulation which can be restarted after modifications are complete. Saving the colony before running simulation is recommended.

Other features include:

  • Individual colony properties/setup file.
  • Zoom range 1-20.
  • Optional painting of the grid lines (slow).
  • Optional painting the dying cells (slow).
  • Possibility of changing the colony size.
  • Random colony generator.
  • Initial population number limit.
  • Single step mode.

In future versions I plan to improve GUI. I will also add support for one or more of the popular GOL colony file formats. Performance also may need some optimization, if I ever want to increase the maximum size of the colony or perhaps implement a dynamically extendable colony size, which may require some more advanced programming techniques to maintain proper rendering speed for huge colonies.

Download here ( and enjoy.
(The most current version as of 10/14/2015 is -



Marek K


  1. Version tons of bug fixes and enhancements - window re-sizing, colony re-sizing (no need to restart), automatic options and colony save prompt, pseudo full screen mode (looks pretty cool). Download:!106&authkey=!ABy2McLGukEtMpI&ithint=folder%2czip

  2. Version with source code is available for download.
    Minor bug fixes and improvements:
    * Ability to turn off colony view on the main control form.
    - faster rendering in full screen mode in case of short timer interval,
    - quickly hide the game screen from your boss :-)
    * Ability to start simulation immediately in full screen mode.
    * Added parameter to restart random colony after predefined number of generations to enjoy uninterrupted watching of patterns.
    * Added validation to options form: accepting digits only now in text boxes holding numeric parameters.

  3. This comment has been removed by the author.

  4. Version with source code (SharpDevelop) is available for download ( in my Public SkyDrive folder).
    Many enhancements and bug fixes, which include automatic scaling option (it was always ON before, now it can be enabled/disabled in Options), increased maximum colony size and screen-saver mode. To install program as a screen saver, change EXE extension to SCR and then click right mouse button on the SCR file and select Install option.

  5. Version with source code (SharpDevelop) is available for download ( in my Public SkyDrive folder).
    Highlights for this release:
    - Screen saver mode (MS Windows).
    - Advanced editing functions.
    - Ability to load Life 1.05 and Life 1.06 formats.
    To install as screen saver, follow these simple steps:
    * Rename executable file to SomeName.scr.
    * Click right mouse button, select Install from context menu.
    * Use standard screen saver dialog to edit settings/preview.
    * Ignore initial warning about missing settings file.
    * Enjoy!