Skip to content

Commit

Permalink
fixed ramp detection
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelRoyerRivard committed Sep 10, 2019
1 parent 867846d commit 3c2c321
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 56 deletions.
25 changes: 16 additions & 9 deletions bin/BotConfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,30 @@

"SC2API" :
{
"BotVersion" : "1.6.4",
"BotVersion" : "1.6.5",
"ConnectToLadder" : false,
"LoadSettings" : false,
"BotRace" : "Terran",
"PlayAsHuman" : false,
"ForceStepMode" : true,
"PlayVsItSelf" : false,
"EnemyDifficulty" : 10,
"EnemyRace" : "Zerg",
"MapFile" : "WintersGateLE.SC2Map",
"EnemyRace" : "Terran",
"MapFile" : "DiscoBloodbathLE.SC2Map",
"StepSize" : 1,
"BatchReplayMode" : false,
"NbBatchReplay" : 50
},

"RandomMaps":
[
"CyberForestLE.SC2Map",
"KairosJunctionLE.SC2Map",
"KingsCoveLE.SC2Map",
"Acropolis.SC2Map",
"NewRepugnancyLE.SC2Map"
"WorldofSleepersLE.SC2Map",
"AcropolisLE.SC2Map",
"WintersGateLE.SC2Map",
"ThunderbirdLE.SC2Map",
"TritonLE.SC2Map",
"EphemeronLE.SC2Map",
"DiscoBloodbathLE.SC2Map"
],

"AllRandomMaps":
Expand Down Expand Up @@ -76,7 +78,12 @@
"OldSunshine.SC2Map",
"Treachery.SC2Map",
"Triton.SC2Map",
"NewRepugnancyLE.SC2Map"
"WorldofSleepersLE.SC2Map",
"AcropolisLE.SC2Map",
"WintersGateLE.SC2Map",
"ThunderbirdLE.SC2Map",
"TritonLE.SC2Map",
"EphemeronLE.SC2Map"
],

"Micro" :
Expand Down
84 changes: 38 additions & 46 deletions src/BuildingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,30 @@ void BuildingManager::FindRampTiles(std::list<CCTilePosition> &rampTiles, std::l
}
else
{
float tileHeight = m_bot.Map().terrainHeight(currentTile.x, currentTile.y);

float topHeightDiff = tileHeight - m_bot.Map().terrainHeight(currentTile.x + 1, currentTile.y);
float downHeightDiff = tileHeight - m_bot.Map().terrainHeight(currentTile.x - 1, currentTile.y);
float rightHeightDiff = tileHeight - m_bot.Map().terrainHeight(currentTile.x, currentTile.y + 1);
float leftHeightDiff = tileHeight - m_bot.Map().terrainHeight(currentTile.x, currentTile.y - 1);

bool topIsLower = topHeightDiff >= 0.2f && 0.3f >= topHeightDiff;
bool downIsLower = downHeightDiff >= 0.2f && 0.3f >= downHeightDiff;
bool rightIsLower = rightHeightDiff >= 0.2f && 0.3f >= rightHeightDiff;
bool leftIsLower = leftHeightDiff >= 0.2f && 0.3f >= leftHeightDiff;

//Ramps tiles are 0.25 lower
if (topIsLower || downIsLower || rightIsLower || leftIsLower)
const auto tileHeight = m_bot.Map().terrainHeight(currentTile.x, currentTile.y);
auto slightlyLowerDiagonalNeighbors = 0;
auto slightlyLowerAdjacentNeighbors = 0;
for (int x = -1; x <= 1; ++x)
{
for (int y = -1; y <= 1; ++y)
{
if (x == 0 && y == 0)
continue;
const auto neighborTile = CCTilePosition(currentTile.x + x, currentTile.y + y);
if (!m_bot.Map().isWalkable(neighborTile))
continue;
const auto neighborHeightDiff = tileHeight - m_bot.Map().terrainHeight(neighborTile);
if(neighborHeightDiff >= 0.24f && neighborHeightDiff <= 0.26f || neighborHeightDiff >= 1.99f && neighborHeightDiff <= 2.01f)
{
const auto diagonal = x != 0 && y != 0;
if (diagonal)
++slightlyLowerDiagonalNeighbors;
else
++slightlyLowerAdjacentNeighbors;
}
}
}
if (slightlyLowerDiagonalNeighbors == 1 || slightlyLowerAdjacentNeighbors == 2)
{
rampTiles.push_back(currentTile);
}
Expand Down Expand Up @@ -186,39 +196,21 @@ std::vector<CCTilePosition> BuildingManager::FindRampTilesToPlaceBuilding(std::l
std::vector<CCTilePosition> tilesToBlock;
for (auto & tile : rampTiles)
{
CCTilePosition below = CCTilePosition(tile.x - 1, tile.y);
CCTilePosition above = CCTilePosition(tile.x + 1, tile.y);
CCTilePosition left = CCTilePosition(tile.x, tile.y - 1);
CCTilePosition right = CCTilePosition(tile.x, tile.y + 1);
if (m_bot.Map().isBuildable(below) && m_bot.Map().isWalkable(below) && m_bot.Map().terrainHeight(tile) == m_bot.Map().terrainHeight(below))
{//we need to block this tile
if (std::find(tilesToBlock.begin(), tilesToBlock.end(), below) == tilesToBlock.end())
{
tilesToBlock.push_back(below);
}
}

if (m_bot.Map().isBuildable(above) && m_bot.Map().isWalkable(above) && m_bot.Map().terrainHeight(tile) == m_bot.Map().terrainHeight(above))
{//we need to block this tile
if (std::find(tilesToBlock.begin(), tilesToBlock.end(), above) == tilesToBlock.end())
{
tilesToBlock.push_back(above);
}
}

if (m_bot.Map().isBuildable(left) && m_bot.Map().isWalkable(left) && m_bot.Map().terrainHeight(tile) == m_bot.Map().terrainHeight(left))
{//we need to block this tile
if (std::find(tilesToBlock.begin(), tilesToBlock.end(), left) == tilesToBlock.end())
{
tilesToBlock.push_back(left);
}
}

if (m_bot.Map().isBuildable(right) && m_bot.Map().isWalkable(right) && m_bot.Map().terrainHeight(tile) == m_bot.Map().terrainHeight(right))
{//we need to block this tile
if (std::find(tilesToBlock.begin(), tilesToBlock.end(), right) == tilesToBlock.end())
for (int x = -1; x <= 1; ++x)
{
for (int y = -1; y <= 1; ++y)
{
tilesToBlock.push_back(right);
if (x == 0 && y == 0 || x != 0 && y != 0)
continue; //only adjacent tiles are parsed
const auto neighbor = CCTilePosition(tile.x + x, tile.y + y);
if (m_bot.Map().isBuildable(neighbor) && m_bot.Map().isWalkable(neighbor) && m_bot.Map().terrainHeight(neighbor) >= m_bot.Map().terrainHeight(tile))
{
//we need to block this tile
if (std::find(tilesToBlock.begin(), tilesToBlock.end(), neighbor) == tilesToBlock.end())
{
tilesToBlock.push_back(neighbor);
}
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/MapTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,10 @@ void MapTools::draw() const
drawTile(x, y, color);
std::string terrainHeight(16, '\0');
std::snprintf(&terrainHeight[0], terrainHeight.size(), "%.2f", m_bot.Map().terrainHeight(x, y));
m_bot.Map().drawText(CCPosition(x, y), terrainHeight, color);
std::stringstream ss;
ss << std::to_string(x) << "," << std::to_string(y) << "\n" << terrainHeight;
//m_bot.Map().drawText(CCPosition(x, y), terrainHeight, color);
m_bot.Map().drawText(CCPosition(x, y), ss.str().c_str(), color);
}
}
}
Expand Down

0 comments on commit 3c2c321

Please sign in to comment.