package snake package life // m13 life model: the whole world is one value, like the snake and the match. /** * The whole world. `cells` are the live cells, always kept canonical: sorted row-major (by `y`, then by `x`), each cell * at most once, all on the board. `seed` is the unsigned 32-bit seed that `Randomize` draws from; `generation` counts * the generations since the board was last cleared or randomized. */ final case class LifeState(cells: List[Point], running: Boolean, seed: Long, generation: Int) /** Everything that can happen to the world, as data. `Toggle` carries the cell that was clicked. */ enum LifeAction: case Frame case Toggle(cell: Point) case TogglePause, Step, Clear, Randomize object LifeModel: // The board, in cells: LW columns, LH rows, LCELL pixels per cell. Below it the page shows a status strip. val LW = 40 val LH = 30 /** Pixels per cell. */ val LCELL = 16 /** Height of the status strip under the board, in pixels. */ val STRIP = 24 /** A fresh world: no live cells, paused, the given seed, generation 0. */ def initialLife(seed: Long): LifeState = LifeState(Nil, running = false, seed, generation = 0)