| Title: | A package for generating mazes |
|---|---|
| Description: | A package for generating mazes in R. |
| Authors: | Vesna Memisevic [aut, cre] |
| Maintainer: | Vesna Memisevic <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-20 06:37:30 UTC |
| Source: | https://github.com/kbroman/Rmaze |
Create a connected maze graph that represents a rectangular grid. Nodes represent cells and edges betweem nodes represent wall sites. All walls are initially on.
makeGraph(nrows = 0, ncols = 0)makeGraph(nrows = 0, ncols = 0)
nrows |
maze hight (number of rows); default value set to 0. |
ncols |
maze width (number of columns); default value set to 0. |
This function creates and returns a maze graph that represents a rectangular grid that matches user specified maze dimensions. Nodes in the graph will be named in the format Aij, where i corresponds to a row number and j corresponds to a column number.
maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1) plotMaze(maze1, 10, 10)maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1) plotMaze(maze1, 10, 10)
Given a perfect maze graph, create an imperfect maze graph.
makeImperfect(gD = NA, ptc = 20, inShiny = FALSE)makeImperfect(gD = NA, ptc = 20, inShiny = FALSE)
gD |
an existing maze graph object. |
ptc |
percentage of walls to randomly add or remove; default value is 10(percent). |
inShiny |
a flag that marks whether the function is called from a shiny app or console. |
A maze graph object containing an imperfect maze.
maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1) plotMaze(maze1, 10, 10) maze1 <- makeImperfect(maze1) plotMaze(maze1, 10, 10)maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1) plotMaze(maze1, 10, 10) maze1 <- makeImperfect(maze1) plotMaze(maze1, 10, 10)
Create a maze uzing a randomized version of depth-first search algorithm (recursive backtracker).
makeMaze_dfs(gD = NA, stepBystep = FALSE, nrows = 0, ncols = 0, inShiny = FALSE)makeMaze_dfs(gD = NA, stepBystep = FALSE, nrows = 0, ncols = 0, inShiny = FALSE)
gD |
an existing maze graph object. |
stepBystep |
a flag that will allow a step by step plot of maze creation |
nrows |
maze hight (number of rows); required only for the step by step plot; default value set to 0. |
ncols |
maze width (number of columns); required only for the step by step plot; default value set to 0. |
inShiny |
a flag that marks whether the function is called from a shiny app or console |
Given a connected maze graph (with all walls on), this function creates a maze (removes some walls) using depth-first search algorithm (recursive backtracker), and returns the resulting maze graph.
maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1) plotMaze(maze1, 10, 10)maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1) plotMaze(maze1, 10, 10)
Create a maze uzing a randomized Kruskal's algorithm.
makeMaze_kruskal(gD = NA, stepBystep = FALSE, nrows = 0, ncols = 0, inShiny = FALSE)makeMaze_kruskal(gD = NA, stepBystep = FALSE, nrows = 0, ncols = 0, inShiny = FALSE)
gD |
an existing maze graph object. |
stepBystep |
a flag that will allow a step by step plot of maze creation |
nrows |
maze hight (number of rows); required only for the step by step plot; default value set to 0. |
ncols |
maze width (number of columns); required only for the step by step plot; default value set to 0. |
inShiny |
a flag that marks whether the function is called from a shiny app or console |
Given a connected maze graph (with all walls on), this function creates a maze (removes some walls) using depth-first search algorithm (recursive backtracker), and returns the resulting maze graph.
maze1 <- makeGraph(10, 10) maze1 <- makeMaze_kruskal(maze1) plotMaze(maze1, 10, 10)maze1 <- makeGraph(10, 10) maze1 <- makeMaze_kruskal(maze1) plotMaze(maze1, 10, 10)
Create a maze uzing a randomized Prim's algorithm.
makeMaze_prim(gD = NA, stepBystep = FALSE, nrows = 0, ncols = 0, inShiny = FALSE)makeMaze_prim(gD = NA, stepBystep = FALSE, nrows = 0, ncols = 0, inShiny = FALSE)
gD |
an existing maze graph object. |
stepBystep |
a flag that will allow a step by step plot of maze creation |
nrows |
maze hight (number of rows); required only for the step by step plot; default value set to 0. |
ncols |
maze width (number of columns); required only for the step by step plot; default value set to 0. |
inShiny |
a flag that marks whether the function is called from a shiny app or console |
Given a connected maze graph (with all walls on), this function creates a maze (removes some walls) using depth-first search algorithm (recursive backtracker), and returns the resulting maze graph.
maze1 <- makeGraph(10, 10) maze1 <- makeMaze_prim(maze1) plotMaze(maze1, 10, 10)maze1 <- makeGraph(10, 10) maze1 <- makeMaze_prim(maze1) plotMaze(maze1, 10, 10)
Given a maze graph, plot a maze.
plotMaze(gD = NA, nrows = 0, ncols = 0, inShiny = FALSE)plotMaze(gD = NA, nrows = 0, ncols = 0, inShiny = FALSE)
gD |
an existing maze graph object. |
nrows |
maze hight (number of rows); default value set to 0. |
ncols |
maze width (number of columns); default value set to 0. |
inShiny |
a flag that marks whether the function is called from a shiny app or console |
This function uses ggplot to plot a maze. Currently, maze enterance and exit points (cells/nodes) are fixed.
maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1) plotMaze(maze1, 10, 10)maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1) plotMaze(maze1, 10, 10)
Plot maze solution (path)
plotMazeSolution(gD = NA, nrows = 0, ncols = 0, inShiny = FALSE)plotMazeSolution(gD = NA, nrows = 0, ncols = 0, inShiny = FALSE)
gD |
an existing maze graph object. |
nrows |
maze hight (number of rows); default value set to 0. |
ncols |
maze width (number of columns); default value set to 0. |
inShiny |
a flag that marks whether the function is called from a shiny app or console. |
The maze solution is found as the shortest path between the start and end maze cells (currently, start and end points of the maze are fixed). The function uses ggplot to plot a maze.
maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1) plotMaze(maze1, 10, 10) plotMazeSolution(maze1, 10, 10)maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1) plotMaze(maze1, 10, 10) plotMazeSolution(maze1, 10, 10)
A function to start a Shiny app that comes with the package. Code from: http://www.r-bloggers.com/supplementing-your-r-package-with-a-shiny-app-2/
runExample()runExample()
Rmaze::runExample()Rmaze::runExample()
Plot maze solution (path)
stepByStepMAze(gD = NA, nrows = 0, ncols = 0, inShiny = FALSE)stepByStepMAze(gD = NA, nrows = 0, ncols = 0, inShiny = FALSE)
gD |
an existing maze graph object. |
nrows |
maze hight (number of rows); default value set to 0. |
ncols |
maze width (number of columns); default value set to 0. |
inShiny |
a flag that marks whether the function is called from a shiny app or console. |
The maze solution is found as the shortest path between the start and end maze cells (currently, start and end points of the maze are fixed). The function uses ggplot to plot a maze.
maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1, stepBystep = TRUE, nrows=10, ncols=10)maze1 <- makeGraph(10, 10) maze1 <- makeMaze_dfs(maze1, stepBystep = TRUE, nrows=10, ncols=10)