Name | University Registration | GitHub | |
---|---|---|---|
Daniel Maike Mendes Gonçalves | 16/0117003 | DanMke | [email protected] |
Lucas Pereira de Andrade Macêdo | 15/0137397 | lukassxp | [email protected] |
git clone https://github.com/projeto-de-algoritmos/Graphs-List1-DanielGoncalves-LucasMacedo.git
pip3 install -r requirements.txt --user
python3 graph-list1.py
A maze is a path or collection of paths, typically from an entrance to a goal. The word is used to refer both to branching tour puzzles through which the solver must find a route, and to simpler non-branching patterns that lead unambiguously through a convoluted layout to a goal.
Maze generation is the act of designing the layout of passages and walls within a maze. There are many different approaches to generating mazes, with various maze generation algorithms for building them, either by hand or automatically by computer. There are two main mechanisms used to generate mazes. In "carving passages", one marks out the network of available routes. In building a maze by "adding walls", one lays out a set of obstructions within an open area. Most mazes drawn on paper are done by drawing the walls, with the spaces in between the markings composing the passages.
Maze solving is the act of finding a route through the maze from the start to finish. Some maze solving methods are designed to be used inside the maze by a traveler with no prior knowledge of the maze, whereas others are designed to be used by a person or computer program that can see the whole maze at once. The mathematician Leonhard Euler was one of the first to analyze plane mazes mathematically, and in doing so made the first significant contributions to the branch of mathematics known as topology. Mazes containing no loops are known as "standard", or "perfect" mazes, and are equivalent to a tree in graph theory. Thus many maze solving algorithms are closely related to graph theory. Intuitively, if one pulled and stretched out the paths in the maze in the proper way, the result could be made to resemble a tree.
-
- Make the initial cell the current cell and mark it as visited
- Make the initial cell the current cell and mark it as visited
-
- While there are unvisited cells
-
- If the current cell has any neighbours which have not been visited
-
- Choose randomly one of the unvisited neighbours
- Choose randomly one of the unvisited neighbours
-
- Push the current cell to the stack
- Push the current cell to the stack
-
- Remove the wall between the current cell and the chosen cell
- Remove the wall between the current cell and the chosen cell
-
- Make the chosen cell the current cell and mark it as visited
- Make the chosen cell the current cell and mark it as visited
- If the current cell has any neighbours which have not been visited
-
- Else if stack is not empty
-
- Pop a cell from the stack
- Pop a cell from the stack
-
- Make it the current cell
- Make it the current cell
- Else if stack is not empty
- While there are unvisited cells
-
- Define an initial node, marking as exploited
- Define an initial node, marking as exploited
-
- Add it to the queue
- Add it to the queue
-
- While the queue is not empty and you have not found the end of the maze
-
- Remove the first node from the queue, U
- Remove the first node from the queue, U
-
- For each neighbor V of U
-
- If you have not explored
-
- Mark U as the parent of V
- Mark U as the parent of V
-
- Mark V as explored
- Mark V as explored
-
- Put V at the end of the queue.
- Put V at the end of the queue.
-
- If V is the end of the maze
-
- The end was found
- The end was found
- If V is the end of the maze
- If you have not explored
- For each neighbor V of U
-
- While the queue is not empty and you have not found the end of the maze
-
- Define the current node as the end of the maze
- Define the current node as the end of the maze
-
- While the father of the node's parent is not empty
-
- Assign the current node as your parent, to walk the way back
- Assign the current node as your parent, to walk the way back
- While the father of the node's parent is not empty