Skip to content
Snippets Groups Projects
Commit 1676cf56 authored by Hannes Jämtner's avatar Hannes Jämtner
Browse files

Got the newest version 4.12 of sc2 to work, gonna continue more tomorrow

parent e08c388d
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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;
}
......@@ -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
......
......@@ -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
}
......@@ -42,6 +42,7 @@ public:
void onStart();
void onFrame();
int width() const;
int height() const;
float terrainHeight(float x, float y) const;
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment