86. Life

Like the Langton's Ant example solution, this one is fairly long but relatively straightforward, so I won't include a lot of code here. The most important piece of code is the following Tick event handler, which updates the world to create the next generation:

// The size of the world.private int GridWid, GridHgt;// The world.private bool[,] World = null;// True if we should wrap squares  across the world's edges.private bool WrapEdges = true;// Move objects.private void moveTimer_Tick(object sender, EventArgs e){    // See how many neighbors each squares has.    int[,] numNeighbors = new int[GridWid, GridHgt];    for (int y = 0; y < GridHgt; y++)    {        for (int x = 0; x < GridWid; x++)        {            // See if this square is occupied.            if (World[x, y])            {

Get The Modern C# Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.