maze-algorithms
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -1,2 +0,7 @@ | ||
import Graph from 'tessellatron'; | ||
export declare const iterativeBreadthFirst: (graph: Graph, id: number) => void; | ||
import { Queue } from 'maze-utilities'; | ||
export default class IterativeBreadthFirst { | ||
graph: any; | ||
queue: Queue<number>; | ||
constructor(graph: any, id00?: number); | ||
generator(): Generator; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const maze_utilities_1 = require("maze-utilities"); | ||
exports.iterativeBreadthFirst = (graph, id) => { | ||
// create a queue to iterate with. | ||
// this cannot be modified directly. | ||
// instead, use enqueue, dequeue, and peek. | ||
const queue = new maze_utilities_1.Queue(); | ||
// add initial ID to queue. | ||
queue.enqueue(id); | ||
// loop through stack until it is empty. | ||
while (queue.hasNodes) { | ||
// peek this number from the stack. | ||
const id01 = queue.front(); | ||
// identify current cell. | ||
const cell01 = graph.data[id01]; | ||
// mark self as 'active'. | ||
cell01.status = 'active'; | ||
// TODO: await command to continue. | ||
// ... | ||
// keep track of whether there are unvisited neighbors. | ||
let foundUnvisited = false; | ||
// loop through Cell neighbors in a random order. | ||
const eligibleDirs = Object.keys(cell01.neighbors); | ||
const randomDirs = maze_utilities_1.shuffle(eligibleDirs); | ||
for (const direction of randomDirs) { | ||
// identify the neighbor cell. | ||
const id02 = cell01.neighbors[direction]; | ||
// ensure neighbor exists | ||
if (id02 !== null) { | ||
const cell02 = graph.data[id02]; | ||
// check for unvisited neighbors. | ||
if (cell02.status === 'unvisited') { | ||
// connect the cells | ||
graph.connectNeighbor(direction, id01, id02); | ||
graph.connectPassage(direction, id01, id02); | ||
// transfer 'active' state to id02. | ||
cell01.status = 'passive'; | ||
cell02.status = 'active'; | ||
// TODO: await command to continue. | ||
// ... | ||
// found an unvisited value! | ||
foundUnvisited = true; | ||
// add unvisited neighbor ID to stack. | ||
queue.enqueue(id02); | ||
// remove active status; | ||
// the next ID will become active now. | ||
// eventually, id02 will be called upon again. | ||
cell02.status = 'passive'; | ||
// leave loop early since an unvisited was found. | ||
break; | ||
class IterativeBreadthFirst { | ||
constructor(graph, id00 = 0) { | ||
// take in the graph. | ||
this.graph = graph; | ||
// create a queue to iterate with. | ||
// this cannot be modified directly. | ||
// instead, use enqueue, dequeue, and peek. | ||
this.queue = new maze_utilities_1.Queue(id00); | ||
} | ||
*generator() { | ||
// loop through stack until it is empty. | ||
while (this.queue.hasNodes) { | ||
// peek this number from the stack. | ||
const id01 = this.queue.front(); | ||
// identify current cell. | ||
const cell01 = this.graph.data[id01]; | ||
// mark self as 'active'. | ||
cell01.status = 'active'; | ||
// await command to continue. | ||
yield; | ||
// keep track of whether there are unvisited neighbors. | ||
let foundUnvisited = false; | ||
// loop through Cell neighbors in a random order. | ||
const eligibleDirs = Object.keys(cell01.neighbors); | ||
const randomDirs = maze_utilities_1.shuffle(eligibleDirs); | ||
for (const direction of randomDirs) { | ||
// identify the neighbor cell. | ||
const id02 = cell01.neighbors[direction]; | ||
// ensure neighbor exists | ||
if (id02 !== null) { | ||
const cell02 = this.graph.data[id02]; | ||
// check for unvisited neighbors. | ||
if (cell02.status === 'unvisited') { | ||
// connect the cells | ||
this.graph.connectNeighbor(direction, id01, id02); | ||
this.graph.connectPassage(direction, id01, id02); | ||
// transfer 'active' state to id02. | ||
cell01.status = 'passive'; | ||
cell02.status = 'active'; | ||
// await command to continue. | ||
yield; | ||
// found an unvisited value! | ||
foundUnvisited = true; | ||
// add unvisited neighbor ID to stack. | ||
this.queue.enqueue(id02); | ||
// remove active status; | ||
// the next ID will become active now. | ||
// eventually, id02 will be called upon again. | ||
cell02.status = 'passive'; | ||
// leave loop early since an unvisited was found. | ||
break; | ||
} | ||
} | ||
} | ||
// check if there were no unvisited neighbors. | ||
if (!foundUnvisited) { | ||
// since there were no unvisited neighbors... | ||
// this cell is unequivically complete! | ||
cell01.status = 'complete'; | ||
// remove id01 from the stack. | ||
// id01 is on top, so pop() will remove it. | ||
this.queue.dequeue(); | ||
} | ||
} | ||
// check if there were no unvisited neighbors. | ||
if (!foundUnvisited) { | ||
// since there were no unvisited neighbors... | ||
// this cell is unequivically complete! | ||
cell01.status = 'complete'; | ||
// remove id01 from the stack. | ||
// id01 is on top, so pop() will remove it. | ||
queue.dequeue(); | ||
} | ||
// await command to continue. | ||
yield; | ||
} | ||
}; | ||
} | ||
exports.default = IterativeBreadthFirst; |
@@ -1,2 +0,7 @@ | ||
import Graph from 'tessellatron'; | ||
export declare const iterativeDepthFirst: (graph: Graph, id: number) => void; | ||
import { Stack } from 'maze-utilities'; | ||
export default class IterativeDepthFirst { | ||
graph: any; | ||
stack: Stack<number>; | ||
constructor(graph: any, id00?: number); | ||
generator(): Generator; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const maze_utilities_1 = require("maze-utilities"); | ||
exports.iterativeDepthFirst = (graph, id) => { | ||
// create a stack to iterate through. | ||
// this cannot be modified directly. | ||
// instead, use pop, push, and peek. | ||
const stack = new maze_utilities_1.Stack(); | ||
// add initial ID to stack. | ||
stack.push(id); | ||
// loop through stack until it is empty. | ||
while (stack.hasNodes) { | ||
// peek this number from the stack. | ||
const id01 = stack.peek(); | ||
// identify current cell. | ||
const cell01 = graph.data[id01]; | ||
// mark self as 'active'. | ||
cell01.status = 'active'; | ||
// TODO: await command to continue. | ||
// ... | ||
// keep track of whether there are unvisited neighbors. | ||
let foundUnvisited = false; | ||
// loop through Cell neighbors in a random order. | ||
const eligibleDirs = Object.keys(cell01.neighbors); | ||
const randomDirs = maze_utilities_1.shuffle(eligibleDirs); | ||
for (const direction of randomDirs) { | ||
// identify the neighbor cell. | ||
const id02 = cell01.neighbors[direction]; | ||
// ensure neighbor exists | ||
if (id02 !== null) { | ||
const cell02 = graph.data[id02]; | ||
// check for unvisited neighbors. | ||
if (cell02.status === 'unvisited') { | ||
// connect the cells | ||
graph.connectNeighbor(direction, id01, id02); | ||
graph.connectPassage(direction, id01, id02); | ||
// transfer 'active' state to id02. | ||
cell01.status = 'passive'; | ||
// found an unvisited value! | ||
foundUnvisited = true; | ||
// add unvisited neighbor ID to stack. | ||
stack.push(id02); | ||
// leave loop early since an unvisited was found. | ||
break; | ||
class IterativeDepthFirst { | ||
constructor(graph, id00 = 0) { | ||
// take in the graph. | ||
this.graph = graph; | ||
// create a stack to iterate through. | ||
// this cannot be modified directly. | ||
// instead, use pop, push, and peek. | ||
this.stack = new maze_utilities_1.Stack(id00); | ||
} | ||
*generator() { | ||
// loop through stack until it is empty. | ||
while (this.stack.hasNodes) { | ||
// peek this number from the stack. | ||
const id01 = this.stack.peek(); | ||
// identify current cell. | ||
const cell01 = this.graph.data[id01]; | ||
// mark self as 'active'. | ||
cell01.status = 'active'; | ||
// await command to continue. | ||
yield; | ||
// keep track of whether there are unvisited neighbors. | ||
let foundUnvisited = false; | ||
// loop through Cell neighbors in a random order. | ||
const eligibleDirs = Object.keys(cell01.neighbors); | ||
const randomDirs = maze_utilities_1.shuffle(eligibleDirs); | ||
for (const direction of randomDirs) { | ||
// identify the neighbor cell. | ||
const id02 = cell01.neighbors[direction]; | ||
// ensure neighbor exists | ||
if (id02 !== null) { | ||
const cell02 = this.graph.data[id02]; | ||
// check for unvisited neighbors. | ||
if (cell02.status === 'unvisited') { | ||
// connect the cells | ||
this.graph.connectNeighbor(direction, id01, id02); | ||
this.graph.connectPassage(direction, id01, id02); | ||
// transfer 'active' state to id02. | ||
cell01.status = 'passive'; | ||
// found an unvisited value! | ||
foundUnvisited = true; | ||
// add unvisited neighbor ID to stack. | ||
this.stack.push(id02); | ||
// leave loop early since an unvisited was found. | ||
break; | ||
} | ||
} | ||
} | ||
// check if there were no unvisited neighbors. | ||
if (!foundUnvisited) { | ||
// since there were no unvisited neighbors... | ||
// this cell is unequivically complete! | ||
cell01.status = 'complete'; | ||
// remove id01 from the stack. | ||
// id01 is on top, so pop() will remove it. | ||
this.stack.pop(); | ||
} | ||
} | ||
// check if there were no unvisited neighbors. | ||
if (!foundUnvisited) { | ||
// since there were no unvisited neighbors... | ||
// this cell is unequivically complete! | ||
cell01.status = 'complete'; | ||
// remove id01 from the stack. | ||
// id01 is on top, so pop() will remove it. | ||
stack.pop(); | ||
} | ||
// await command to continue. | ||
yield; | ||
} | ||
}; | ||
} | ||
exports.default = IterativeDepthFirst; |
@@ -1,2 +0,1 @@ | ||
import Graph from 'tessellatron'; | ||
export declare const recursiveDepthFirst: (graph: Graph, id01: number) => void; | ||
export declare const recursiveDepthFirst: (graph: any, id01: number) => void; |
@@ -1,2 +0,2 @@ | ||
import Maze from './maze'; | ||
import Maze from './generator'; | ||
export default Maze; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const maze_1 = require("./maze"); | ||
exports.default = maze_1.default; | ||
const generator_1 = require("./generator"); | ||
exports.default = generator_1.default; | ||
const newMaze = generator_1.default([1, 3, 5]); | ||
const generate = newMaze.generator(); | ||
console.log(newMaze.graph.data[0]); | ||
generate.next(); | ||
generate.next(); | ||
generate.next(); | ||
console.log(newMaze.graph.data[0]); |
{ | ||
"name": "maze-algorithms", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Maze Algorithms provides various functions to create different mazes.", | ||
@@ -26,3 +26,3 @@ "keywords": [ | ||
"maze-utilities": "^1.1.4", | ||
"tessellatron": "^0.1.9" | ||
"tessellatron": "^0.2.0" | ||
}, | ||
@@ -29,0 +29,0 @@ "devDependencies": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15884
340
1
+ Addedtessellatron@0.2.0(transitive)
- Removedtessellatron@0.1.10(transitive)
Updatedtessellatron@^0.2.0