You are here:

C++/maze in c++


Dear Professor:
I'm sorry to bother you. I have a question from you. My question is about maze. One of my masters wanted us that we research about maze. But whatever I saerch it in the search engine, I coudn't please him, until I found this page in search engine. My master want us that we write a definition for maze and explain about algorithm for solve it and write data structure for save and solve it that works for any mazes. then we have to the program in c++. I hope U answer me. because I don't have any other opportunity to give my master.
Thanks a lot.

Yours truly,

Hello masumeh, thank you for the question.

The most common algorithm to finding the exit of a maze is to move in the immediate direction you can move. If you hit a wall, it doesn't matter, because it will move back out since it can move there. You write a function that checks the space directly north, south, east and west and move that direction, then call the function recursively so it will continue going each way in the maze until it finds the exit. So your function would consist of 4 if checks, then a command to move your player, then calling the function again, with the terminating condition being that if(myPlayer.position == exit.position)

Or something to that extent.

If you have any other questions, please do not hesistate to ask.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2017 All rights reserved.