Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Conway's Game of Life written in Swift 👾

License

NotificationsYou must be signed in to change notification settings

zntfdr/Life

Repository files navigation

Life

Build statusSwift Package ManagerAll platformsTwitter: @zntfdr

Welcome toLife, a Swift implementation ofConway's Game of Life.

Usage

Life has two main entitites,World andCell:

  • 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.varworld=tryWorld(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()...

AWorld instance only remembers the current alive generation, which is accessible via thealiveCells property.

At any moment new alive cells can be added, andold alive cells can be removed, to do so use theadd(_:) andremove(_:)World instance methods.

Lastly,World exposes anisCellAlive(_:) instance method to check whether the specified cell is part of the current generation.

You can find many more examples in theTests folder.

Game modes

Life comes in two modes: Simple and Loop.

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

varworld=tryWorld(rows: rows, columns: columns, mode:.loop)
SimpleLoop
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 theSwift Package Manager. To install it into a project, followthis 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 byFederico 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, pleaseopen 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 usingLife!


[8]ページ先頭

©2009-2025 Movatter.jp