maze-generation
Version:
A package to generate mazes using the depth first or hunt and kill algorithm. Mazes can be generated with seed values for reproducibility
114 lines • 4.85 kB
TypeScript
import { Cell, type Visited, type CellJSONRepresentation } from "./Cell.js";
import { Solver } from "./Solver.js";
import type { ColumnRowCoordinate, Direction, Coordinate } from "./types";
export interface NeighbouringCoordinateWithDirection extends Coordinate {
direction: Direction;
}
export type MazeCells = Array<Cell[]>;
type NeighbouringIndicies = {
up?: Coordinate;
down?: Coordinate;
left?: Coordinate;
right?: Coordinate;
};
type CellWithNeighbours = {
firstCell: Coordinate;
neighbours: NeighbouringCoordinateWithDirection[];
};
type MazeJSONRepresentation = {
rows: Array<CellJSONRepresentation[]>;
};
/**
* A class to represent the generated maze. This is made of cells
* @see Cell
*/
export declare class Maze {
cells: MazeCells;
solution: Solver | undefined;
/**
* Constructs a 2D array of cells
* @param {*} width The width of the maze, i.e. how many cells each row contains
* @param {*} height The height of the maze, i.e. how many rows the maze contains
*/
constructor(width: number, height: number);
/**
* Returns if the cell has been visited or not
* @param {*} row The row index of the cell
* @param {*} column The column index ofsolution the cell
* @returns true if the cell has been visited; false if the cell hasn't been visited.
*/
getCellVisited(row: number, column: number): boolean;
/**
* Marks a cell as visited
* @param {*} row The row index of the cell
* @param {*} column The column index of the cell
*/
visitCell(row: number, column: number): void;
/**
* Gets the first unvisited cell in the maze with visited neighbours and returns the cell and the neighbours information
* @returns If true: the first unvisited cell indicies and the indicies of its neighbours; false if no cell with visitedNeighbours exists
*/
getFirstUnvisitedCellWithVisitedNeighbour(): false | CellWithNeighbours;
getUnvisitedCells(): Coordinate[];
getTotalUnvisitedCells(): number;
/**
* Removes the wall of the selected cell
* @param {*} row The row index of the cell
* @param {*} column The column index of the cell
* @param {string} direction left;right;up;down. The wall that should be removed.
*/
removeWall(row: number, column: number, direction: Direction): void;
/**
* Returns if a wall exists in the specified direction
* @param {*} row The row index of the cell
* @param {*} column The column index of the cell
* @param {string} direction left;right;up;down. The wall that should be removed.
* @returns {boolean} true if the wall exists; false if the wall does not exist.
*/
getWallStatus(row: number, column: number, direction: Direction): Visited;
/**
* Gets the indicies of neighbouring cells
* @param {*} row The row index of the cell
* @param {*} column The column index of the cell
* @returns {{[]}} An object containing the indicies of neighbouring cells
*/
getCellNeighbourIndices(row: number, column: number): NeighbouringIndicies;
/**
* Calls getCellNeighbourIndices, checks if each neighbour is unvisited and adds the unvisited cell's coordinates to an array
* @param {*} row The row index of the cell
* @param {*} column The column index of the cell
* @returns {[]} The indicies of unvisited neighours of the chosen cell
*/
getUnvisitedNeigbourIndices(row: number, column: number): NeighbouringCoordinateWithDirection[];
/**
* Calls getCellNeighbourIndices, checks if each neighbour is visited and adds the visited cell's coordinates to an array
* @param {*} row The row index of the cell
* @param {*} column The column index of the cell
* @returns {[]} The indicies of visited neighours of the chosen cell
*/
getVisitedNeigbourIndices(row: number, column: number): NeighbouringCoordinateWithDirection[];
/**
* Generates a solution for the maze
* @param {{row: number, column: number}} start the {row, column} coordinates of the starting cell
* @param {{row: number, column: number}} goal the {row, column} coordinates of the goal cell
*/
generateSolution(start: ColumnRowCoordinate, goal: ColumnRowCoordinate): Solver;
/**
* @returns {string} The string represention of all cells within the maze.
* e.g.
* _ _ _
* | _|
* |_| | |
* | | | |
* |_ _ _|
**/
toString(): string;
/**
* Returns a JSON representation of the maze.
* The JSON object contains a rows array, which contains an array for each row.
* Each row array contains the JSON representations of each cell within the Maze for that row.
*/
toJSON(): MazeJSONRepresentation;
}
export {};
//# sourceMappingURL=Maze.d.ts.map