-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
26 lines (25 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const Generator = require('./src/Generator');
const Prando = require('prando');
module.exports = (options) => {
let { width, height, seed, algorithm } = options;
if (typeof width === 'undefined' || typeof height === 'undefined') {
throw new Error('An object with the following parameters is required to generate a maze:\n{ height, width, seed (optional), algorithm (optional) }');
}
if (typeof algorithm === 'undefined') {
algorithm = 'DEPTHFIRST';
}
if (typeof seed === 'undefined') {
seed = Math.floor(Math.random() * Math.floor(100000));
}
if (typeof width !== 'number' || typeof height !== 'number') {
throw new Error('Width and height must be numbers');
}
if (width === 0 | height === 0) {
throw new Error('Width and height must be greater than 0');
} else if (width > 3000 || height > 3000) {
throw new Error('Height and width must be a maximum of 3000');
}
const mazeGen = new Generator(width, height);
const prando = new Prando(seed);
return mazeGen.generateMaze(algorithm, prando);
};