consider field size ;)
This commit is contained in:
parent
7e64cf85e0
commit
56aa4261f6
18
src/main.cc
18
src/main.cc
|
@ -53,6 +53,7 @@ class Bot {
|
|||
int x, y;
|
||||
bool up, right, down, left;
|
||||
std::map<std::pair<int, int>, unsigned> known_map;
|
||||
int field_width, field_height;
|
||||
|
||||
asio::awaitable<void> Protocol();
|
||||
asio::awaitable<void> Join();
|
||||
|
@ -192,19 +193,23 @@ unsigned Bot::ShortestPath(int x, int y) {
|
|||
if (visited.count(position)) {
|
||||
continue;
|
||||
}
|
||||
if (!(known_map[position] & static_cast<unsigned>(Direction::LEFT))) {
|
||||
if (!(known_map[position] & static_cast<unsigned>(Direction::LEFT)) &&
|
||||
position.first > 0) {
|
||||
queue.emplace(distance + 1,
|
||||
std::make_pair(position.first - 1, position.second));
|
||||
}
|
||||
if (!(known_map[position] & static_cast<unsigned>(Direction::RIGHT))) {
|
||||
if (!(known_map[position] & static_cast<unsigned>(Direction::RIGHT)) &&
|
||||
position.first < field_width) {
|
||||
queue.emplace(distance + 1,
|
||||
std::make_pair(position.first + 1, position.second));
|
||||
}
|
||||
if (!(known_map[position] & static_cast<unsigned>(Direction::UP))) {
|
||||
if (!(known_map[position] & static_cast<unsigned>(Direction::UP)) &&
|
||||
position.second > 0) {
|
||||
queue.emplace(distance + 1,
|
||||
std::make_pair(position.first, position.second - 1));
|
||||
}
|
||||
if (!(known_map[position] & static_cast<unsigned>(Direction::DOWN))) {
|
||||
if (!(known_map[position] & static_cast<unsigned>(Direction::DOWN)) &&
|
||||
position.second < field_height) {
|
||||
queue.emplace(distance + 1,
|
||||
std::make_pair(position.first, position.second + 1));
|
||||
}
|
||||
|
@ -215,6 +220,11 @@ unsigned Bot::ShortestPath(int x, int y) {
|
|||
}
|
||||
|
||||
asio::awaitable<void> Bot::ChooseMove() {
|
||||
if (known_map.empty()) {
|
||||
field_width = x;
|
||||
field_height = y;
|
||||
}
|
||||
|
||||
// update map
|
||||
known_map[std::make_pair(x, y)] =
|
||||
(up ? static_cast<unsigned>(Direction::UP) : 0) |
|
||||
|
|
Loading…
Reference in a new issue