# node-gol-hashlife

0.1.1 • Public • Published

## Use case

Hashlife is an algorithm used to evolve Conway's Game of Life simulation. If you are not familiar with this cellular automata model or other Life-algorithms, you might want to take a look at the following guidelines for using hashlife:

You should use hashlife for:

• Patterns containing a lot of redundancy (sub-patterns that show up often).
• Far-future evolution of the simulation.

Conversely, you shouldn't use hashlife for:

• Highly chaotic patterns.
• Evolving the simulation one generation at a time.
• Memory light execution.

## Installation

Install via npm: `npm install node-gol-hashlife`

The `dist/` directory contains both a normal (`gol.js`) as well as a minified version of the library (`gol.min.js`). Import either into Node.js using `require("gol")` or directly include in the browser using `<script src="gol.min.js"></script>`

## Usage

Lets take a look at a basic example. Say we wish to view the evolution of the glider pattern.

### Create a universe

Universe size is important. The amount of generations we can simulate in the future depends on it. A universe's size is always a power of two, and a universe with size 2n can simulate 2n - 2 generations ahead.

Suppose we are interested in the glider's evolution two generations into the future. For that, we will need a universe of size 8x8, since 8 = 2^3 which means we can now simulate the pattern 2(3 - 1) generations ahead.

### Set initial pattern

Now that we have an empty universe, lets populate it with the initial glider pattern:

### Simulate and inspect

Now that we have the glider in the universe, lets inspect its evolution. The simulation object allows us to view generations that are a power of two ahead in time:

Note that the hashlife algorithm evaluates this future state for the central quadrant of the universe. In our case we evaluated cells from (-2, -2) up to (2, 2) two generations into the future. Had we wanted to evaluate a larger neighbourhood, we'd need a larger universe.

## Package Sidebar

### Install

`npm i node-gol-hashlife`

### Repository

github.com/rharel/node-gol-hashlife

### Homepage

github.com/rharel/node-gol-hashlife

1

0.1.1