From fd2ad3883cc12bb0dc5531326da1e9b129ca9428 Mon Sep 17 00:00:00 2001 From: Yann Thierry-Mieg Date: Sat, 14 Jul 2018 14:42:49 +0200 Subject: [PATCH 1/2] Make function robust to existing command structure If there is already a building, or, e.g. creep in a location, the placement queries for a CommandCenter (line 19) will answer false. In the onStart method of a bot, it is likely that your own initial base is blocking at least one expansion location. This led to the algorithm returning points way off the map, or in e.g. (0,0). With this patch, we a posteriori edit the results of the query, so that an existing CC/Hatch/Nexus still counts as a good location to build in. --- src/sc2lib/sc2_search.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/sc2lib/sc2_search.cc b/src/sc2lib/sc2_search.cc index 6c9b0fe5..a23c69ec 100644 --- a/src/sc2lib/sc2_search.cc +++ b/src/sc2lib/sc2_search.cc @@ -103,6 +103,21 @@ std::vector CalculateExpansionLocations(const ObservationInterface* obs } std::vector results = query->Placement(queries); + // Edit the results : allow to build in command structure existing location + Units commandStructures = observation->GetUnits( + [](const Unit& unit) { + return unit.unit_type == UNIT_TYPEID::TERRAN_COMMANDCENTER || unit.unit_type == UNIT_TYPEID::TERRAN_ORBITALCOMMAND || unit.unit_type == UNIT_TYPEID::TERRAN_PLANETARYFORTRESS || + unit.unit_type == UNIT_TYPEID::PROTOSS_NEXUS || + unit.unit_type == UNIT_TYPEID::ZERG_HATCHERY || unit.unit_type == UNIT_TYPEID::ZERG_LAIR || unit.unit_type == UNIT_TYPEID::ZERG_HIVE; + }); + for (auto cc : commandStructures) { + for (int i = 0; i < queries.size(); ++i) { + if (DistanceSquared2D(cc->pos, queries[i].target_pos) < 1.0f) { + results[i] = true; + } + } + } + size_t start_index = 0; for (int i = 0; i < clusters.size(); ++i) { std::pair >& cluster = clusters[i]; From 6264222e863fd50b2d73af45933b5ade550f68a3 Mon Sep 17 00:00:00 2001 From: Yann Thierry-Mieg Date: Sat, 14 Jul 2018 18:14:57 +0200 Subject: [PATCH 2/2] break from nested loop on finding a correct spot we can avoid a full traversal of the queries --- src/sc2lib/sc2_search.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sc2lib/sc2_search.cc b/src/sc2lib/sc2_search.cc index a23c69ec..8592017c 100644 --- a/src/sc2lib/sc2_search.cc +++ b/src/sc2lib/sc2_search.cc @@ -114,6 +114,8 @@ std::vector CalculateExpansionLocations(const ObservationInterface* obs for (int i = 0; i < queries.size(); ++i) { if (DistanceSquared2D(cc->pos, queries[i].target_pos) < 1.0f) { results[i] = true; + // we can safely break here, each query is at least one away + break; } } }