|
@@ -38,6 +38,18 @@ unsigned int identifyTile(unsigned int y, unsigned int x, unsigned int l) {
|
|
|
return y * l + x;
|
|
|
}
|
|
|
|
|
|
+void locateTile(unsigned int id, unsigned int l, unsigned int &x, unsigned int &y) {
|
|
|
+ y = id / l;
|
|
|
+ x = id - l * y;
|
|
|
+}
|
|
|
+
|
|
|
+unsigned int delta(unsigned int c1, unsigned int c2) {
|
|
|
+ if (c1 < c2)
|
|
|
+ return c2 - c1;
|
|
|
+ else
|
|
|
+ return c1 - c2;
|
|
|
+}
|
|
|
+
|
|
|
void moveCursorUp(const unsigned int& h) {
|
|
|
cout << "\033[" << h << 'A';
|
|
|
}
|
|
@@ -435,8 +447,16 @@ class World
|
|
|
}
|
|
|
|
|
|
unsigned int euristic(unsigned int from, unsigned int to) {
|
|
|
- // Todo : improve euristic
|
|
|
- return 0;
|
|
|
+ // Manhattan
|
|
|
+ unsigned int x1, y1, x2, y2, dx, dy;
|
|
|
+
|
|
|
+ locateTile(from, l, x1, y1);
|
|
|
+ locateTile(to, l, x2, y2);
|
|
|
+
|
|
|
+ dx = delta(x1, x2);
|
|
|
+ dy = delta(y1, y2);
|
|
|
+
|
|
|
+ return dx + dy;
|
|
|
}
|
|
|
|
|
|
void animate(bool exitFound, const list<unsigned int>& discovered, const list<unsigned int>& path) {
|