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 maze object.

start

The coordinates of the starting point, or a description of a relative location (see find_maze_refpoint). If not provided, this will be as close as possible to the bottom left corner.

end

The coordinates of the end point, or a description of a relative location (see find_maze_refpoint). If not provided, this will be as close as possible to the top right corner.

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)


[Package mazing version 1.0.5 Index]