Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ int main()
for(auto& coordinate : path) {
std::cout << coordinate.x << " " << coordinate.y << "\n";
}
}
generator.visualize(path);
}
39 changes: 39 additions & 0 deletions source/AStar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,45 @@ bool AStar::Generator::detectCollision(Vec2i coordinates_)
return false;
}

void AStar::Generator::visualize(const CoordinateList& path)
{
char **vis = new char*[worldSize.y];
for (uint i = 0; i < worldSize.y; ++i) {
vis[i] = new char[worldSize.x];
}

for (uint i = 0; i < worldSize.y; ++i) {
for (uint j = 0; j < worldSize.x; ++j) {
vis[i][j] = '+';
}
}

for (auto it = walls.begin(); it != walls.end(); ++it) {
vis[(*it).y][(*it).x] = 'X';
}

for (auto it = path.begin(); it != path.end(); ++it) {
if (path.begin() == it)
vis[(*it).y][(*it).x] = 'E';
else if (path.end() == next(it))
vis[(*it).y][(*it).x] = 'S';
else
vis[(*it).y][(*it).x] = 'O';
}

for (uint i = 0; i < worldSize.y; ++i) {
for (uint j = 0; j < worldSize.x; ++j) {
printf("%c ", vis[i][j]);
}
printf("\n");
}

for (uint i = 0; i < worldSize.y; ++i) {
delete[] vis[i];
}
delete[] vis;
}

AStar::Vec2i AStar::Heuristic::getDelta(Vec2i source_, Vec2i target_)
{
return{ abs(source_.x - target_.x), abs(source_.y - target_.y) };
Expand Down
1 change: 1 addition & 0 deletions source/AStar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace AStar
void addCollision(Vec2i coordinates_);
void removeCollision(Vec2i coordinates_);
void clearCollisions();
void visualize(const CoordinateList& path);

private:
HeuristicFunction heuristic;
Expand Down