From 381e358072443f41be5f2d521fde85cd8dae6379 Mon Sep 17 00:00:00 2001 From: Thomas Lindner Date: Sat, 21 May 2022 10:58:27 +0200 Subject: [PATCH] Revert "hardcode field size ;)" This reverts commit 737ae965d03aeb55d181bd2f00155e99840110cd. --- src/main.cc | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/main.cc b/src/main.cc index 261ab5b..4d62a63 100644 --- a/src/main.cc +++ b/src/main.cc @@ -55,7 +55,6 @@ class Bot { int x, y; bool up, right, down, left; std::map, unsigned> known_map; - int field_width, field_height; asio::awaitable Protocol(); asio::awaitable Join(); @@ -76,9 +75,7 @@ Bot::Bot(asio::any_io_executor executor, std::string_view name, socket{executor}, server{server}, name{name}, - pass{pass}, - field_width{22}, - field_height{22} { + pass{pass} { 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)) { continue; } - if (!(known_map[position] & static_cast(Direction::LEFT)) && - position.first > 0) { + if (!(known_map[position] & static_cast(Direction::LEFT))) { auto pos = std::make_pair(position.first - 1, position.second); queue.emplace(distance + 1 + AStarHeuristic(pos), pos); } - if (!(known_map[position] & static_cast(Direction::RIGHT)) && - position.first < field_width) { + if (!(known_map[position] & static_cast(Direction::RIGHT))) { auto pos = std::make_pair(position.first + 1, position.second); queue.emplace(distance + 1 + AStarHeuristic(pos), pos); } - if (!(known_map[position] & static_cast(Direction::UP)) && - position.second > 0) { + if (!(known_map[position] & static_cast(Direction::UP))) { auto pos = std::make_pair(position.first, position.second - 1); queue.emplace(distance + 1 + AStarHeuristic(pos), pos); } - if (!(known_map[position] & static_cast(Direction::DOWN)) && - position.second < field_height) { + if (!(known_map[position] & static_cast(Direction::DOWN))) { auto pos = std::make_pair(position.first, position.second + 1); queue.emplace(distance + 1 + AStarHeuristic(pos), pos); }