Skip to content

Instantly share code, notes, and snippets.

View BeauNouvelle's full-sized avatar
👨‍💻
Working

Beau Nouvelle BeauNouvelle

👨‍💻
Working
View GitHub Profile
let firstCell = Cell(x: 10, y: 10, state: .dead)
let secondCell = Cell(x: 11, y: 10, state: .dead)
print(firstCell.isNeighbor(to: secondCell))
// true - Same row, adjacent column.
let firstCell = Cell(x: 10, y: 10, state: .dead)
let secondCell = Cell(x: 20, y: 10, state: .dead)
print(firstCell.isNeighbor(to: secondCell))
// false - Same row, vastly different column.
public class World {
public var cells = [Cell]()
public let size: Int
}
public init(size: Int) {
self.size = size
}
for x in 0..<size {
for y in 0..<size {
let randomState = arc4random_uniform(3)
let cell = Cell(x: x, y: y, state: randomState == 0 ? .alive : .dead)
cells.append(cell)
}
}
let world = World(size: 2)
dump(world.cells)
public class WorldView: UIView {
var world: World = World(size: 100)
var cellSize: Int = 10
}
public convenience init(worldSize: Int, cellSize: Int) {
let frame = CGRect(x: 0, y: 0, width: worldSize * cellSize, height: worldSize * cellSize)
self.init(frame: frame)
self.world = World(size: worldSize)
self.cellSize = cellSize
}
public convenience init() {
let frame = CGRect(x: 0, y: 0, width: 1000, height: 1000)
self.init(frame: frame)
}
public required init?(coder aDecoder: NSCoder) {
fatalError("Not implemented")
}
public override init(frame: CGRect) {
super.init(frame: frame)
}