#' Plots the Dolution of the Maze
#'
#' Draws a line from the start to the finish
#'
#' @param x a maze object
#' @param ... additional parameters for the line command
#'
#' @return NULL
#' @export
#'
#' @examples
#' maze <- makeMazeRecursiveBacktracker()
#' d <- distance(maze)
#' s <- solveMaze(maze, d)
#' plot(maze)
#' plot(d)
#' plot(s)
plot.solution <- function(x, ...){
w <- attributes(x)$width
h <- attributes(x)$height
# Wieviele steps gibt es?
m <- max(x)
# result initialisieren
res <- matrix(0, ncol = 2, nrow = m)
# Vom Ziel zum Start gehen
for(i in 1:m){
res[i,] <- which(x == i, arr.ind = TRUE)
}
# Umdrehen damit ich am Anfang starte
res <- res[m:1,]
# links untere Ecke ist bei 1,1!!!
graphics::lines(res[,2] + 0.5, h - res[,1] + 1.5, ...)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.