77{
80
81 std::srand(std::time(nullptr));
82
83 int total_time = 0;
84 int idx = 0;
85
86
90 }
91 }
92
93 std::vector<std::pair<MapCoords, MapCoords>> start_end;
94 for (int i = 0; i < 10000; i++) {
96
97 do {
100
101 std::vector<MapCoords> path;
102 do {
103 do {
106 }
while (!start.
is_within_range(end,
MAX_VIEW_RANGE) && ((path = astar.findPath(start, end)).size() == 0 || (path.at(0).x() != end.
x() && path.at(0).y() != end.
y())));
107
108 start_end.push_back(std::make_pair(start, end));
109
110 }
111
112 for (int i = 0; i < 10000; i++) {
115
116 auto start_time = std::chrono::high_resolution_clock::now();
117 auto path = astar.findPath(start, end);
118 auto finish_time = std::chrono::high_resolution_clock::now();
119 auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(finish_time - start_time);
120 bool path_found = path.size() != 0;
121
122 total_time += elapsed.count();
123 if (path.size() == 0)
124 BOOST_FAIL("Path not found");
125#ifdef PRINT_FILE
126 std::ofstream mapfile;
127 char filename[100];
128 snprintf(filename, 100, "izlude-%d.txt", i);
129 mapfile.open(filename);
133 bool found = false;
134
135 for (auto c : path) {
136 if (coords == c) {
137 if (start.
x() == x && start.
y() == y)
138 mapfile << "@ (" << x << ", " << y << ")";
139 else if (end.
x() == x && end.
y() == y)
140 mapfile << "T (" << x << ", " << y << ")";
141 else if (c.x() == x && c.y() == y)
142 mapfile << "^";
143 found = true;
144 }
145 }
146
147 if (!found) {
148 if (start.
x() == x && start.
y() == y)
149 mapfile << "@ (" << x << ", " << y << ")";
150 else if (end.
x() == x && end.
y() == y)
151 mapfile << "T (" << x << ", " << y << ")";
152 else if (
cell[x][y].isWalkable())
153 mapfile << " ";
154 else
155 mapfile << "|";
156 }
157 }
158
159 mapfile << "\n";
160 }
161
162 mapfile.close();
163#endif
164 }
165 std::cout << "total time: " << total_time << std::endl;
166
167
168
169
170
171
172
173
174
175}
#define MAP_HEIGHT
Definition: AStarTest.cpp:48
Cell cell[MAP_WIDTH][MAP_HEIGHT]
Definition: AStarTest.cpp:52
#define MAP_WIDTH
Definition: AStarTest.cpp:47
bool check_collision(int16_t x, int16_t y)
Definition: AStarTest.cpp:54
Coordinates< MAX_CELLS_PER_MAP > MapCoords
Definition: GridDefinitions.hpp:83
#define MAX_VIEW_RANGE
Definition: Horizon.hpp:59
int16_t y() const
Definition: Coordinates.hpp:120
bool is_within_range(Coordinates< BOUNDS > const &bounds, int range) const
Definition: Coordinates.hpp:82
int16_t x() const
Definition: Coordinates.hpp:119
void setHeuristic(const HeuristicFunction &heuristic_)
Definition: AStar.hpp:137
static uint32_t manhattan(MapCoords source_, MapCoords target_)
Definition: AStar.hpp:55
uint8_t prontera[122304]
Definition: prontera.cpp:4