Go to file
Federico Zanetello 230acd22b5
Merge pull request #3 from zntfdr/swift-5.5-migration
Swift 5.5 migration
2022-01-30 10:48:01 +07:00
.assets initial commit 2020-04-19 19:03:55 +07:00
.github/workflows update GH workflows dependencies 2022-01-30 10:33:07 +07:00
Sources use @main 2022-01-30 10:23:32 +07:00
Tests/LifeTests initial commit 2020-04-19 19:03:55 +07:00
.gitignore initial commit 2020-04-19 19:03:55 +07:00
.swiftlint.yml initial commit 2020-04-19 19:03:55 +07:00
LICENSE add license 2020-04-19 21:55:32 +07:00
Package.resolved update dependencies 2022-01-30 10:18:53 +07:00
Package.swift update dependencies 2022-01-30 10:18:53 +07:00
README.md Improve mode description 2020-04-21 21:21:40 +07:00
makefile update make file 2022-01-30 10:29:09 +07:00

README.md

Life

Build status Swift Package Manager All platforms Twitter: @zntfdr

Welcome to Life, a Swift implementation of Conway's Game of Life.

Usage

Life has two main entitites, World and Cell:

  • World represents the game space, which is a two-dimensional orthogonal grid of square cells, it also keeps track of the current alive cells generation.

  • Cell represents 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()
...

A World instance only remembers the current alive generation, which is accessible via the aliveCells property.

At any moment new alive cells can be added, and old alive cells can be removed, to do so use the add(_:) and remove(_:) World instance methods.

Lastly, 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 Tests folder.

Game modes

Life comes in two modes: Simple and Loop.

The mode is specified when creating a new World instance (the default mode is .simple):

var world = try World(rows: rows, columns: columns, mode: .loop)
Simple 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.

Installation

Life is distributed using the Swift Package Manager. To install it into a project, follow this tutorial and use this repository URL: https://github.com/zntfdr/Life.git.

Command Line Tool

life in action

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

Credits

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 its 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 youre planning, or a test that reproduces an issue.

Thank you and please enjoy using Life!