add more files to .gitignore, continue clean up of files and functions
This commit is contained in:
parent
8755548d08
commit
8a261dcb0f
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
/Debug
|
||||
/KoraBotTest/Release
|
||||
/KoraBotTests
|
||||
/Release
|
||||
/.vs
|
|
@ -48,7 +48,7 @@
|
|||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../BWAPILIB/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;_DEBUG;_WINDOWS;_USRDLL;KORABOT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
|
@ -72,7 +72,7 @@
|
|||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<AdditionalIncludeDirectories>../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../BWAPILIB/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NOMINMAX;WIN32;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010300;NDEBUG;_WINDOWS;_USRDLL;KORABOT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <BWAPI.h>
|
||||
|
||||
#include "../Source/BWEM/src/bwem.h"
|
||||
#include "../kora-bot/Source/CUnit.h"
|
||||
#include "../Source/CUnit.h"
|
||||
|
||||
using namespace BWAPI;
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../include;$(SolutionDir)Release\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../../BWAPILIB/include;$(SolutionDir)Release\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -100,7 +100,7 @@
|
|||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<AdditionalIncludeDirectories>../../include;$(SolutionDir)Release\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../../BWAPILIB/include;$(SolutionDir)Release\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -117,7 +117,7 @@
|
|||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<AdditionalIncludeDirectories>../../include;$(SolutionDir)Release\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../../BWAPILIB/include;$(SolutionDir)Release\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -136,7 +136,7 @@
|
|||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
<AdditionalIncludeDirectories>../../include;$(SolutionDir)Release\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>../../BWAPILIB/include;$(SolutionDir)Release\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#pragma once
|
||||
#include <BWAPI.h>
|
||||
|
||||
#include "../Source/BWEM/src/bwem.h";
|
||||
#include "../Source/Macro.h";
|
||||
#include "../Source/BWEM/src/bwem.h"
|
||||
#include "../Source/Macro.h"
|
||||
|
||||
using namespace BWAPI;
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
#pragma once
|
||||
#include <BWAPI.h>
|
||||
|
||||
#include "../Source/BWEM/src/bwem.h";
|
||||
#include "../Source/CBase.h";
|
||||
#include "../Source/Util.h";
|
||||
#include "../Source/BWEM/src/bwem.h"
|
||||
#include "../Source/CBase.h"
|
||||
#include "../Source/Util.h"
|
||||
|
||||
using namespace BWAPI;
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ bool CBase::isExposedToCenter()
|
|||
// if it contains a base, then the target Area is not
|
||||
// exposed to the center
|
||||
int count = 0;
|
||||
for (auto a : Util::getPath(area, targetArea))
|
||||
for (auto a : CMap::getPath(area, targetArea))
|
||||
{
|
||||
if (a->Id() == area->Id()) continue;
|
||||
if (a->AccessibleNeighbours().size() > 2) return true;
|
||||
|
|
107
Source/CMap.cpp
107
Source/CMap.cpp
|
@ -15,4 +15,111 @@ TilePosition CMap::getAreaAverage(const BWEM::Area area)
|
|||
int xAverage = (area.TopLeft().x + area.BottomRight().x) / 2;
|
||||
int yAverage = (area.TopLeft().y + area.BottomRight().y) / 2;
|
||||
return TilePosition(xAverage, yAverage);
|
||||
}
|
||||
|
||||
// gets a walking path from one Area to another
|
||||
// this is just the a* pathfinding algorithm
|
||||
std::vector<const BWEM::Area*> CMap::getPath(const BWEM::Area* a1, const BWEM::Area* a2)
|
||||
{
|
||||
std::vector<const BWEM::Area*> returnPath;
|
||||
std::vector<const BWEM::Area*> closedSet;
|
||||
std::vector<const BWEM::Area*> openSet;
|
||||
openSet.push_back(a1);
|
||||
|
||||
std::map<const BWEM::Area*, const BWEM::Area*> cameFrom;
|
||||
std::map<int, int> gScore;
|
||||
|
||||
for (const BWEM::Area& a : map.Areas())
|
||||
{
|
||||
gScore.insert(std::pair<int, int>(a.Id(), 10000));
|
||||
}
|
||||
|
||||
gScore[a1->Id()] = 0;
|
||||
|
||||
while (!openSet.empty())
|
||||
{
|
||||
const BWEM::Area* current;
|
||||
|
||||
int score = 9999;
|
||||
for (auto o : openSet)
|
||||
{
|
||||
if (gScore[o->Id()] < score)
|
||||
{
|
||||
score = gScore[o->Id()];
|
||||
current = o;
|
||||
}
|
||||
}
|
||||
|
||||
if (current->Id() == a2->Id()) // found the goal
|
||||
{
|
||||
std::vector<const BWEM::Area*> path;
|
||||
|
||||
for (auto const& ent : cameFrom)
|
||||
{
|
||||
path.push_back(ent.first);
|
||||
}
|
||||
|
||||
path.push_back(current);
|
||||
return reconstructPath(cameFrom, current);
|
||||
}
|
||||
|
||||
// remove current from openSet
|
||||
int index = 0;
|
||||
for (size_t i = 0; i < openSet.size(); i++)
|
||||
{
|
||||
if (current == openSet.at(i))
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
openSet.erase(openSet.begin() + index);
|
||||
|
||||
// add current to closedSet
|
||||
closedSet.push_back(current);
|
||||
|
||||
for (auto n : current->AccessibleNeighbours())
|
||||
{
|
||||
if (std::find(closedSet.begin(), closedSet.end(), n) != closedSet.end()) // if the neighbor is in the closed set, ignore
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
TilePosition tp1 = CMap::getAreaAverage(current);
|
||||
TilePosition tp2 = CMap::getAreaAverage(n);
|
||||
|
||||
int tentativeGScore = gScore[current->Id()] + 2;
|
||||
|
||||
if (!(std::find(openSet.begin(), openSet.end(), n) != openSet.end()))
|
||||
{
|
||||
openSet.push_back(n);
|
||||
}
|
||||
else if (tentativeGScore >= gScore[n->Id()])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
cameFrom[n] = current;
|
||||
//cameFrom.emplace(n, current);
|
||||
gScore[n->Id()] = tentativeGScore;
|
||||
}
|
||||
}
|
||||
|
||||
return returnPath;
|
||||
}
|
||||
|
||||
// used by getPath to format the final path
|
||||
std::vector<const BWEM::Area*> CMap::reconstructPath(std::map<const BWEM::Area*, const BWEM::Area*> cameFrom, const BWEM::Area* current)
|
||||
{
|
||||
std::vector<const BWEM::Area*> returnPath;
|
||||
returnPath.push_back(current);
|
||||
|
||||
while (cameFrom.find(current) != cameFrom.end())
|
||||
{
|
||||
current = cameFrom[current];
|
||||
returnPath.push_back(current);
|
||||
}
|
||||
|
||||
std::reverse(returnPath.begin(), returnPath.end());
|
||||
|
||||
return returnPath;
|
||||
}
|
|
@ -15,4 +15,6 @@ class CMap
|
|||
public:
|
||||
static TilePosition getAreaAverage(const BWEM::Area* area);
|
||||
static TilePosition getAreaAverage(const BWEM::Area area);
|
||||
static std::vector<const BWEM::Area*> getPath(const BWEM::Area* a1, const BWEM::Area* a2);
|
||||
static std::vector<const BWEM::Area*> reconstructPath(std::map<const BWEM::Area*, const BWEM::Area*> cameFrom, const BWEM::Area* current);
|
||||
};
|
|
@ -18,6 +18,7 @@ CUnit::CUnit(BWAPI::Unit unit)
|
|||
void CUnit::initialize()
|
||||
{
|
||||
this->action = "";
|
||||
this->isScout = false;
|
||||
this->lastSeen = TilePosition(0, 0);
|
||||
this->miningBase = -1;
|
||||
this->target = TilePosition(-1, -1);
|
||||
|
@ -43,6 +44,11 @@ bool CUnit::isInSquad()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CUnit::isMining()
|
||||
{
|
||||
return (this->action == "minerals" || this->action == "gas");
|
||||
}
|
||||
|
||||
void CUnit::mine(std::string action, int baseIndex)
|
||||
{
|
||||
this->action = action;
|
||||
|
|
|
@ -15,10 +15,12 @@ public:
|
|||
CUnit(BWAPI::Unit unit);
|
||||
|
||||
std::string action;
|
||||
int id;
|
||||
void initialize();
|
||||
bool isIdle();
|
||||
bool isInSquad();
|
||||
int id;
|
||||
bool isMining();
|
||||
bool isScout;
|
||||
BWAPI::TilePosition lastSeen;
|
||||
void mine(std::string action, int baseIndex);
|
||||
int miningBase;
|
||||
|
|
|
@ -215,9 +215,9 @@ void KoraBot::onFrame()
|
|||
CheckItem::checkSunken();
|
||||
CheckItem::checkUltraCavern();
|
||||
Macro::morphCreepColonies();
|
||||
Macro::setScouts();
|
||||
Military::checkAttack();
|
||||
Military::checkSquads();
|
||||
Scouting::setScouts();
|
||||
}
|
||||
|
||||
// functions to be run about every two seconds
|
||||
|
|
|
@ -39,6 +39,7 @@ void Macro::addSquad()
|
|||
}
|
||||
|
||||
// does top-level analysis of what to build
|
||||
//@TODO clean this up
|
||||
void Macro::analyzeQueue()
|
||||
{
|
||||
std::string entry = "";
|
||||
|
@ -65,12 +66,8 @@ void Macro::analyzeQueue()
|
|||
|
||||
if (index > -1)
|
||||
{
|
||||
if (queue.at(index).isTech())
|
||||
if (queue.at(index).isUnit())
|
||||
{
|
||||
}
|
||||
else if (queue.at(index).isUnit())
|
||||
{
|
||||
//Broodwar << queue.at(index).unit << std::endl;
|
||||
if (!queue.at(index).unit.isBuilding())
|
||||
{
|
||||
if (!stopProduction || Broodwar->self()->minerals() > 300 + queue.at(index).unit.mineralPrice())
|
||||
|
@ -105,21 +102,16 @@ void Macro::analyzeQueue()
|
|||
else
|
||||
{
|
||||
players.at(selfID).units.at(workerIndex).action = "build";
|
||||
TilePosition target;
|
||||
if (queue.at(index).unit == UnitTypes::Zerg_Sunken_Colony)
|
||||
TilePosition target = BuildingPlacement::getPosition(players.at(selfID).units.at(workerIndex).targetUnit);
|
||||
if (queue.at(index).unit == UnitTypes::Zerg_Sunken_Colony
|
||||
|| queue.at(index).unit == UnitTypes::Zerg_Spore_Colony)
|
||||
{
|
||||
players.at(selfID).units.at(workerIndex).targetUnit = UnitTypes::Zerg_Creep_Colony;
|
||||
target = BuildingPlacement::getPosition(UnitTypes::Zerg_Sunken_Colony);
|
||||
}
|
||||
else if (queue.at(index).unit == UnitTypes::Zerg_Spore_Colony)
|
||||
{
|
||||
players.at(selfID).units.at(workerIndex).targetUnit = UnitTypes::Zerg_Creep_Colony;
|
||||
target = BuildingPlacement::getPosition(UnitTypes::Zerg_Spore_Colony);
|
||||
target = BuildingPlacement::getPosition(queue.at(index).unit);
|
||||
}
|
||||
else
|
||||
{
|
||||
players.at(selfID).units.at(workerIndex).targetUnit = queue.at(index).unit;
|
||||
target = BuildingPlacement::getPosition(players.at(selfID).units.at(workerIndex).targetUnit);
|
||||
}
|
||||
players.at(selfID).units.at(workerIndex).target = target;
|
||||
}
|
||||
|
@ -165,8 +157,7 @@ int Macro::findMiningBase(BWAPI::Unit unit, std::string type)
|
|||
{
|
||||
int d = unit->getDistance(players.at(selfID).bases.at(i).base);
|
||||
|
||||
if (d < distance &&
|
||||
!players.at(selfID).bases.at(i).isSaturated(type))
|
||||
if (d < distance && !players.at(selfID).bases.at(i).isSaturated(type))
|
||||
{
|
||||
distance = d;
|
||||
index = i;
|
||||
|
@ -177,10 +168,10 @@ int Macro::findMiningBase(BWAPI::Unit unit, std::string type)
|
|||
return index;
|
||||
}
|
||||
|
||||
// stops a drone from mining minerals or gas
|
||||
void Macro::freeUnit(int index)
|
||||
{
|
||||
if (players.at(selfID).units.at(index).action == "minerals"
|
||||
|| players.at(selfID).units.at(index).action == "gas")
|
||||
if (players.at(selfID).units.at(index).isMining())
|
||||
{
|
||||
int base = players.at(selfID).units.at(index).miningBase;
|
||||
if (base > -1)
|
||||
|
@ -193,6 +184,7 @@ void Macro::freeUnit(int index)
|
|||
//players.at(selfID).units.at(index).unit->stop();
|
||||
}
|
||||
|
||||
// find a base with larva to morph a unit at
|
||||
CUnit Macro::getTrainingBase()
|
||||
{
|
||||
int id = 0;
|
||||
|
@ -250,15 +242,14 @@ void Macro::onUnitComplete(Unit unit)
|
|||
|
||||
for (auto b : bases)
|
||||
{
|
||||
if (unit->getTilePosition().x == b.tilePosition.x
|
||||
&& unit->getTilePosition().y == b.tilePosition.y)
|
||||
if (Util::isSameTilePosition(unit->getTilePosition(), b.tilePosition))
|
||||
{
|
||||
chk = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (chk && players.at(selfID).bases.size() > 0) players.at(selfID).bases.back().complete = true;
|
||||
if (Util::isBase(unit) && players.at(selfID).bases.size() > 0) players.at(selfID).bases.back().complete = true;
|
||||
}
|
||||
int unitIndex = Util::getUnitIndex(unit);
|
||||
if (unitIndex > -1)
|
||||
|
@ -278,7 +269,7 @@ void Macro::onUnitCreate(Unit unit)
|
|||
{
|
||||
for (auto b : bases)
|
||||
{
|
||||
if (unit->getTilePosition().x == b.tilePosition.x && unit->getTilePosition().y == b.tilePosition.y)
|
||||
if (Util::isSameTilePosition(unit->getTilePosition(), b.tilePosition))
|
||||
{
|
||||
CBase base = CBase(unit);
|
||||
base.complete = true;
|
||||
|
@ -290,6 +281,7 @@ void Macro::onUnitCreate(Unit unit)
|
|||
}
|
||||
}
|
||||
|
||||
//@TODO clean this up
|
||||
void Macro::onUnitDestroy(Unit unit)
|
||||
{
|
||||
if (unit->getPlayer() != Broodwar->neutral())
|
||||
|
@ -311,6 +303,7 @@ void Macro::onUnitDestroy(Unit unit)
|
|||
if (players.at(id).units.at(index).action == "expand")
|
||||
{
|
||||
newBase = false;
|
||||
stopProduction = false;
|
||||
}
|
||||
int queueIndex = -1;
|
||||
for (size_t i = 0; i < queue.size(); i++)
|
||||
|
@ -522,28 +515,6 @@ void Macro::setNewBase(bool status)
|
|||
newBase = status;
|
||||
}
|
||||
|
||||
void Macro::setScouts()
|
||||
{
|
||||
if (scouts.size() < 4)
|
||||
{
|
||||
bool added = false;
|
||||
for (size_t i = 0; i < players.at(selfID).units.size(); i++)
|
||||
{
|
||||
if (players.at(selfID).units.at(i).unit->getType() == UnitTypes::Zerg_Overlord && !added)
|
||||
{
|
||||
bool found = Scouting::isScout(players.at(selfID).units.at(i));
|
||||
|
||||
if (!added && !found || scouts.size() == 0)
|
||||
{
|
||||
players.at(selfID).units.at(i).action = "scout";
|
||||
scouts.push_back(players.at(selfID).units.at(i));
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Macro::setSelfID(int id)
|
||||
{
|
||||
selfID = id;
|
||||
|
|
|
@ -76,6 +76,5 @@ public:
|
|||
static bool queueHas(BWAPI::UpgradeType upgrade);
|
||||
|
||||
// scouting
|
||||
static void setScouts();
|
||||
static bool workerScout;
|
||||
};
|
|
@ -83,7 +83,7 @@ void Military::checkAttack()
|
|||
if (squadIndex > -1)
|
||||
{
|
||||
addSquadlessUnits(squadIndex);
|
||||
Macro::squads.at(squadIndex).checkDamage();
|
||||
Macro::squads.at(squadIndex).updateDamage();
|
||||
|
||||
if (Macro::squads.at(squadIndex).groundDamage > baseToAttack.second + damagePadding)
|
||||
{
|
||||
|
@ -163,8 +163,8 @@ void Military::checkSquads()
|
|||
int added = 0;
|
||||
for (size_t i = 0; i < Macro::squads.size(); i++)
|
||||
{
|
||||
Macro::squads.at(i).checkCenter();
|
||||
Macro::squads.at(i).checkDamage();
|
||||
Macro::squads.at(i).updateCenter();
|
||||
Macro::squads.at(i).updateDamage();
|
||||
|
||||
if (Macro::squads.at(i).units.size() > 0)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "Scouting.h"
|
||||
|
||||
//@TODO this is fugly
|
||||
TilePosition Scouting::getScoutingLocation()
|
||||
{
|
||||
TilePosition location = TilePosition(0, 0);
|
||||
|
@ -33,7 +34,6 @@ TilePosition Scouting::getScoutingLocation()
|
|||
|
||||
for (size_t i = 0; i < Macro::locations.size(); i++)
|
||||
{
|
||||
|
||||
if (Util::ownedBy(Macro::locations.at(i).tilePosition) == Macro::enemyIDs.front())
|
||||
{
|
||||
if (!locationScouted(Macro::locations.at(i))
|
||||
|
@ -84,18 +84,6 @@ TilePosition Scouting::getScoutingLocation()
|
|||
return Macro::locations.at(index).tilePosition;
|
||||
}
|
||||
|
||||
bool Scouting::isScout(CUnit u)
|
||||
{
|
||||
for (size_t j = 0; j < Macro::scouts.size(); j++)
|
||||
{
|
||||
if (Macro::scouts.at(j).unit->getID() == u.unit->getID())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Scouting::locationScouted(Location l)
|
||||
{
|
||||
for (size_t i = 0; i < Macro::scouts.size(); i++)
|
||||
|
@ -167,3 +155,24 @@ void Scouting::scout()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Scouting::setScouts()
|
||||
{
|
||||
if (Macro::scouts.size() < 4)
|
||||
{
|
||||
bool added = false;
|
||||
for (size_t i = 0; i < Macro::players.at(Macro::selfID).units.size(); i++)
|
||||
{
|
||||
if (Macro::players.at(Macro::selfID).units.at(i).unit->getType() == UnitTypes::Zerg_Overlord && !added)
|
||||
{
|
||||
if (!added && !Macro::players.at(Macro::selfID).units.at(i).isScout || Macro::scouts.size() == 0)
|
||||
{
|
||||
Macro::players.at(Macro::selfID).units.at(i).action = "scout";
|
||||
Macro::players.at(Macro::selfID).units.at(i).isScout = true;
|
||||
Macro::scouts.push_back(Macro::players.at(Macro::selfID).units.at(i));
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,6 +17,6 @@ public:
|
|||
|
||||
static int checkNextBase();
|
||||
static TilePosition getScoutingLocation();
|
||||
static bool isScout(CUnit unit);
|
||||
static bool locationScouted(Location l);
|
||||
static void setScouts();
|
||||
};
|
|
@ -28,37 +28,6 @@ void Squad::attack(std::pair<TilePosition, int> baseToAttack)
|
|||
}
|
||||
}
|
||||
|
||||
//TODO rename
|
||||
void Squad::checkCenter()
|
||||
{
|
||||
int averageX = 0;
|
||||
int averageY = 0;
|
||||
int size = this->units.size();
|
||||
if (size == 0) size = 1;
|
||||
|
||||
for (auto u : this->units)
|
||||
{
|
||||
averageX += u.unit->getTilePosition().x;
|
||||
averageY += u.unit->getTilePosition().y;
|
||||
}
|
||||
|
||||
this->center = TilePosition((averageX / size), (averageY / size));
|
||||
}
|
||||
|
||||
//TODO rename
|
||||
void Squad::checkDamage()
|
||||
{
|
||||
int ground = 0;
|
||||
int air = 0;
|
||||
for (auto u : this->units)
|
||||
{
|
||||
ground += u.unitType.groundWeapon().damageAmount();
|
||||
air += u.unitType.airWeapon().damageAmount();
|
||||
}
|
||||
this->groundDamage = ground;
|
||||
this->airDamage = air;
|
||||
}
|
||||
|
||||
bool Squad::contains(CUnit unit)
|
||||
{
|
||||
for (size_t i = 0; i < this->units.size(); i++)
|
||||
|
@ -77,4 +46,33 @@ bool Squad::containsType(UnitType ut)
|
|||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Squad::updateCenter()
|
||||
{
|
||||
int averageX = 0;
|
||||
int averageY = 0;
|
||||
int size = this->units.size();
|
||||
if (size == 0) size = 1;
|
||||
|
||||
for (auto u : this->units)
|
||||
{
|
||||
averageX += u.unit->getTilePosition().x;
|
||||
averageY += u.unit->getTilePosition().y;
|
||||
}
|
||||
|
||||
this->center = TilePosition((averageX / size), (averageY / size));
|
||||
}
|
||||
|
||||
void Squad::updateDamage()
|
||||
{
|
||||
int ground = 0;
|
||||
int air = 0;
|
||||
for (auto u : this->units)
|
||||
{
|
||||
ground += u.unitType.groundWeapon().damageAmount();
|
||||
air += u.unitType.airWeapon().damageAmount();
|
||||
}
|
||||
this->groundDamage = ground;
|
||||
this->airDamage = air;
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@ public:
|
|||
std::vector<CUnit> units;
|
||||
|
||||
void addUnit(CUnit unit);
|
||||
void attack(std::pair<TilePosition, int> baseToAttack);
|
||||
void checkCenter();
|
||||
void checkDamage();
|
||||
void attack(std::pair<TilePosition, int> baseToAttack);;
|
||||
bool contains(CUnit unit);
|
||||
bool containsType(UnitType ut);
|
||||
void updateCenter();
|
||||
void updateDamage();
|
||||
};
|
155
Source/Util.cpp
155
Source/Util.cpp
|
@ -117,6 +117,7 @@ int Util::getBaseIndex(Unit u)
|
|||
//@TODO move this to CUnit
|
||||
int Util::getClosestOwnedBase(Unit unit)
|
||||
{
|
||||
unit->getUnitsInRadius(256*32, BWAPI::Filter::IsResourceDepot);
|
||||
double distance = 1000;
|
||||
int index = -1;
|
||||
for (size_t i = 0; i < Macro::players.at(Macro::selfID).bases.size(); i++)
|
||||
|
@ -156,7 +157,7 @@ std::pair<const BWEM::Area*, bool> Util::getNeighborArea(const BWEM::Area* a1, c
|
|||
const BWEM::Area* area;
|
||||
int count = 0;
|
||||
|
||||
std::vector< const BWEM::Area*> path = Util::getPath(a1, a2);
|
||||
std::vector< const BWEM::Area*> path = CMap::getPath(a1, a2);
|
||||
if(path.size() > 1)
|
||||
return std::pair<const BWEM::Area*, bool>(path.at(1), true);
|
||||
|
||||
|
@ -190,96 +191,6 @@ CBase Util::getNextExpand(int playerID)
|
|||
return Macro::bases.at(index);
|
||||
}
|
||||
|
||||
// gets a walking path from one Area to another
|
||||
// this is just the a* pathfinding algorithm
|
||||
std::vector<const BWEM::Area*> Util::getPath(const BWEM::Area* a1, const BWEM::Area* a2)
|
||||
{
|
||||
std::vector<const BWEM::Area*> returnPath;
|
||||
std::vector<const BWEM::Area*> closedSet;
|
||||
std::vector<const BWEM::Area*> openSet;
|
||||
openSet.push_back(a1);
|
||||
|
||||
std::map<const BWEM::Area*, const BWEM::Area*> cameFrom;
|
||||
std::map<int, int> gScore;
|
||||
|
||||
for (const BWEM::Area& a : map.Areas())
|
||||
{
|
||||
gScore.insert(std::pair<int, int>(a.Id(), 10000));
|
||||
}
|
||||
|
||||
gScore[a1->Id()] = 0;
|
||||
|
||||
while (!openSet.empty())
|
||||
{
|
||||
const BWEM::Area* current;
|
||||
|
||||
int score = 9999;
|
||||
for (auto o : openSet)
|
||||
{
|
||||
if (gScore[o->Id()] < score)
|
||||
{
|
||||
score = gScore[o->Id()];
|
||||
current = o;
|
||||
}
|
||||
}
|
||||
|
||||
if (current->Id() == a2->Id()) // found the goal
|
||||
{
|
||||
std::vector<const BWEM::Area*> path;
|
||||
|
||||
for (auto const& ent : cameFrom)
|
||||
{
|
||||
path.push_back(ent.first);
|
||||
}
|
||||
|
||||
path.push_back(current);
|
||||
return reconstructPath(cameFrom, current);
|
||||
}
|
||||
|
||||
// remove current from openSet
|
||||
int index = 0;
|
||||
for (int i = 0; i < openSet.size(); i++)
|
||||
{
|
||||
if (current == openSet.at(i))
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
openSet.erase(openSet.begin() + index);
|
||||
|
||||
// add current to closedSet
|
||||
closedSet.push_back(current);
|
||||
|
||||
for (auto n : current->AccessibleNeighbours())
|
||||
{
|
||||
if (std::find(closedSet.begin(), closedSet.end(), n) != closedSet.end()) // if the neighbor is in the closed set, ignore
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
TilePosition tp1 = CMap::getAreaAverage(current);
|
||||
TilePosition tp2 = CMap::getAreaAverage(n);
|
||||
|
||||
int tentativeGScore = gScore[current->Id()] + 2;
|
||||
|
||||
if (!(std::find(openSet.begin(), openSet.end(), n) != openSet.end()))
|
||||
{
|
||||
openSet.push_back(n);
|
||||
}
|
||||
else if(tentativeGScore >= gScore[n->Id()])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
cameFrom[n] = current;
|
||||
//cameFrom.emplace(n, current);
|
||||
gScore[n->Id()] = tentativeGScore;
|
||||
}
|
||||
}
|
||||
|
||||
return returnPath;
|
||||
}
|
||||
|
||||
int Util::getQueueIndex(UnitType ut)
|
||||
{
|
||||
for (size_t i = 0; i < Macro::queue.size(); i++)
|
||||
|
@ -319,26 +230,6 @@ std::pair<const BWEM::Area*, bool> Util::getTargetArea(const BWEM::Area* startin
|
|||
}
|
||||
}
|
||||
|
||||
/*for (const BWEM::Area& a : map.Areas())
|
||||
{
|
||||
for (const BWEM::Base& b : a.Bases())
|
||||
{
|
||||
if (b.Starting() && !(isSameArea(a, startingArea))
|
||||
{
|
||||
bool chk = true;
|
||||
if (!startLocation
|
||||
&& Macro::players.at(Macro::selfID).bases.size() > 0
|
||||
&& Macro::players.at(Macro::selfID).bases.front().tilePosition == b.Location())
|
||||
{
|
||||
chk = false;
|
||||
}
|
||||
if (chk)
|
||||
{
|
||||
return std::pair<const BWEM::Area*, bool>(&a, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return std::pair<const BWEM::Area*, bool>(area, false);
|
||||
}
|
||||
|
||||
|
@ -362,7 +253,7 @@ double Util::getWalkDistance(TilePosition tp1, TilePosition tp2)
|
|||
TilePosition currentPosition = tp1;
|
||||
|
||||
int count = 0;
|
||||
for (auto a : getPath(area, targetArea))
|
||||
for (auto a : CMap::getPath(area, targetArea))
|
||||
{
|
||||
if (count > 0)
|
||||
{
|
||||
|
@ -384,6 +275,20 @@ bool Util::isAttackingUnit(CUnit u)
|
|||
&& u.unit->getType() != UnitTypes::Zerg_Overlord);
|
||||
}
|
||||
|
||||
// run on hatcheries to see if they're a macro hatch or a mining base
|
||||
bool Util::isBase(Unit unit)
|
||||
{
|
||||
for (auto b : Macro::bases)
|
||||
{
|
||||
if (isSameTilePosition(unit->getTilePosition(), b.tilePosition))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// determines if a tileposition is a base position
|
||||
bool Util::isBasePosition(TilePosition tp)
|
||||
{
|
||||
|
@ -401,12 +306,17 @@ bool Util::isSameArea(const BWEM::Area* area1, const BWEM::Area* area2)
|
|||
&& area1->TopLeft().y == area2->TopLeft().y);
|
||||
}
|
||||
|
||||
bool Util::isSameTilePosition(TilePosition tp1, TilePosition tp2)
|
||||
{
|
||||
return (tp1.x == tp2.x && tp1.y == tp2.y);
|
||||
}
|
||||
|
||||
// returns id of player who owns a base at tileposition tp
|
||||
int Util::ownedBy(TilePosition tp)
|
||||
{
|
||||
for (int i = 0; i < Macro::players.size(); i++)
|
||||
for (size_t i = 0; i < Macro::players.size(); i++)
|
||||
{
|
||||
for (int j = 0; j < Macro::players.at(i).bases.size(); j++)
|
||||
for (size_t j = 0; j < Macro::players.at(i).bases.size(); j++)
|
||||
{
|
||||
if (Macro::players.at(i).bases.at(j).tilePosition == tp) return i;
|
||||
}
|
||||
|
@ -415,23 +325,6 @@ int Util::ownedBy(TilePosition tp)
|
|||
return -1;
|
||||
}
|
||||
|
||||
// used by Util::getPath
|
||||
std::vector<const BWEM::Area*> Util::reconstructPath(std::map<const BWEM::Area*, const BWEM::Area*> cameFrom, const BWEM::Area* current)
|
||||
{
|
||||
std::vector<const BWEM::Area*> returnPath;
|
||||
returnPath.push_back(current);
|
||||
|
||||
while (cameFrom.find(current) != cameFrom.end())
|
||||
{
|
||||
current = cameFrom[current];
|
||||
returnPath.push_back(current);
|
||||
}
|
||||
|
||||
std::reverse(returnPath.begin(), returnPath.end());
|
||||
|
||||
return returnPath;
|
||||
}
|
||||
|
||||
bool Util::unitCounted(Unit unit)
|
||||
{
|
||||
for (auto u : Macro::players.at(unit->getPlayer()->getID()).units)
|
||||
|
|
|
@ -25,16 +25,16 @@ public:
|
|||
static int getLocation(TilePosition tp);
|
||||
static std::pair<const BWEM::Area*, bool> getNeighborArea(const BWEM::Area* a1, const BWEM::Area* a2);
|
||||
static CBase getNextExpand(int playerID);
|
||||
static std::vector<const BWEM::Area*> getPath(const BWEM::Area* a1, const BWEM::Area* a2);
|
||||
static int getQueueIndex(UnitType ut);
|
||||
static std::pair<const BWEM::Area*, bool> getTargetArea(const BWEM::Area* startingArea, bool startLocation);
|
||||
static int getUnitIndex(Unit unit);
|
||||
static double getWalkDistance(TilePosition tp1, TilePosition tp2);
|
||||
static bool isAttackingUnit(CUnit u);
|
||||
static bool isBase(Unit unit);
|
||||
static bool isBasePosition(TilePosition tp);
|
||||
static bool isSameArea(const BWEM::Area* area1, const BWEM::Area* area2);
|
||||
static bool isSameTilePosition(TilePosition tp1, TilePosition tp2);
|
||||
static int ownedBy(TilePosition tp);
|
||||
static std::vector<const BWEM::Area*> reconstructPath(std::map<const BWEM::Area*, const BWEM::Area*> cameFrom, const BWEM::Area* current);
|
||||
static bool unitCounted(Unit unit);
|
||||
static int workerBuildingTargetCount(UnitType unit);
|
||||
};
|
Loading…
Reference in a new issue