Maze traversal

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.

location struct
1
2
3
4
5
6
7
8
9
10
11
 struct Location  {
	friend std::ostream &operator <<(std::ostream &os, const Location &location) {
		os << "(" << location.x << ", " << location.y << ")";
		return os;
	}
	bool operator ==(const Location &rhs) const {return x == rhs.x && y == rhs.y;}
	bool operator !=(const Location &rhs) const {return !(*this == rhs);}
	operator bool() const {return x >= 0;}
	Location(int x=-1, int y=-1) : x(x), y(y) {}
	int x, y;
};


maze class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Maze {
	friend std::ostream &operator <<(std::ostream &os, Maze &maze);
	friend Maze load(std::string filename);
public:
    Maze(std::vector<std::vector<bool> > specifics, const Location &startPos, const Location &endPos);
    bool solve();
    //void run();
private:
	bool contains(const Location &location) const;
	bool isPath(const Location &location) const;
	int height() {return spec.size();}
	int width() {return spec[0].size();}
	std::vector<std::vector<bool> > spec;
	Location start, finish;
	Location current;
};


solve function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
            return true;
        for loop to start moving around... but how?
      }
}


sorry about sloppiness of solve, been trying somethings to understand what is going on.
not much point in double-posting mate.
Topic archived. No new replies allowed.