Ok, here is what I am attempting.
I have a map (2D array) of the inside of a building for part of my project. The 'working' areas of this map are corridors etc. This working area is divided into zones and there are interfaces between each zone. So for example there could be a corridor zone and a room zone with the doorway as the interface. The interfaces also double up as waypoints, I just assigned 2 different names in case I got confused. Here are the classes I have contructed:
Code:
class waypoints
{
private:
int *w_coordinates;
int number_of_w_squares;
zone *zone1;
zone *zone2;
public:
void set_w_coordinates(int pos_x, int pos_y, int a);
void setup(int num_squares, zone &a, zone &b);
zone* GetZone1();
zone* GetZone2();
~waypoints();
}w_1,w_2,w_3,w_4;
class zone
{
private:
int number_of_squares, number_of_interfaces;
int *coordinates;
public:
void setup(int a, int b);
void set_coordinates(int i, int pos_x, int pos_y);
void set_interfaces(waypoints b);
bool IsInZone(int x, int y);
int GetSquaresNumber();
int GetSquareCoordinate(int i);
vector <waypoints> interfaces;
~zone();
};
As I hope can be determined, a zone has a vector of all it's intefaces (A corridor can have many rooms and other corridors attached to it). The waypoints class has 2 pointers to zones (one zone either side).
I am trying to implement a search algorithm that, given start and end coordinates, will populate a vector of zones with the correct sequence of zones (assuming only one route is possible) to get from start to finish.
I have begun a function here:
Code:
FindZoneRoute(int startx, int endx, int starty, int endy)
{
vector<zone *> zone_route;
for (vector<waypoints>::iterator wi=GetZone(startx,starty).interfaces.begin(),wi != GetZone(startx,starty).interfaces.end(),wi++)
{
if (!CompareZones(wi->GetZone1(),¤t))
{
}
if (!CompareZones(wi->GetZone2(),¤t))
{
}
}
}
GetZone() returns the zone containing the coordinates given.
GetZone1() and GetZone2() return the pointer to zone1 or zone2 respectively held in the zone class.
CompareZones() returns true if the zones passed into it are the same. The if(!CompareZones()) is used so that I don't end up going backwards.
Please bear with me if I clearly haven't got a clue or if my code sucks, I don't know if I am in the right forest, yet alone barking up the right tree!
Any help or guidance would be great, I am lost on this. Thanks