A module that helps with finding the longest path in a matrix maxe.
- Source:
Methods
-
<private, static> __expandPath(maze, path, pathsQueue) → {boolean}
-
Expand `path`'s end with one cell and put all those possible combinations into `pathsQueue`.
The path can branch off into at maximum 4 new paths. When a new path is created it's put into the paths queue where the priority is minus the length of the path. `maze` is also updated for each visited cell with `visited=true`. On the other hand, if `path` doesn't have any adjacent unvisited floor cells nothing is done and the function returns `true` which says that `path` has reached a dead end.
Parameters:
Name Type Description maze
Array.<Array.<Object>> A matrix that represents a maze. Properties
Name Type Description wall
boolean visited
boolean path
Array.<Object> The path that should be expanded. Properties
Name Type Description y
number x
number pathsQueue
module:structs/PriorityQueue Where the expanded paths should be put. - Source:
Returns:
If the path has reached a dead end. In this case no new path is added to `pathsQueue`.- Type
- boolean
-
<static> find(maze, start) → {Array.<Object>}
-
Find the longest path in the maze.
Parameters:
Name Type Description maze
Array.<Array.<Object>> A matrix that represents a maze. Properties
Name Type Description wall
boolean Whether it's a wall or a floor. start
Object The start of the path. Properties
Name Type Description y
number Y coordinate. x
number X coordinate. - Source:
Returns:
An array of objects with x and y attributes.- Type
- Array.<Object>