universe.coffee | |
---|---|
This module is part of resursiveuniver.se. Universe ModuleThe Universe Module provides the basic | |
The Life "Universe" | |
Baseline Setup | _ = require('underscore')
exports ?= window or this |
Cafe au Life is based on two very simple classes: The smallest unit of Life is the | class Cell
constructor: (@value) ->
@level = 0
@initialize.apply(this, arguments)
initialize: ->
_.defaults Cell,
Alive: new Cell(1)
Dead: new Cell(0) |
HashLife operates on square regions of the board, with the length of the side of each square being a natural power of two
( For example, a square of size eight (
The squares of size four are in turn each composed of four squares of size two (
And those in turn are each composed of four cells, which cannot be subdivided. (For simplicity, a Cafe au Life board is represented as one such large square, although the HashLife algorithm can be used to handle any board shape by tiling it with squares.) As noted above, this data structure is a Quadtree. | class Square
constructor: ({@nw, @ne, @se, @sw}) ->
@level = @nw.level + 1
@initialize.apply(this, arguments)
initialize: ->
@for: (quadrants, creator = Square) ->
new creator(quadrants)
_.defaults exports, {Cell, Square} |
The first time throughNow that you've finished the Universe Module, read the Future Module next to understand the core algorithm for computing the future of a pattern. Then move on to the canonicalization and [memoization][memoization] modules to understand how Cafe au Life runs so quickly. Review the garbage collection, menagerie, and API modules at your leisure, they are incidental to the core idea. | |
(c) 2012 Reg Braithwaite (@raganwald) Cafe au Life is freely distributable under the terms of the MIT license. The annotated source code was generated directly from the original source using Docco. | |