-
Notifications
You must be signed in to change notification settings - Fork 0
LeHast/MazeSolver
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Overall, the code implements a program that reads in a text file containing a maze, finds the start and end points of the maze, and then finds a path through the maze. The program has a main function and a Maze class with several member functions. In the main function, the program checks that two arguments have been provided and then opens the file provided as an argument. The program reads in the maze character by character, adds each row to the Maze object, and then closes the file. Finally, the program calls the Maze object's FindPath function to find a path through the maze. The Maze class has a constructor that initializes the number of rows and columns to zero. It has an AddRow function that accepts a character vector representing a row of the maze and adds the row to the maze array. It also updates the number of rows and columns in the maze. The FindStartEnd function checks the first and last rows and columns of the maze for the start and end points of the maze. If it finds the start and end points, it adds them to a vector of pairs called _cellStart. If it doesn't find the start and end points, the program exits with an error message. The SetStartEnd function accepts two integers representing the row and column of either the start or end point and adds the corresponding cell to the _cellStart vector. If there are already two cells in the vector, the program exits with an error message. The FindPath function first calls FindStartEnd to find the start and end points of the maze. It then initializes variables to represent the current row and column and the start and end cells of the maze. It also initializes a variable to represent the direction that the path is currently traveling. It creates a vector of pairs called tempPath to store the cells that make up the path through the maze. It also creates a copy of the maze array called tempMaze. The function then enters a while loop that continues until it finds a path through the maze or determines that there is no path. In each iteration of the loop, the function checks if it has reached the end cell of the maze. If it has, the function sets the endFound variable to true and breaks out of the loop. If it hasn't reached the end cell, the function attempts to move to the right, down, left, and up in that order. If it finds a cell that it can move to, it pushes that cell onto the tempPath vector, updates the tempMaze array, and updates the current row and column. If it can't find a cell to move to, it pops the last cell off of the tempPath vector and updates the current row and column accordingly. If it can't pop any cells off the tempPath vector, it exits with an error message. If it reaches the end of the loop without finding a path, it exits with an error message.
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published