Go to the documentation of this file.
19 FILE *f = fopen(map,
"r");
22 printf(
"Unable to open file '%s'\n", map);
26 int num = fscanf(f,
"type %s\nheight %d\nwidth %d\nmap\n", format, &
mHeight, &
mWidth);
29 printf(
"Bad file format: '%s'\n", map);
34 for (uint16_t y = 0; y <
mHeight; y++)
36 for (uint16_t x = 0; x <
mWidth; x++)
38 fscanf(f,
"%c", &what);
41 fscanf(f,
"%c", &what);
43 printf(
"Error loading\n");
46 for (
int x = 0; x < 20; x++)
47 costs.push_back(1+0.2*x);
48 std::random_device rd;
60 for (uint16_t y = 0; y <
mHeight; y++)
62 for (uint16_t x = 0; x <
mWidth; x++)
68 for (
int x = 0; x < 20; x++)
69 costs.push_back(1+0.2*x);
70 std::random_device rd;
81 neighbors.push_back(nodeID);
86 neighbors.push_back(nodeID);
91 neighbors.push_back(nodeID);
96 neighbors.push_back(nodeID);
99 if (nodeID.
y > 0 && nodeID.
x > 0)
101 neighbors.push_back(nodeID);
102 neighbors.back().x--;
103 neighbors.back().y--;
105 if (nodeID.
y > 0 && nodeID.
x+1 <
mWidth)
107 neighbors.push_back(nodeID);
108 neighbors.back().x++;
109 neighbors.back().y--;
113 neighbors.push_back(nodeID);
114 neighbors.back().x++;
115 neighbors.back().y++;
117 if (nodeID.
y+1 <
mHeight && nodeID.
x > 0)
119 neighbors.push_back(nodeID);
120 neighbors.back().x--;
121 neighbors.back().y++;
130 actions.push_back(
kW);
134 actions.push_back(
kN);
138 actions.push_back(
kE);
142 actions.push_back(
kS);
144 if (nodeID.
y > 0 && nodeID.
x > 0)
146 actions.push_back(
kNW);
148 if (nodeID.
y > 0 && nodeID.
x+1 <
mWidth)
150 actions.push_back(
kNE);
154 actions.push_back(
kSE);
156 if (nodeID.
y+1 <
mHeight && nodeID.
x > 0)
158 actions.push_back(
kSW);
167 case kN: s.
y-=1;
break;
168 case kS: s.
y+=1;
break;
169 case kE: s.
x+=1;
break;
170 case kW: s.
x-=1;
break;
171 case kNW: s.
y-=1; s.
x-=1;
break;
172 case kSW: s.
y+=1; s.
x-=1;
break;
173 case kNE: s.
y-=1; s.
x+=1;
break;
174 case kSE: s.
y+=1; s.
x+=1;
break;
183 case kN: a =
kS;
break;
185 case kE: a =
kW;
break;
187 case kS: a =
kN;
break;
189 case kW: a =
kE;
break;
198 assert(!
"Not implemented");
206 const double DIAGONAL_COST = M_SQRT2;
207 double a = ((l1.
x>l2.
x)?(l1.
x-l2.
x):(l2.
x-l1.
x));
208 double b = ((l1.
y>l2.
y)?(l1.
y-l2.
y):(l2.
y-l1.
y));
212 return ((a>b)?(b*DIAGONAL_COST+a-b):(a*DIAGONAL_COST+b-a));
218 if (node1.
x != node2.
x && node1.
y != node2.
y)
222 double result = base*0.5*(c1+c2);
263 float _scale, xOffset, yOffset;
267 xOffset = (2.0-
mWidth*_scale)*0.5;
271 _scale = 2.0/(float)(
mWidth);
272 yOffset = (2.0-
mHeight*_scale)*0.5;
275 float epsilon = _scale/2.0;
276 x = -1+l.
x*_scale+epsilon+xOffset;
277 y = -1+l.
y*_scale+epsilon+yOffset;
double GCost(const xyLoc &node1, const xyLoc &node2) const
tDirection GetAction(const xyLoc &s1, const xyLoc &s2) const
void GetCoordinate(const xyLoc &l, float &x, float &y, float &r) const
bool InvertAction(tDirection &a) const
DynamicWeightedGridEnvironment(const char *map)
uint64_t GetActionHash(tDirection act) const
uint64_t GetStateHash(const xyLoc &node) const
void Draw(Graphics::Display &display) const
bool GoalTest(const xyLoc &node, const xyLoc &goal) const
virtual rgbColor GetColor() const
std::vector< uint8_t > terrain
void FillCircle(rect r, rgbColor c)
void ApplyAction(xyLoc &s, tDirection a) const
double HCost(const xyLoc &node1, const xyLoc &node2) const
Heuristic value between two arbitrary nodes.
void GetActions(const xyLoc &nodeID, std::vector< tDirection > &actions) const
void GetSuccessors(const xyLoc &nodeID, std::vector< xyLoc > &neighbors) const
Nodes to be stored within a Graph.