diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp index 8cfda7a02fe1c56399a0826a22c7b1dc14295b51..a10533024f6a180f2da6c68c7ae90dfc33cbeeea 100644 --- a/python-api-src/library.cpp +++ b/python-api-src/library.cpp @@ -93,6 +93,7 @@ PYBIND11_MODULE(library, m) .def("debug_set_energy", &IDABot::DebugSetEnergy, "Set the energy on a unit through debug mode") .def("debug_set_life", &IDABot::DebugSetLife, "Set the life on a unit through debug mode") .def("debug_set_shield", &IDABot::DebugSetShields, "Set the shields on a unit through debug mode") + .def("get_enemy_base_location", &IDABot::GetEnemyBaseLocation, "Return the CCpostion of the enemy base") .def_property_readonly("base_location_manager", &IDABot::Bases) .def_property_readonly("tech_tree", &IDABot::GetTechTree) .def_property_readonly("map_tools", &IDABot::Map) diff --git a/src/IDABot.cpp b/src/IDABot.cpp index 871f0dcfe83aa3a09d7446160817989d6f67708c..ac3aa2a8f27998de60fb59c4df7006e8b4ce309c 100644 --- a/src/IDABot.cpp +++ b/src/IDABot.cpp @@ -332,3 +332,10 @@ void IDABot::DebugSetShields(float value, const Unit unit) Debug()->DebugSetShields(value, unit.getUnitPtr()); } +// There is a bug in the latest SC2 +// This a function to get the enemy base instead of using build location manager +const std::vector<Point2D> IDABot::GetEnemyBaseLocation() +{ + return Observation()->GetGameInfo().enemy_start_locations; +} + diff --git a/src/IDABot.h b/src/IDABot.h index 5c4d3a891f349486d77ece41cce9f2f6bf90d0b0..026d8bbbb687f3a38f268c49ff8448bd7d57b97a 100644 --- a/src/IDABot.h +++ b/src/IDABot.h @@ -15,6 +15,7 @@ #include "Unit.h" using sc2::UnitTypeID; +using sc2::Point2D; class IDABot : public sc2::Agent { @@ -84,7 +85,7 @@ public: void DebugSetEnergy(float value, const Unit unit); void DebugSetLife(float value, const Unit unit); void DebugSetShields(float value, const Unit unit); - Unit findClosestWorkerTo(std::vector<Unit> & unitsToAssign, const CCPosition & target); + const std::vector<Point2D> GetEnemyBaseLocation(); // Not needed, just convenience functions diff --git a/src/MapTools.cpp b/src/MapTools.cpp index 9adad0de01b7c3736c7cbfdc5e1be8765dd7adb4..9714266742e38929b60d91ce67a85fda34ef1b36 100644 --- a/src/MapTools.cpp +++ b/src/MapTools.cpp @@ -7,6 +7,23 @@ #include <fstream> #include <array> +namespace { + bool getBit(const sc2::ImageData& grid, int tileX, int tileY) { + assert(grid.bits_per_pixel == 1); + + sc2::Point2DI pointI(tileX, tileY); + if (pointI.x < 0 || pointI.x >= grid.width || pointI.y < 0 || pointI.y >= grid.height) + { + return false; + } + + div_t idx = div(pointI.x + pointI.y * grid.width, 8); + return (grid.data[idx.quot] >> (7 - idx.rem)) & 1; + } + +} // namespace + + const size_t LegalActions = 4; const int actionX[LegalActions] ={1, -1, 0, 0}; const int actionY[LegalActions] ={0, 0, 1, -1}; @@ -541,17 +558,7 @@ CCTilePosition MapTools::getLeastRecentlySeenTile() const bool MapTools::canWalk(int tileX, int tileY) { #ifdef SC2API - auto & info = m_bot.Observation()->GetGameInfo(); - sc2::Point2DI pointI(tileX, tileY); - if (pointI.x < 0 || pointI.x >= info.width || pointI.y < 0 || pointI.y >= info.width) - { - return false; - } - - assert(info.pathing_grid.data.size() == info.width * info.height); - unsigned char encodedPlacement = info.pathing_grid.data[pointI.x + ((info.height - 1) - pointI.y) * info.width]; - bool decodedPlacement = encodedPlacement == 255 ? false : true; - return decodedPlacement; + return getBit(m_bot.Observation()->GetGameInfo().pathing_grid, tileX, tileY); #else for (int i=0; i<4; ++i) { @@ -571,17 +578,7 @@ bool MapTools::canWalk(int tileX, int tileY) bool MapTools::canBuild(int tileX, int tileY) { #ifdef SC2API - auto & info = m_bot.Observation()->GetGameInfo(); - sc2::Point2DI pointI(tileX, tileY); - if (pointI.x < 0 || pointI.x >= info.width || pointI.y < 0 || pointI.y >= info.width) - { - return false; - } - - assert(info.placement_grid.data.size() == info.width * info.height); - unsigned char encodedPlacement = info.placement_grid.data[pointI.x + ((info.height - 1) - pointI.y) * info.width]; - bool decodedPlacement = encodedPlacement == 255 ? true : false; - return decodedPlacement; + return getBit(m_bot.Observation()->GetGameInfo().placement_grid, tileX, tileY); #else return BWAPI::Broodwar->isBuildable(BWAPI::TilePosition(tileX, tileY)); #endif @@ -604,4 +601,5 @@ float MapTools::terrainHeight(const CCPosition & point) const #else return 0; #endif -} \ No newline at end of file +} + diff --git a/src/MapTools.h b/src/MapTools.h index 51f0533986cfb7a0c4b791d8c20178d346ab94c2..8453345e01667597071510cd7095f5b6805367d4 100644 --- a/src/MapTools.h +++ b/src/MapTools.h @@ -42,6 +42,7 @@ public: void onStart(); void onFrame(); + int width() const; int height() const; float terrainHeight(float x, float y) const; diff --git a/src/Unit.h b/src/Unit.h index 5a7cef49664e37ee60a197e26a12cbf8065f9854..58e769193625600afff87ce0639b20cf9c4ac48e 100644 --- a/src/Unit.h +++ b/src/Unit.h @@ -61,6 +61,7 @@ public: float getFacing() const; float getRadius() const; + void stop () const; void attackUnit (const Unit & target) const; void attackMove (const CCPosition & targetPosition) const;