Life copied to clipboard
Conway's Game of Life written in Swift 👾
Welcome to Life, a Swift implementation of Conway's Game of Life.
Life has two main entitites,
Worldrepresents the game space, which is a two-dimensional orthogonal grid of square cells, it also keeps track of the current alive cells generation.
Cellrepresents a specific cell in the world.
import Life // Create a World instance. var world = try World(rows: rows, columns: columns) // Add alive cells. world.add(Cell(row: .., column: ..)) world.add(Cell(row: .., column: ..)) ... // Spawn the next world generations. world.spawnNextGeneration() world.spawnNextGeneration() ...
World instance only remembers the current alive generation, which is accessible via the
At any moment new alive cells can be added, and old alive cells can be removed, to do so use the
World instance methods.
World exposes an
isCellAlive(_:) instance method to check whether the specified cell is part of the current generation.
You can find many more examples in the
Life comes in two modes: Simple and Loop.
The mode is specified when creating a new
World instance (the default mode is
var world = try World(rows: rows, columns: columns, mode: .loop)
|Any cell outside of the world edges is considered dead.||The world left and right edges are stitched together, the world top and bottom edges are stitched together.|
Command Line Tool
Life also comes with a command line tool that showcases its functionality.
To install it, clone the project and run make:
$ git clone https://github.com/zntfdr/Life.git $ cd Life $ make
Life was built by Federico Zanetello.
Contributions and Support
All users are welcome and encouraged to become active participants in the project continued development — by fixing any bug that they encounter, or by improving the documentation wherever it’s found to be lacking.
If you'd like to make a change, please open a Pull Request, even if it just contains a draft of the changes you’re planning, or a test that reproduces an issue.
Thank you and please enjoy using Life!