markovjr
v2.1.0
Published
[Demo](https://seikho.github.io/markovjr)
Downloads
14
Readme
MarkovJR.js
As seen on https://github.com/mxgmn/MarkovJunior
> yarn add markjovjr
Installation
> npm install markovjr
> yarn add markovjr
API
Generate
The generate
function applies the rule set to the grid
import { generate } from 'marjovjr'
function generate(model: Model): Model
Model
Grids must be Cubes of Cuboids:
- All string lengths must be equal
- All array lengths across the Z-dimension must be equal
interface Model {
type: '2d' | '3d'
grid: string[] | Array<string[]>
rules: Rule[]
log?: { frequency: number }
}
Passing log: { frequency }
will print out the current representation of the grid every N
th application of a rule.
Rules and Sequences
These are expressed {FROM PATTERN}={TO PATTERN} #[COUNT]
COUNT is optional Examples sequences:
WBB=WAW
Will convertWBB
toWAW
WBB=WAW #5
Will convertWBB
toWAW
a maximum for 5 timesBWB/BBB=WWW/WWW
Will scan forBWB/BBB
whereBBB
is on the row belowBWB
BWB BBB=WWW WWW
Will scan forBWB BBB
whereBBB
is on the row one 'deeper' thanBWB
Rules can contain one or more sequences. Sequences are expressed as arrays.
*
is a wildcard- In a
FROM
pattern, it will match any character - In
TO
pattern, it will leave the character unchanged
- In a
- Any character that isn't a
Color
is treated as transparent FROM
andTO
patterns must be equal in length and- Step characters (
/
) must occur in the same position inFROM
andTO
patterns
type Rule = string | string[]
type Color = 'B' | 'I' | 'P' | 'E' | 'N' | 'D' | 'A' | 'W' | 'R' | 'O' | 'Y' | 'G' | 'U' | 'S' | 'K' | 'F'
const model: Model2D = {
type: '2d',
// Grids are strings of Colors
grid: ['BWBBBB', 'BBBBBB', 'BBBBBB', 'BBBBBB', 'BBBBBB', 'BBBBBB'],
rules: ['WBB=WAW', ['A=W', 'B=R']],
}
Utility Functions
type Coord2D = [number, number]
type Coord3D = [number, number, number]
grid2D({ size: Coord2D, start: Coord2D, char?: string })
- Generate black 2D grids with a single
W
character at thestart
coordinate
- Generate black 2D grids with a single
grid3D({ size: Coord3D, start: Coord3D, char?: string })
- Generate black 3D grids with a single
W
character at thestart
coordinate
- Generate black 3D grids with a single
License
MIT