only limit field in one direction

This commit is contained in:
Thomas Lindner 2022-05-21 12:01:06 +02:00
parent 381e358072
commit b85ae09645

View file

@ -200,7 +200,8 @@ unsigned Bot::ShortestPath(int x, int y) {
if (visited.count(position)) { if (visited.count(position)) {
continue; continue;
} }
if (!(known_map[position] & static_cast<unsigned>(Direction::LEFT))) { if (!(known_map[position] & static_cast<unsigned>(Direction::LEFT)) &&
position.first > 0) {
auto pos = std::make_pair(position.first - 1, position.second); auto pos = std::make_pair(position.first - 1, position.second);
queue.emplace(distance + 1 + AStarHeuristic(pos), pos); queue.emplace(distance + 1 + AStarHeuristic(pos), pos);
} }
@ -208,7 +209,8 @@ unsigned Bot::ShortestPath(int x, int y) {
auto pos = std::make_pair(position.first + 1, position.second); auto pos = std::make_pair(position.first + 1, position.second);
queue.emplace(distance + 1 + AStarHeuristic(pos), pos); queue.emplace(distance + 1 + AStarHeuristic(pos), pos);
} }
if (!(known_map[position] & static_cast<unsigned>(Direction::UP))) { if (!(known_map[position] & static_cast<unsigned>(Direction::UP)) &&
position.second > 0) {
auto pos = std::make_pair(position.first, position.second - 1); auto pos = std::make_pair(position.first, position.second - 1);
queue.emplace(distance + 1 + AStarHeuristic(pos), pos); queue.emplace(distance + 1 + AStarHeuristic(pos), pos);
} }