Maze solving: Difference between revisions

no edit summary
(implements a solution for solving the mazes in swift)
No edit summary
Line 5,229:
=={{header|Swift}}==
{{works with|Swift|3}}
// The following requires the use of the implementation for [[Maze generation#Swift|generation task]]. Assumes there will be no // circular paths through the maze as the problem suggests.
<br><br>
 
{{code:}}
enum errors: Error {
/// Occurs when a start or end position is given that is outside of bounds
case IndexOutsideMazeBoundary
}
/// Used to solve any maze generated by the swift implementation of maze generator at:
 
/// https://www.rosettacode.org/wiki/Maze_generation#Swift
/// Used to solve any maze generated by the swift implementation of maze generator at:
/// https://www.rosettacode.org/wiki/Maze_generation#Swift
class MazeSolver {
/// your starting index position in the maze
var startPos: (Int, Int)
/// the end index position you are trying to reach within the maze
Line 5,422:
// Reference: https://www.rosettacode.org/wiki/Maze_generation#Swift
// adapts the display method used in the swift implementation of the maze generator we used for this app to display the maze solved
// solved
func displaySolvedMaze(finalPath: [(Int, Int)]) {
/// all cells are 3 wide in the x axis
Line 5,477 ⟶ 5,478:
}
 
{{USE}}
// example implementation using the aforementioned maze generator code for the swift implementation on rosettaCode
 
// let x = 20
// let y = 10
// let maze = MazeGenerator(x, y)
// var solver: MazeSolver = MazeSolver(maze: maze.maze)
 
 
// let x = 20
// for i in 0...5 {
//let y = do {10
// let maze = MazeGenerator(x, y)
// // making sure the start and end pos are within the maze boundary
// var solver: MazeSolver = MazeSolver(maze: maze.maze)
// try solver.solveAndDisplay(startPos: (0, i), endPos: (5+i, 5))
do {
// }
// // making sure the start and end pos are within the maze boundary
// catch errors.IndexOutsideMazeBoundary {
// try solver.solveAndDisplay(startPos: (0, i0), endPos: (5+i, 5))
// print("[ERROR] given start or end point outside of bounds")
// }
// catch errors.IndexOutsideMazeBoundary {
// }
// print("[ERROR] given start or end point outside of bounds")
// }
{{RESULT}}
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| O * | | * * | * * | * * * * * * * * * | |
+---+ + +---+ + + + + +---+---+---+---+---+---+---+ + +---+ +
| * * | | * | * * | * | * | | * * | * * * * | | |
+ +---+---+ + +---+---+ + +---+ + + + +---+---+---+---+ + +
| * | | * | | * * | * * * | * | * * | | |
+ +---+ + + + + +---+---+---+ + +---+---+---+ +---+---+---+ +
| * | | | * * | * * | * * | * * * * | | |
+ + +---+ +---+ +---+ + + +---+---+---+---+ + +---+ +---+ +
| * | | | * * | * | | * | * * * | * * | | | | |
+ + + +---+ +---+ + +---+ + +---+ + +---+ + + + +---+
| * | | | | X * | * * | * | * | * * | | | | | |
+ + +---+ +---+ +---+---+ + + +---+---+---+ + + +---+---+ +
| * | | | | | * | * | * * * | | | |
+ +---+ +---+ +---+---+ + + +---+---+ + +---+---+---+ + + +
| * * | | * * | * * * | | | | |
+---+ + +---+---+---+---+---+---+---+ +---+---+ + +---+ + +---+ +
| | * | | * * * * | * * | * * | | | | | | |
+ + +---+---+ +---+---+ + + +---+ + + + + +---+---+---+ +
| * * * * | * * | * * * | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
 
=={{header|Tcl}}==
Anonymous user