use field size
This commit is contained in:
parent
b85ae09645
commit
993411847e
12
src/main.cc
12
src/main.cc
|
@ -55,6 +55,7 @@ class Bot {
|
||||||
int x, y;
|
int x, y;
|
||||||
bool up, right, down, left;
|
bool up, right, down, left;
|
||||||
std::map<std::pair<int, int>, unsigned> known_map;
|
std::map<std::pair<int, int>, unsigned> known_map;
|
||||||
|
int field_width, field_height;
|
||||||
|
|
||||||
asio::awaitable<void> Protocol();
|
asio::awaitable<void> Protocol();
|
||||||
asio::awaitable<void> Join();
|
asio::awaitable<void> Join();
|
||||||
|
@ -114,8 +115,9 @@ asio::awaitable<void> Bot::Protocol() {
|
||||||
} else if (field == "error") {
|
} else if (field == "error") {
|
||||||
std::getline(iss, field);
|
std::getline(iss, field);
|
||||||
std::cout << "-> Error: " << field << std::endl;
|
std::cout << "-> Error: " << field << std::endl;
|
||||||
} else if (field == "goal") {
|
} else if (field == "game") {
|
||||||
iss >> goal_x >> dummy >> goal_y;
|
iss >> field_width >> dummy >> field_height >> dummy >> goal_x >>
|
||||||
|
dummy >> goal_y;
|
||||||
std::cout << "-> Goal is at (" << goal_x << ", " << goal_y << ")"
|
std::cout << "-> Goal is at (" << goal_x << ", " << goal_y << ")"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
known_map.clear();
|
known_map.clear();
|
||||||
|
@ -205,7 +207,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::RIGHT))) {
|
if (!(known_map[position] & static_cast<unsigned>(Direction::RIGHT)) &&
|
||||||
|
position.first < field_width) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -214,7 +217,8 @@ unsigned Bot::ShortestPath(int x, int y) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
if (!(known_map[position] & static_cast<unsigned>(Direction::DOWN))) {
|
if (!(known_map[position] & static_cast<unsigned>(Direction::DOWN)) &&
|
||||||
|
position.second < field_height) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue