Skip to content

Repository files navigation

Game of Life

Conway's Game of Life, written in C# with GTK for the UI. I built this in 2023 as a first-year project at Charles University, so treat it as early work rather than a polished piece of software.

The rules are the standard ones: a grid of cells, each alive or dead, and each generation is decided by how many live neighbours a cell has. You pick a starting pattern from a menu, watch it evolve, and can pause it with the space bar. There's a handful of classic patterns bundled in StartingStates/ (glider, pulsar, Gosper's glider gun, and others), plus a random option.

Demo: selecting a starting state and watching it evolve

Requirements

  • .NET SDK, targeting net7.0 (built and tested against the .NET 7 and .NET 8 SDKs)
  • GTK3 installed natively, since GtkSharp is a binding over the system GTK libraries rather than a bundled one. On macOS: brew install gtk+3. Most Linux distributions have GTK3 already; on Windows the GtkSharp NuGet package pulls in the runtime it needs.

Build and run

dotnet build
dotnet run

Both commands need to be run from the repository root, next to Game-of-Life.csproj. dotnet run opens a window with the grid and a menu bar for choosing a starting state, a speed control (slow/medium/fast), and a life span setting if you want the simulation to stop after a fixed number of generations rather than run forever.

Layout

  • Model.cs: the grid and the generation rules
  • View.cs: the GTK window, drawing, and controls
  • StartingStates/: plain text files, one character per cell, 1 for alive and 0 for dead, used to seed a pattern

Notes

This was my first time working with GTK, or with a graphics/UI library in C# generally, so some of the design choices (mutable state passed around between the window and the view, for one) are what a first-year student version of me thought was reasonable at the time. It runs and does what it says, but I wouldn't hold it up as an example of how I'd write it now.

About

Conway's Game of Life in C# with a GTK interface: pick a starting pattern, control speed and generation limit

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages