Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
cellular-automata-rule-parser
Advanced tools
Readme
Parser for Life, Generations, Vote for Life, Wolfram's Elementary CA, Cyclic CA, LUKY and NLUKY rule formats, as well as extended Life and Generations rule formats designed for 3D cellular automata.
With npm do:
npm install cellular-automata-rule-parser
To run the test suite, clone this repository, install the dependencies and run the following command from the root directory:
npm test
var parser = require('cellular-automata-rule-parser');
var rule = parser('S23/B3'); // classic conway's life rule
console.log(rule); // an object describing the rule
console.log(rule.process(0, [0,0,0,0,0,0,0,0])); // 0
console.log(rule.process(0, [1,1,1,0,0,0,0,0])); // 1
console.log(rule.process(1, [1,1,0,0,0,0,0,0])); // 1
console.log(rule.process(1, [1,1,1,1,0,0,0,0])); // 0
rule = parser('23/36'); // highlife
rule = parser('/2/3'); // brian's brain
rule = parser('W30'); // wolfram's rule 30
rule = parser('LUKY 3323'); // conway's life in luky format
The parser function accepts a rule string as argument and returns an object describing the rule with a process function. The process function takes as argument the current value of a cell and a flat array containing all its neighbours. It's the caller's responsibility to provide this array of neighbours.
S23/B3
The S and B are optional.
23/3
Whitespaces can be used freely.
23 / 3
The M and V extensions respectively sets the neighbourhood type to moore
and von Neumann
(the default is moore
).
23 / 3 M
and 23 / 3 V
The range of neighbourhood can be specified after the M/V extension.
23 / 3 M 2
Extended life is a comma separated variant of the S/B format with additional support for ranges of values. The comma separated format allow to use number greater than 9 which is useful for 3D cellular automata.
ES2,3/B3
The S and B are optional, the E isn't.
E2,3/3
Whitespaces can be used freely.
E 2,3 / 3
The M and V extensions respectively sets the neighbourhood type to moore
and von Neumann
(the default is moore
).
E 2,3 / 3 M
and E 2,3 / 3 V
The neighbourhood type can also be defined in full text with 'moore' and 'von-neumann'.
E 2,3 / 3 moore
and E 2,3 / 3 von-neumann
More unconventional neighbourhood types are also accepted : axis
, corner
, edge
and face
.
E 2,3 / 3 axis
and E 2,3 / 3 corner
for example
The range of neighbourhood can be specified after the neighbourhood type.
E 2,3 / 3 M 2
or E 2,3 / 3 moore 2
Ranges of values can be specified with the X..X notation. The following rule matches all the values for 0 to 5 and 7 to 12 for survival.
ES0..5,7..12/B
The extended stochastic format is identical to the extended life with an added notation to add a probability per value or range of values.
The probability of survival or birth, a decimal number between 0 and 1 suffixed with a colon, can be added after the value or range of value.
E 0..5:0.2 / 8:0.95
S6/B246/C3
The S, B and C are optional.
6/246/3
Whitespaces can be used freely.
6 / 246 / 3
The M and V extensions respectively sets the neighbourhood type to moore
and von Neumann
(the default is moore
).
6 / 246 / 3 M
and 6 / 246 / 3 V
The range of neighbourhood can be specified after the M/V extension.
6 / 246 / 3 M 2
Extended life is a comma separated variant of the S/B format with additional support for ranges of values. The comma separated format allow to use number greater than 9 which is useful for 3D cellular automata.
ES2,3/B3/C2
The S, B and C are optional, the E isn't.
E2,3/3/2
Whitespaces can be used freely.
E 2,3 / 3 / 2
The M and V extensions respectively sets the neighbourhood type to moore
and von Neumann
(the default is moore
).
E 2,3 / 3 / 2 M
and E 2,3 / 3 / 2 V
The neighbourhood type can also be defined in full text with 'moore' and 'von-neumann'.
E 2,3 / 3 / 2 moore
and E 2,3 / 3 / 2 von-neumann
More unconventional neighbourhood types are also accepted : axis
, corner
, edge
and face
.
E 2,3 / 3 / 2 axis
and E 2,3 / 3 / 2 corner
for example
The range of neighbourhood can be specified after the neighbourhood type.
E 2,3 / 3 / 2 M 2
or E 2,3 / 3 / 2 moore 2
Ranges of values can be specified with the X..X notation. The following rule matches all the values for 0 to 5 and 7 to 12 for survival.
ES0..5,7..12/B/C2
13579
Whitespaces can be used freely.
1 3 5 7 9
The M and V extensions respectively sets the neighbourhood type to moore
and von Neumann
(the default is moore
).
13579 M
and 13579 V
The range of neighbourhood can be specified after the M/V extension.
13579 M 2
R2/T5/C3/NN
Whitespaces can be used freely.
R2 / T5 / C3 / NN
The Greenberg-Hastings model can be enabled with the GH modifier.
R2 / T5 / C3 / NN / GH
W30
or Rule30
Whitespaces can be used freely.
W 30
or Rule 30
LUKY3323
Whitespaces can be used freely.
LUKY 3 3 2 3
NLUKY03323
Whitespaces can be used freely.
NLUKY 0 3 3 2 3
const
and let
variable declarations).MIT
FAQs
Parser for Life (S/B), Generations (S/B/C), Vote for Life, Wolfram, Cyclic (R/T/C/N), LUKY and NLUKY cellular automata rule formats, as well as extended Life and Generations rule formats designed for 3D cellular automata.
The npm package cellular-automata-rule-parser receives a total of 14 weekly downloads. As such, cellular-automata-rule-parser popularity was classified as not popular.
We found that cellular-automata-rule-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.