Skip to contents

Re-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 maze object, as returned by generate_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 cell A, then BFS from A locates a farthest cell B from it; start = A, end = B.

  • "farthest": keeps the maze's existing start and sets end to the farthest cell from it. This is the same rule generate_maze() uses by default for non-"dfs" algorithms, exposed here so it can be reapplied after the maze has changed (e.g. after braid() or sparsify()).

  • "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 override strategy for 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))