4 template <
class environment>
11 virtual const char *
GetName() {
return "Greedy DM following unit"; }
18 std::vector<tDirection> directions;
19 directions.push_back(
kN);
20 directions.push_back(
kNE);
21 directions.push_back(
kE);
22 directions.push_back(
kSE);
23 directions.push_back(
kS);
24 directions.push_back(
kSW);
25 directions.push_back(
kW);
26 directions.push_back(
kNW);
31 if (nodeVec.
x == 0 && nodeVec.
y == 0)
33 a = directions[random()%directions.size()];
37 double bestDotProd = -1;
38 double secondBestValue = -1;
44 for (
unsigned int i=0; i<directions.size(); i++)
47 wme->GetNextState(
loc,directions[i],nextThisDir);
50 if (theEnv->GetMap()->CanStep(
loc.
x,
loc.
y, nextThisDir.
x, nextThisDir.
y))
52 if (theEnv->GetOccupancyInfo() && theEnv->GetOccupancyInfo()->GetStateOccupied(nextThisDir))
57 double dotProd1 = (nodeVec.
x * dirVec.
x) + (nodeVec.
y * dirVec.
y);
58 double dotProd2 = (dirVec.
x * nextVec.
x) + (dirVec.
y * nextVec.
y);
60 double dotProd = 0.5 * dotProd1 + 0.5 * dotProd2;
62 if (nextVec.
x == 0 && nextVec.
y == 0)
67 if (dotProd >= bestDotProd)
71 secondBestValue = bestDotProd;
72 bestDotProd = dotProd;
74 bestDir = directions[i];
97 if (secondBest ==
kStay)
101 if ((bestDotProd - secondBestValue < 0.1) && (random()%4 == 1))
126 { theEnv->OpenGLDraw(
loc); }