Choose new start/end cells for a maze
set_endpoints.RdRe-labels the start and end cells recorded on a maze
object, without touching its passages. Several strategies are available
for picking cells automatically, and an explicit start and/or
end overrides the chosen strategy for that endpoint.
Usage
set_endpoints(maze, strategy = c("longest", "corners", "random", "farthest"),
start = NULL, end = NULL)Arguments
- maze
A
mazeobject, as returned bygenerate_maze().- strategy
One of
"longest","farthest","corners", or"random":"longest"(the default): finds the true longest shortest path in the maze (its diameter) via double breadth-first search – BFS from an arbitrary cell locates a farthest cellA, then BFS fromAlocates a farthest cellBfrom it;start = A,end = B."farthest": keeps the maze's existingstartand setsendto the farthest cell from it. This is the same rulegenerate_maze()uses by default for non-"dfs"algorithms, exposed here so it can be reapplied after the maze has changed (e.g. afterbraid()orsparsify())."corners":start = c(1, 1),end = c(rows, cols)."random": two distinct, uniformly chosen cells.
- start, end
Optional
c(row, column)positions. When supplied, they overridestrategyfor that endpoint (validated to lie inside the maze).
Value
A modified maze object of class maze, with start
and/or end replaced. All other fields, including passages,
are unchanged.
Examples
maze <- generate_maze(10, 10, seed = 42)
longest <- set_endpoints(maze, "longest")
corners <- set_endpoints(maze, "corners")
fixed <- set_endpoints(maze, start = c(1, 1), end = c(2, 2))