Files
SwiftUI-LifeGame/Root/Sources/Core/BoardExample.swift
T
2022-04-27 13:49:36 +09:00

54 lines
1.8 KiB
Swift

//
// BoardExample.swift
// LifeGameApp
//
// Created by Yusuke Hosonuma on 2020/08/25.
//
import LifeGame
// Note:
// Widgetのプレースホルダなど、固定時間での表示が望ましいケースで表示例として利用すること。
// (Widget専用にしちゃってもよいかも?)
public enum BoardExample: CaseIterable {
public struct Data {
public var title: String
public var board: Board<Cell>
}
case butterfly
case cross
case monolith
case nebura
public var data: Data {
switch self {
case .butterfly:
return Data(
title: "Butterfly",
board: Board(size: 4, cells: cells([1,0,0,0,1,1,0,0,1,0,1,0,0,1,1,1]))
)
case .cross:
return Data(
title: "Cross",
board: Board(size: 8, cells: cells([0,0,1,1,1,1,0,0,0,0,1,0,0,1,0,0,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,0,0,1,0,0,1,0,0,0,0,1,1,1,1,0,0]))
)
case .monolith:
return Data(
title: "Monolith",
board: Board(size: 11, cells: cells([1,1,0,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,0,1,1]))
)
case .nebura:
return Data(
title: "Nebura",
board: Board(size: 9, cells: cells([1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1]))
)
}
}
private func cells(_ rawCells: [Int]) -> [Cell] {
rawCells.map { $0 == 1 ? Cell.alive : Cell.die }
}
}