Conway's Game of life
ES6 JavaScript algorithm implementation.
Installation
You can install Game of life using npm:
npm install -g game-of-life-es6
Usage
Node
var GameOfLife = world = 1 1;
Browser
API
Please check API Documentation for more details.
Rules
The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead. Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:
- Any live cell with fewer than two live neighbours dies, as if caused by under-population.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by overcrowding.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed—births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the preceding one). The rules continue to be applied repeatedly to create further generations.
Good coding pratices
According to Kent Back four rules for a simple system are in order (most important first):
- Run all the tests
- Contain no duplicate code
- Express all the ideas the author wants to express
- Minimize classes and methods
SOLID principles:
- Single Responsibility (SRP):
A class (component) should have one, and only one, reason to change
. - Open-Closed (OCP):
A system should be open for extension, but closed for modification
. - Liskov Substitution (LSP):
Derived types should be substitutable for their base types
. - Interface Segregation (ISP):
Abstractions should not depend upon details. Details should depend upon abstractions
. - Dependency Inversion (DIP):
Interfaces should be small, focused on a specific use case
.
The DRY (Don't Repeat Yourself) Principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
Contributing
Requirements
- Node 0.12.x or io.js 1.x
- grunt-cli: run npm install -g grunt-cli if needed.
- Windows only: remember to set Git and Node path in environment variable %PATH%.
Grunt tasks
grunt dependencies
- helps to update package.json filegrunt spec
- lints the code and runs unit testsgrunt build
- lints the code, runs unit tests, createsdist/bundle.js
transformed ES5 codegrunt
- runsgrunt build
Useful Links
General
Design
- Principles of Object Oriented Design
- Is Design Dead? - article by Martin Fowler
- Don't Repeat Yourself
- XP Simplicty Rules
- Understanding the Four Rules of Simple Design - book by Corey Haines
- The Four Elements of Simple Design
ES6
- Traceur
- An ES6 Module Loader polyfill
- Traceur-TodoMVC – a Backbone.js app written with ES6
- Practical Workflows for ES6 Modules - video by Guy Bedford
- Practical Workflows for ES6 Modules - article by Guy Bedford
- Overview of ECMAScript 6 features
- Classes in ECMAScript 6
- An aggregation of tooling for ES6
- Author In ES6, Transpile To ES5 As A Build-step: A Workflow For Grunt
- Using Grunt & the ES6 Module Transpiler
- ES6 modules today with Babel (6TO5)
- Lint Like It’s 2015 (babel-eslint)