16 MapAbstraction::~MapAbstraction()
21 void MapAbstraction::GetRandomTileFromNode(
node *n,
int &x,
int &y)
23 while (GetAbstractionLevel(n) != 0)
24 n = GetNthChild(n, random()%GetNumChildren(n));
29 void MapAbstraction::GetTileFromNode(
node *n,
int &x,
int &y)
31 if (GetAbstractionLevel(n) != 0)
33 GetTileUnderLoc(x, y, GetNodeLoc(n));
34 node *t = GetNodeFromMap(x, y);
35 if (GetNthParent(t, GetAbstractionLevel(n)) == n)
42 while (GetAbstractionLevel(n) != 0)
43 n = GetNthChild(n, 0);
50 void MapAbstraction::ToggleDrawAbstraction(
int which)
52 bool drawThis = ((levelDraw>>which)&0x1);
54 levelDraw |= (1<<which);
56 levelDraw = levelDraw&(~(1<<which));
59 void MapAbstraction::OpenGLDraw()
const
61 for (
unsigned int x = 0; x < abstractions.size(); x++)
63 if ((levelDraw >> x) & 1)
64 DrawGraph(abstractions[x], (x>1)&&((levelDraw>>(x-1))&1));
70 void MapAbstraction::DrawGraph(
Graph *g,
bool drawLevel)
const
113 if (e->GetLabelL(
kEdgeCapacity) == 0) glColor4f(.5, .5, .5, 1);
114 else if (e->GetLabelL(
kEdgeCapacity) <= 0) glColor4f(.2, .2, .2, 1);
115 else if (e->getMarked()) glColor4f(1, 1, 1, 1);
117 glColor4f(1-((GLfloat)(abLevel%15)/15.0), ((GLfloat)(abLevel%15)/15.0), 0, 1);
118 else glColor4f(1-((GLfloat)(abLevel%15)/15.0), ((GLfloat)(abLevel%15)/15.0), 0, 1);
133 recVec rv = GetNodeLoc(n);
134 glVertex3f(rv.
x, rv.
y, rv.
z);
139 glVertex3f(rv.
x, rv.
y, rv.
z);
148 DrawLevelConnections(n);
154 void MapAbstraction::DrawLevelConnections(
node *n)
const
163 glColor4f(.6, .6, .6, .6);
168 glVertex3f(v.
x, v.
y, v.
z);
169 glVertex3f(v1.
x, v1.
y, v1.
z);
175 void MapAbstraction::GetTileUnderLoc(
int &x,
int &y,
const recVec &v)
177 double width = (GetMap()->GetMapWidth()+1)/2.0;
178 double height = (GetMap()->GetMapHeight()+1)/2.0;
181 x = (int)(
width*(v.
x+1.0));
187 recVec MapAbstraction::GetNodeLoc(
node *n)
const
225 ans.
x = ans.
y = ans.
z = 0;
230 recVec tmp = GetNodeLoc(nextChild);
233 ans.
x += weight*tmp.
x;
234 ans.
y += weight*tmp.
y;
235 ans.
z += weight*tmp.
z;
254 void MapAbstraction::ClearMarkedNodes()
256 for (
unsigned int x = 0; x < abstractions.size(); x++)
259 for (
edge *e = abstractions[x]->edgeIterNext(ei); e; e = abstractions[x]->edgeIterNext(ei))
265 double MapAbstraction::h(
node *a,
node *b)
267 if ((a == 0) || (b == 0))
270 recVec rv1 = GetNodeLoc(a);
271 recVec rv2 = GetNodeLoc(b);
272 double answer = OctileDistance((
double)rv1.
x,(
double)rv1.
y,(
double)rv2.
x,(
double)rv2.
y);
278 answer *= GetMap()->GetCoordinateScale();
290 double MapAbstraction::OctileDistance(
double x1,
double y1,
double x2,
double y2)
294 if (fabs(x1-x2) < fabs(y1-y2))
295 answer = root2m1*fabs(x1-x2)+fabs(y1-y2);
297 answer = root2m1*fabs(y1-y2)+fabs(x1-x2);
331 sprintf(name,
"(%d, %d)", x, y);
345 sprintf(name,
"(%d/%d)", x, y);
362 sprintf(name,
"(%d\\%d)", x, y);
403 for (
int x = 0; x < numEdges; x++)
408 ") edges, we're on #" << x <<
" and we got nil!";
409 cout <<
"(node " << n->
GetNum() <<
")" << endl;