summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@ground-control>2015-11-25 15:36:50 -0600
committertom <tom@ground-control>2015-11-25 15:36:50 -0600
commit0fb714b1a642361eebadf7d74333c20f861354d2 (patch)
treeb1d43d8744b8637c83d1b0c5e9053a3c38fba437
parente63a678a8fdde888620b6d5a5059bd0f37141592 (diff)
fixed heuristic movement
-rw-r--r--inc/Character.hpp2
-rw-r--r--src/Character.cpp8
2 files changed, 6 insertions, 4 deletions
diff --git a/inc/Character.hpp b/inc/Character.hpp
index f47589a..3c88ab2 100644
--- a/inc/Character.hpp
+++ b/inc/Character.hpp
@@ -25,7 +25,7 @@ class Character
char getSymbol(){return symbol;}
private:
- string order = "wander";
+ string order = "move";
Location l; // current location
Location d; // destination
char symbol;
diff --git a/src/Character.cpp b/src/Character.cpp
index 012b1a2..29f9d5c 100644
--- a/src/Character.cpp
+++ b/src/Character.cpp
@@ -53,15 +53,15 @@ void Character::heuristic(vector <Character> men, vector <Location> impassable)
float v,u;
Location L;
+
if(open.size())
{
- v = sqrt(((open[0].x - d.x)^2) + ((open[0].y - d.y)^2));
+ v = sqrt(pow(open[0].x - d.x,2) + pow(open[0].y - d.y,2));
L = open[0];
}
for(int i = 0; i < open.size(); i++)
{
- u = sqrt(((open[i].x - d.x)^2) + ((open[i].y - d.y)^2));
- cout << u << " ";
+ u = sqrt(pow(open[i].x - d.x,2) + pow(open[i].y - d.y,2));
if (u<v)
{
L = open[i];
@@ -69,6 +69,8 @@ void Character::heuristic(vector <Character> men, vector <Location> impassable)
}
}
move(L);
+ if(l.x==d.x && l.y==d.y)
+ order="wait";
}
vector <Location> Character::getLocal(Location L, vector <Character> men, vector <Location> impassable)