match-n-scanner
Scan the matrix and return parts where equal values are connected.
It is intended to be used for Match 3 games, Match 4 games, .. and others.
Installation
npm install match-n-scanner
Basic usage
const MatchNScanner = ; const matrix = 'A' 'B' 'C' 'D' 'D' 'C' 'C' 'A' 'C'; const scanner = matrix; const matchesAbove3Length = scanner;console;// ->// [ [ { element: 'C', rowIndex: 0, columnIndex: 2 },// { element: 'C', rowIndex: 1, columnIndex: 2 },// { element: 'C', rowIndex: 2, columnIndex: 2 } ] ] const matchesAbove2Length = scanner;console;// ->// [ [ { element: 'C', rowIndex: 0, columnIndex: 2 },// { element: 'C', rowIndex: 1, columnIndex: 2 },// { element: 'C', rowIndex: 2, columnIndex: 2 } ],// [ { element: 'D', rowIndex: 1, columnIndex: 0 },// { element: 'D', rowIndex: 1, columnIndex: 1 } ] ]
APIs
Sorry, see tests or source code for a detailed explanation.
MatchNScanner class
constructor(matrix, options = {})
options: {
// Expression for checking whether elements are equal
equalityChecker?: (elementA, elementB) => boolean,
} = {};
fromText(matrixAsText, options = {})
MatchNScanner instance
scan(options = {})
options: {
// Minimum length to return
minMatchLength?: number,
// If it returns false, this element will be ignored
sieve?: (any) => boolean,
} = {}