2.1.0 • Published 3 years ago
markovjr v2.1.0
MarkovJR.js
As seen on https://github.com/mxgmn/MarkovJunior
> yarn add markjovjrInstallation
> npm install markovjr
> yarn add markovjrAPI
Generate
The generate function applies the rule set to the grid
import { generate } from 'marjovjr'
function generate(model: Model): ModelModel
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 Nth application of a rule.
Rules and Sequences
These are expressed {FROM PATTERN}={TO PATTERN} #[COUNT]
COUNT is optional Examples sequences:
WBB=WAWWill convertWBBtoWAWWBB=WAW #5Will convertWBBtoWAWa maximum for 5 timesBWB/BBB=WWW/WWWWill scan forBWB/BBBwhereBBBis on the row belowBWBBWB BBB=WWW WWWWill scan forBWB BBBwhereBBBis on the row one 'deeper' thanBWB
Rules can contain one or more sequences. Sequences are expressed as arrays.
*is a wildcard- In a
FROMpattern, it will match any character - In
TOpattern, it will leave the character unchanged
- In a
- Any character that isn't a
Coloris treated as transparent FROMandTOpatterns must be equal in length and- Step characters (
/) must occur in the same position inFROMandTOpatterns
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
Wcharacter at thestartcoordinate
- Generate black 2D grids with a single
grid3D({ size: Coord3D, start: Coord3D, char?: string })- Generate black 3D grids with a single
Wcharacter at thestartcoordinate
- Generate black 3D grids with a single
License
MIT