Anonymous user
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}}
<br><br>
{{code:}}
enum errors: Error {
//
case IndexOutsideMazeBoundary
}
▲/// Used to solve any maze generated by the swift implementation of maze generator at:
▲/// https://www.rosettacode.org/wiki/Maze_generation#Swift
class MazeSolver {
///
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
func displaySolvedMaze(finalPath: [(Int, Int)]) {
/// all cells are 3 wide in the x axis
Line 5,477 ⟶ 5,478:
}
{{USE}}
// let x = 20▼
// let maze = MazeGenerator(x, y)▼
// var solver: MazeSolver = MazeSolver(maze: maze.maze)▼
// // making sure the start and end pos are within the maze boundary▼
// try solver.solveAndDisplay(startPos: (0, i), endPos: (5+i, 5))▼
do {
// }▼
// catch errors.IndexOutsideMazeBoundary {▼
// print("[ERROR] given start or end point outside of bounds")▼
{{RESULT}}
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| O * | | * * | * * | * * * * * * * * * | |
+---+ + +---+ + + + + +---+---+---+---+---+---+---+ + +---+ +
| * * | | * | * * | * | * | | * * | * * * * | | |
+ +---+---+ + +---+---+ + +---+ + + + +---+---+---+---+ + +
| * | | * | | * * | * * * | * | * * | | |
+ +---+ + + + + +---+---+---+ + +---+---+---+ +---+---+---+ +
| * | | | * * | * * | * * | * * * * | | |
+ + +---+ +---+ +---+ + + +---+---+---+---+ + +---+ +---+ +
| * | | | * * | * | | * | * * * | * * | | | | |
+ + + +---+ +---+ + +---+ + +---+ + +---+ + + + +---+
| * | | | | X * | * * | * | * | * * | | | | | |
+ + +---+ +---+ +---+---+ + + +---+---+---+ + + +---+---+ +
| * | | | | | * | * | * * * | | | |
+ +---+ +---+ +---+---+ + + +---+---+ + +---+---+---+ + + +
| * * | | * * | * * * | | | | |
+---+ + +---+---+---+---+---+---+---+ +---+---+ + +---+ + +---+ +
| | * | | * * * * | * * | * * | | | | | | |
+ + +---+---+ +---+---+ + + +---+ + + + + +---+---+---+ +
| * * * * | * * | * * * | | |
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
=={{header|Tcl}}==
|