parent
737ae965d0
commit
381e358072
17
src/main.cc
17
src/main.cc
|
@ -55,7 +55,6 @@ 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();
|
||||||
|
@ -76,9 +75,7 @@ Bot::Bot(asio::any_io_executor executor, std::string_view name,
|
||||||
socket{executor},
|
socket{executor},
|
||||||
server{server},
|
server{server},
|
||||||
name{name},
|
name{name},
|
||||||
pass{pass},
|
pass{pass} {
|
||||||
field_width{22},
|
|
||||||
field_height{22} {
|
|
||||||
asio::co_spawn(executor, std::bind(&Bot::Protocol, this), asio::detached);
|
asio::co_spawn(executor, std::bind(&Bot::Protocol, this), asio::detached);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,23 +200,19 @@ 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);
|
||||||
}
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
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