-
Notifications
You must be signed in to change notification settings - Fork 5
/
createWorld.js
47 lines (36 loc) · 959 Bytes
/
createWorld.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var classicTransitionRule = require('./classicTransitionRule')
/**
* Create a GoL world.
*
* @param {Function} getNeighboursOf
* @returns {Function} world
*/
function createWorld (getNeighboursOf) {
/**
* @param {Function} [transitionRule] defaults to classis GoL transition rule
* @returns {Function} evolve
*/
function world (transitionRule) {
if (typeof transitionRule === 'undefined') {
transitionRule = classicTransitionRule.bind(null, 2, 3, 3)
}
/**
* @param {Function} isAliveNow
* @returns {Function} isAliveNext
*/
function evolve (isAliveNow) {
var nextStatusOf = transitionRule(getNeighboursOf, isAliveNow)
/**
* @param {*} cell
* @returns {Boolean} status of the cell
*/
function isAliveNext (cell) {
return nextStatusOf(cell)
}
return isAliveNext
}
return evolve
}
return world
}
module.exports = createWorld