Posts

Showing posts from May, 2017

Conclusion

Image
Actually, I tried a lot of different cases before. I didn't know how many paths between entrance and exit. So I used to want to add missions in my maze, such as the wumpus, I want to add enemy in my maze to limit the solution, however, It's hard to achieve. Because I can't make sure how many solutions first and I also can't limit the choices. So only one solution between entrance and exit is the best choice. So I decided to make that tree model for my project. Which means I set the entrance as the start node and the exit as one of the little branches, so I can make sure only one path.  And I also tried that simple solution that find the way both from entrance and exit. Here is what I got for that: Finally, I used the DFS to figure it out: I learned a lot from my project.

My model

After I choose to use Deep First Search, I make a model for my project. I want to make sure I have only one way between the entrance and the exit. So I thought what would be a tree, I randomly select a grid as a root node, starting from its depth at random search, offer a way to, until no way to go, take a step back and find another way, go to the corner and back to step back and change another one...Such a cycle, until completely no choice...Actually still back also.In the procedure is the following process (see the code in createMaze () function) :Randomly select a grid as a root node, pressing it into the stack.Then when the stack is not empty execute the following cycle:INTREE symbol of take out a grid, it is set to 1, and then will be out of the tree all of its neighbors in the grid pressure into the stack (random order), and the father of the neighbor grid points to the grid.Solve the two problems, the rest of the maze, display path, ball movement is relatively simple.

Final analysis

Image
I had some issues on generating the maze before, I said I couldn't make the random maze every time. Finally I figured out. I have two solutions to make the random maze. First, I wanted to make a simple maze, but I always met some trouble. For example, If I assume that the entrance is top left and exit is bottom right, then I start form the entrance to the exit, pick one from the blue block randomly and go for it, then sign for passing.  Then if I randomly choose to go to the yellow point, I will have three choice for next step because I don't want to go back or have the same path only if I have choice.  But when I come to a died node, which means I can't go anymore, like the red point. I have to go back and find the green point. Then I popped the last point and make a pathlist which means the past points and n-1 is the green point.  However,  if this happened , a bug will happen, means that there is no path for the exit. So we have