Hypnos Game of Life Swift

This project is based on John Conway's Game of Life and utilizes Life 1.06 file format for input. It is in 64-bit signed integer space. It was built in Xcode (Version 12.3) using Swift version 5.3.2. It has been ported to C#.

This Summer durning my Lambda School experience we had a "build week" in which the assignment was to build Game of Life as an iOS app.

This assignment differs in some fundamental ways.

  • Command line tool instead of a GUI
  • 64-bit signed integer space: The iOS app kept the entire grid in memory. The smaller grid size made this possible.

While I started with the basic game logic from iOS; it had to be heavily adapted since I switched from a fixed grid to a sparse grid stored in a dictionary. This results in a much smaller memory footprint; especially with smaller game files.

My Approach

  1. Load the file.
  2. The game board only contains live cells.
  3. Process each live cell in the game board and note if the cell is dying this iteration.
  4. In the process of checking the game board, note adjoining cells.
  5. Check each of the adjoining cells to determine whether the cell should be alive (added to the game board) after this iteration.
  6. Remove the dead cells from the game board.
  7. From the list of adjoining cells, add any new cells to the game board.
  8. Got to step 3 and repeat number of generations specified by the user.
  9. Save final game board to file with -result.txt appended to input filename.

How to Review

Start with main.swift. The bulk of the program logic is in GameOfLife.swift with a supporting object in Cell.swift. ConsoleIO.swift supports the command line program (file input/output and parsing the command line) and should be reviewed last.