-
Notifications
You must be signed in to change notification settings - Fork 0
/
rulesets.js
70 lines (62 loc) · 1.36 KB
/
rulesets.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function replicatorRules(n) {
return {
diesIf: n % 2 === 0,
bornIf: n % 2 === 1,
includeDiagonals: true,
}
}
function ulamStanislawRules(n) {
return {
diesIf: false,
bornIf: n === 1,
includeDiagonals: false,
}
}
function golRules(n) { // B3/S23
return {
diesIf: !(n === 2 || n === 3),
bornIf: n === 3,
includeDiagonals: true,
}
}
function highLifeRules(n) { //B36 / S23
return {
diesIf: !(n === 2 || n === 3),
bornIf: n === 3 || n === 6,
includeDiagonals: true,
}
}
function seeds(n) {
return {
diesIf: n !== 2,
bornIf: n === 2,
includeDiagonals: true,
}
}
function ruleFromStr(expression) {
let [b, s] = expression.split("/");
b = b.substring(1);
s = s.substring(1);
b = b.split("").map(e => parseInt(e));
s = s.split("").map(e => parseInt(e));
return n => {
return {
diesIf: !s.map(e => (n === e)).reduce((acc, curr) => acc || curr),
bornIf: b.map(e => (n === e)).reduce((acc, curr) => acc || curr),
includeDiagonals: true,
}
}
}
const presets = [
"B1357/S1357",
"B25/S4",
"B3/S012345678",
"B3/S23",
"B34/S34",
"B35678/S5678",
"B36/S125",
"B36/S23",
"B3678/S34678",
"B368/S245",
"B4678/S35678",
];