I am creating a maze game that is to be traversed and solved by the machine. I have created a maze class that contains the starting and ending positions of the maze as well as the maze itself which is contained in a 2d vector of bools. What I am getting tripped up on is how to actually code moving up and down and across the maze to get to the finish. My starting point is [11][4] in the maze and our professor has told us the best way to move about is to check all 4 locations around the current position and if its true (aka it is a path and not a wall) push it onto the stack. I understand conceptually what this means but I can't visualize how to code it properly, any help would be appreciated. FYI, there is a location struct that simplifies how to express a location.
bool Maze::solve() {
stack<Location> location; //vector to hold location objects/paths
Location current; //will hold current position in maze
current = start; //set current to start position in beginning
location.push(current); //push first maze location (start) onto vector
///need to set current to top of stack; while traversing maze current is top of stack and if current hits (==) finish return true
while (!location.empty()) //while location still has values inside
{
current=location.top();//set current to top of stack
cout << current << endl;
cout << spec[11][4];
if (current==finish) //if current == finish the maze is solved
returntrue;
for loop to start moving around... but how?
}
}
sorry about sloppiness of solve, been trying somethings to understand what is going on.