Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kjirou/match-n-scanner
Scan the matrix and return parts where equal values are connected
https://github.com/kjirou/match-n-scanner
game-development javascript match-3 nodejs
Last synced: 12 days ago
JSON representation
Scan the matrix and return parts where equal values are connected
- Host: GitHub
- URL: https://github.com/kjirou/match-n-scanner
- Owner: kjirou
- License: mit
- Created: 2017-08-26T02:53:57.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-08-31T07:15:40.000Z (about 3 years ago)
- Last Synced: 2024-10-06T08:37:59.210Z (about 1 month ago)
- Topics: game-development, javascript, match-3, nodejs
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/match-n-scanner
- Size: 22.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# match-n-scanner
[![npm version](https://badge.fury.io/js/match-n-scanner.svg)](https://badge.fury.io/js/match-n-scanner)
[![CircleCI](https://circleci.com/gh/kjirou/match-n-scanner.svg?style=svg)](https://circleci.com/gh/kjirou/match-n-scanner)
[![Build Status](https://travis-ci.org/kjirou/match-n-scanner.svg?branch=master)](https://travis-ci.org/kjirou/match-n-scanner)Scan the matrix and return parts where equal values are connected.
It is intended to be used for [Match 3 games](https://en.wikipedia.org/wiki/Category:Match_3_games), Match 4 games, .. and others.
## Installation
```bash
npm install match-n-scanner
```## Basic usage
```js
const MatchNScanner = require('match-n-scanner');const matrix = [
['A', 'B', 'C'],
['D', 'D', 'C'],
['C', 'A', 'C'],
];const scanner = new MatchNScanner(matrix);
const matchesOf3OrMore = scanner.scan({minMatchLength: 3});
console.log(matchesOf3OrMore);
// ->
// [ [ { element: 'C', rowIndex: 0, columnIndex: 2 },
// { element: 'C', rowIndex: 1, columnIndex: 2 },
// { element: 'C', rowIndex: 2, columnIndex: 2 } ] ]const matchesOf2OrMore = scanner.scan({minMatchLength: 2});
console.log(matchesOf2OrMore);
// ->
// [ [ { 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](/test/lib/MatchNScanner.js) or [source code](/lib/MatchNScanner.js) 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,
} = {}
```