22 fourConnected =
false;
39 bool n1 =
false, s1 =
false, e1 =
false, w1 =
false;
41 int w = map->GetMapWidth();
42 int h = map->GetMapHeight();
45 printf(
"Four connected not implemented!\n");
53 bool a =
false, b =
false;
74 bool a =
false, b =
false;
95 bool a =
false, b =
false;
116 bool a =
false, b =
false;
168 std::vector<xyLoc> oneSuccessor;
169 std::vector<xyLoc> multipleSuccessors;
170 std::vector<xyLoc> succ;
172 multipleSuccessors.push_back(
loc);
173 while (multipleSuccessors.size() > 0)
175 xyLoc tmp = multipleSuccessors.back();
176 multipleSuccessors.pop_back();
177 GetSuccessors(tmp, succ);
178 if (succ.size() == 1)
180 oneSuccessor.push_back(succ[0]);
182 else if (succ.size() > 0) {
183 multipleSuccessors.insert( multipleSuccessors.end(), succ.begin(),succ.end());
186 while (oneSuccessor.size() > 0)
188 xyLoc tmp = oneSuccessor.back();
189 oneSuccessor.pop_back();
190 GetSuccessors(tmp, succ);
191 if (succ.size() == 1)
193 oneSuccessor.push_back(succ[0]);
195 else if (succ.size() > 0){
196 neighbors.push_back(tmp);
204 bool n1 =
false, s1 =
false, e1 =
false, w1 =
false;
206 int w = map->GetMapWidth();
207 int h = map->GetMapHeight();
210 printf(
"Four connected not implemented!\n");
280 bool up=
false, down=
false;
284 actions.push_back(
kS);
289 actions.push_back(
kN);
296 actions.push_back(
kNW);
298 actions.push_back(
kSW);
300 actions.push_back(
kW);
307 actions.push_back(
kNE);
309 actions.push_back(
kSE);
311 actions.push_back(
kE);
320 case -1: result =
kE;
break;
322 case 1: result =
kW;
break;
329 case -1: result = result|
kS;
break;
331 case 1: result = result|
kN;
break;
340 case kN: a =
kS;
break;
342 case kE: a =
kW;
break;
344 case kS: a =
kN;
break;
346 case kW: a =
kE;
break;
358 case kN: s.
y-=1;
break;
359 case kS: s.
y+=1;
break;
360 case kE: s.
x+=1;
break;
361 case kW: s.
x-=1;
break;
362 case kNW: s.
y-=1; s.
x-=1;
break;
363 case kSW: s.
y+=1; s.
x-=1;
break;
364 case kNE: s.
y-=1; s.
x+=1;
break;
365 case kSE: s.
y+=1; s.
x+=1;
break;
375 h1 = abs(l1.
x-l2.
x)+abs(l1.
y-l2.
y);
378 double a = ((l1.
x>l2.
x)?(l1.
x-l2.
x):(l2.
x-l1.
x));
379 double b = ((l1.
y>l2.
y)?(l1.
y-l2.
y):(l2.
y-l1.
y));
381 h1 = (a>b)?(b*DIAGONAL_COST+a-b):(a*DIAGONAL_COST+b-a);
389 const double multiplier = 1.0;
392 case kN:
return 1.0*multiplier;
393 case kS:
return 1.0*multiplier;
394 case kE:
return 1.0*multiplier;
395 case kW:
return 1.0*multiplier;
396 case kNW:
return DIAGONAL_COST*multiplier;
397 case kSW:
return DIAGONAL_COST*multiplier;
398 case kNE:
return DIAGONAL_COST*multiplier;
399 case kSE:
return DIAGONAL_COST*multiplier;
407 const double multiplier = 1.0;
408 if (l1.
x == l2.
x)
return 1.0*multiplier;
409 if (l1.
y == l2.
y)
return 1.0*multiplier;
410 if (l1 == l2)
return 0.0;
411 return DIAGONAL_COST*multiplier;
416 return ((
node.x == goal.
x) && (
node.y == goal.
y));
421 return map->GetMapHeight()*map->GetMapWidth();
427 return node.y*map->GetMapWidth()+
node.x;
434 return (uint32_t) act;
444 GLdouble xx, yy, zz, rad;
445 map->GetOpenGLCoord(l.
x, l.
y, xx, yy, zz, rad);
448 glColor4f(r, g, b, t);
457 GLdouble xx, yy, zz, rad;
458 GLdouble xx2, yy2, zz2;
459 map->GetOpenGLCoord(l1.
x, l1.
y, xx, yy, zz, rad);
460 map->GetOpenGLCoord(l2.
x, l2.
y, xx2, yy2, zz2, rad);
466 glColor4f(r, g, b, t);
475 GLdouble xx, yy, zz, rad;
476 map->GetOpenGLCoord(s.
x, s.
y, xx, yy, zz, rad);
478 glColor3f(0.5, 0.5, 0.5);
479 glBegin(GL_LINE_STRIP);
480 glVertex3f(xx, yy, zz-rad/2);
484 case kN: s.
y-=1;
break;
485 case kS: s.
y+=1;
break;
486 case kE: s.
x+=1;
break;
487 case kW: s.
x-=1;
break;
488 case kNW: s.
y-=1; s.
x-=1;
break;
489 case kSW: s.
y+=1; s.
x-=1;
break;
490 case kNE: s.
y-=1; s.
x+=1;
break;
491 case kSE: s.
y+=1; s.
x+=1;
break;
496 map->GetOpenGLCoord(s.
x, s.
y, xx, yy, zz, rad);
497 glVertex3f(xx, yy, zz-rad/2);
504 GLdouble xx1, yy1, zz1, rad;
505 GLdouble xx2, yy2, zz2;
506 map->GetOpenGLCoord(a.
x, a.
y, xx1, yy1, zz1, rad);
507 map->GetOpenGLCoord(b.
x, b.
y, xx2, yy2, zz2, rad);
509 double angle = atan2(yy1-yy2, xx1-xx2);
510 double xoff = sin(2*
PI-angle)*rad*0.1;
511 double yoff = cos(2*
PI-angle)*rad*0.1;
515 GLfloat rr, gg, bb, t;
517 glColor4f(rr, gg, bb, t);
519 glBegin(GL_TRIANGLE_STRIP);
521 glVertex3f(xx1+xoff, yy1+yoff, zz1-rad/2);
522 glVertex3f(xx2+xoff, yy2+yoff, zz2-rad/2);
523 glVertex3f(xx1-xoff, yy1-yoff, zz1-rad/2);
524 glVertex3f(xx2-xoff, yy2-yoff, zz2-rad/2);
532 GLdouble xx, yy, zz, rad;
533 map->GetOpenGLCoord(s.
x, s.
y, xx, yy, zz, rad);
536 glColor4f(r, g, b, t);
538 glTranslatef(xx-rad, yy+rad/2, zz-2*rad);
539 glScalef(scale*rad/(300.0), scale*rad/300.0, 1);
540 glRotatef(180, 0.0, 0.0, 1.0);
541 glRotatef(180, 0.0, 1.0, 0.0);
542 glDisable(GL_LIGHTING);
543 auto len = strlen(str);
546 glEnable(GL_LIGHTING);
554 GLdouble xx, yy, zz, rad;
555 map->GetOpenGLCoord(s.
x, s.
y, xx, yy, zz, rad);
558 glColor4f(r, g, b, t);
560 glTranslatef(xx-rad, yy+rad/2, zz-rad);
561 glScalef(rad/(300.0), rad/300.0, 1);
562 glRotatef(180, 0.0, 0.0, 1.0);
563 glRotatef(180, 0.0, 1.0, 0.0);
564 glDisable(GL_LIGHTING);
567 glEnable(GL_LIGHTING);
575 s =
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width = \""+std::to_string(10*map->GetMapWidth())+
"\" height = \""+std::to_string(10*map->GetMapHeight())+
"\" ";
576 s +=
"viewBox=\""+std::to_string(-map->GetMapWidth())+
" "+std::to_string(-map->GetMapHeight())+
" ";
577 s += std::to_string(12*map->GetMapWidth())+
" "+std::to_string(12*map->GetMapHeight())+
"\" ";
578 s +=
"preserveAspectRatio = \"none\" ";
589 for (
int y = 0; y < map->GetMapHeight(); y++)
591 for (
int x = 0; x < map->GetMapWidth(); x++)
594 if (map->GetTerrainType(x, y) ==
kGround)
600 else if (map->GetTerrainType(x, y) ==
kTrees)
606 else if (map->GetTerrainType(x, y) ==
kWater)
612 else if (map->GetTerrainType(x, y) ==
kSwamp)
625 for (
int y = 0; y < map->GetMapHeight(); y++)
627 for (
int x = 0; x < map->GetMapWidth(); x++)
640 for (
int y = 0; y < map->GetMapHeight(); y++)
642 for (
int x = 0; x < map->GetMapWidth(); x++)
645 if (map->GetTerrainType(x, y) ==
kGround)
647 if (x == map->GetMapWidth()-1)
649 if (y == map->GetMapHeight()-1)
652 else if (map->GetTerrainType(x, y) ==
kTrees)
654 if (x == map->GetMapWidth()-1)
656 if (y == map->GetMapHeight()-1)
659 else if (map->GetTerrainType(x, y) ==
kWater)
661 if (x == map->GetMapWidth()-1)
663 if (y == map->GetMapHeight()-1)
666 else if (map->GetTerrainType(x, y) ==
kSwamp)
675 SetColor(0.0, 0.0, 0.0);
678 if (map->GetTerrainType(x, y) != map->GetTerrainType(x-1, y))
680 SetColor(0.0, 0.0, 0.0);
685 if (map->GetTerrainType(x, y) != map->GetTerrainType(x, y-1))
691 if (map->GetTerrainType(x, y) != map->GetTerrainType(x+1, y))
697 if (map->GetTerrainType(x, y) != map->GetTerrainType(x, y+1))
714 if (map->GetTerrainType(l.
x, l.
y) ==
kGround)
778 std::deque<xyLoc> queue;
780 std::vector<xyLoc> v;
781 std::vector<bool> visited(map->GetMapHeight()*map->GetMapWidth());
782 while (!queue.empty())
784 GetBasicSuccessors(queue.front(), v);
787 if (!visited[s.x+s.y*map->GetMapWidth()])
797 map->GetOpenGLCoord(queue.front().x, queue.front().y, x, y, z, r);
804 map->GetOpenGLCoord(s.x, s.y, x, y, z, r);
809 visited[s.x+s.y*map->GetMapWidth()] =
true;
825 std::deque<xyLoc> queue;
827 std::vector<xyLoc> v;
828 std::vector<bool> visited(map->GetMapHeight()*map->GetMapWidth());
829 while (!queue.empty())
831 GetSuccessors(queue.front(), v);
834 if (!visited[s.x+s.y*map->GetMapWidth()])
844 map->GetOpenGLCoord(queue.front().x, queue.front().y, x, y, z, r);
851 map->GetOpenGLCoord(s.x, s.y, x, y, z, r);
856 visited[s.x+s.y*map->GetMapWidth()] =
true;
881 for (
int y = 0; y < map->GetMapHeight(); y++)
883 for (
int x = 0; x < map->GetMapWidth(); x++)
887 GLdouble px, py, t, rad;
888 map->GetOpenGLCoord(x, y, px, py, t, rad);
894 if (map->GetTerrainType(x, y) ==
kGround)
899 else if (map->GetTerrainType(x, y) ==
kTrees)
904 else if (map->GetTerrainType(x, y) ==
kWater)
909 else if (map->GetTerrainType(x, y) ==
kSwamp)
924 for (
int y = 0; y < map->GetMapHeight(); y++)
926 for (
int x = 0; x < map->GetMapWidth(); x++)
933 GLdouble px, py, t, rad;
934 map->GetOpenGLCoord(x, y, px, py, t, rad);
947 std::vector<std::pair<point, point>> lines;
948 for (
int y = 0; y < map->GetMapHeight(); y++)
950 for (
int x = 0; x < map->GetMapWidth(); x++)
952 GLdouble
px1,
py1, t1, rad1;
953 map->GetOpenGLCoord(x, y,
px1,
py1, t1, rad1);
954 float px=
static_cast<float>(
px1);
955 float py=
static_cast<float>(
py1);
956 float t=
static_cast<float>(t1);
957 float rad=
static_cast<float>(rad1);
960 if ((map->GetTerrainType(x, y) ==
kGround) ||
961 (map->GetTerrainType(x, y) ==
kTrees) ||
962 (map->GetTerrainType(x, y) ==
kWater))
964 if (x == map->GetMapWidth()-1)
966 point s = {px+rad, py-rad};
967 point g = {px+rad, py+rad};
969 lines.push_back({s, g});
971 if (y == map->GetMapHeight()-1)
973 point s = {px-rad, py+rad};
974 point g = {px+rad, py+rad};
976 lines.push_back({s, g});
979 else if (map->GetTerrainType(x, y) ==
kSwamp)
989 if (map->GetTerrainType(x, y) != map->GetTerrainType(x-1, y))
991 point s = {px-rad, py-rad};
992 point g = {px-rad, py+rad};
994 lines.push_back({s, g});
997 if (map->GetTerrainType(x, y) != map->GetTerrainType(x, y-1))
999 point s = {px-rad, py-rad};
1000 point g = {px+rad, py-rad};
1002 lines.push_back({s, g});
1005 if (map->GetTerrainType(x, y) != map->GetTerrainType(x+1, y))
1007 point s = {px+rad, py-rad};
1008 point g = {px+rad, py+rad};
1010 lines.push_back({s, g});
1013 if (map->GetTerrainType(x, y) != map->GetTerrainType(x, y+1))
1015 point s = {px-rad, py+rad};
1016 point g = {px+rad, py+rad};
1018 lines.push_back({s, g});
1024 std::vector<point> points;
1025 while (lines.size() > 0)
1029 points.push_back(lines.back().first);
1030 points.push_back(lines.back().second);
1035 for (
size_t x = 0; x < lines.size(); x++)
1037 if (lines[x].first == points.back())
1039 points.push_back(lines[x].second);
1040 lines.erase(lines.begin()+x);
1044 if (lines[x].second == points.back())
1046 points.push_back(lines[x].first);
1047 lines.erase(lines.begin()+x);
1060 GLdouble px, py, pz, rad;
1061 map->GetOpenGLCoord(l.
x, l.
y, px, py, pz, rad);
1077 disp.
FillCircle({
static_cast<float>(px),
static_cast<float>(py)}, rad, c);
1090 GLdouble px, py, t, rad;
1091 map->GetOpenGLCoord(l1.
x, l1.
y, px, py, t, rad);
1101 GLdouble px, py, t, rad;
1102 map->GetOpenGLCoord(l2.
x, l2.
y, px, py, t, rad);
1123 GLdouble px, py, t, rad;
1124 map->GetOpenGLCoord(l.
x, l.
y, px, py, t, rad);
1144 GLdouble px, py, t, rad;
1145 map->GetOpenGLCoord(l.
x, l.
y, px, py, t, rad);
1152 disp.
DrawText(txt, {
static_cast<float>(px),
static_cast<float>(py)}, c, rad);
1161 map->GetOpenGLCoord(l1.
x, l1.
y, px, py, t, rad);
1166 GLdouble px, py, t, rad;
1167 map->GetOpenGLCoord(l2.
x, l2.
y, px, py, t, rad);
1168 p.
x = (1-v)*p.
x + (v)*px;
1169 p.
y = (1-v)*p.
y + (v)*py;
1182 GLdouble xx1, yy1, zz1, rad;
1183 GLdouble xx2, yy2, zz2;
1184 map->GetOpenGLCoord(a.
x, a.
y, xx1, yy1, zz1, rad);
1185 map->GetOpenGLCoord(b.
x, b.
y, xx2, yy2, zz2, rad);
1191 disp.
DrawLine({
static_cast<float>(xx1),
static_cast<float>(yy1)},
1192 {
static_cast<float>(xx2),
static_cast<float>(yy2)},
width, c);
1197 GLdouble xx1, yy1, zz1, rad;
1198 GLdouble xx2, yy2, zz2;
1199 map->GetOpenGLCoord(a.
x, a.
y, xx1, yy1, zz1, rad);
1200 map->GetOpenGLCoord(b.
x, b.
y, xx2, yy2, zz2, rad);
1206 disp.
DrawArrow({
static_cast<float>(xx1),
static_cast<float>(yy1)},
1207 {
static_cast<float>(xx2),
static_cast<float>(yy2)},
width, c);
1215 case kN: news.
y-=1;
break;
1216 case kS: news.
y+=1;
break;
1217 case kE: news.
x+=1;
break;
1218 case kW: news.
x-=1;
break;
1219 case kNW: news.
y-=1; news.
x-=1;
break;
1220 case kSW: news.
y+=1; news.
x-=1;
break;
1221 case kNE: news.
y-=1; news.
x+=1;
break;
1222 case kSE: news.
y+=1; news.
x+=1;
break;