solve_maze {mazing} | R Documentation |
Find a path through a maze
Description
A function that finds the shortest path between points in a maze.
Usage
solve_maze(maze, start = "bottomleft", end = "topright")
Arguments
maze |
A |
start |
The coordinates of the starting point, or a description of a
relative location (see |
end |
The coordinates of the end point, or a description of a relative
location (see |
Details
For the start
and end
arguments (as well as the output
matrix), these coordinates refer to the plotting coordinates, not the
matrix indices. For plotting, the x-coordinate (column index) is listed
first, whereas in matrix notation, the row (y-coordinate) is listed first.
Value
A matrix
containing the coordinates of the path through the
maze. Note that the x-coordinate (column index) comes first, so for the
corresponding indices in the original matrix, these coordinates will need
to be reversed.
Examples
m <- maze(15,15)
p <- solve_maze(m)
plot(m, walls = TRUE)
lines(p, col = 2, lwd = 3)