Compare commits

...

2 commits

10 changed files with 72 additions and 12 deletions

View file

@ -21,6 +21,7 @@ void CUnit::initialize()
this->isScout = false;
this->lastSeen = TilePosition(0, 0);
this->miningBase = -1;
this->squadIndex = -1;
this->target = TilePosition(-1, -1);
}
@ -53,4 +54,12 @@ void CUnit::mine(std::string action, int baseIndex)
{
this->action = action;
this->miningBase = baseIndex;
}
void CUnit::unsetTargetUnit()
{
int queueIndex = Util::getQueueIndex(this->targetUnit);
if(queueIndex > -1)
Macro::queue.at(queueIndex).inProgress = 0;
this->targetUnit = UnitTypes::None;
}

View file

@ -26,9 +26,11 @@ public:
int miningBase;
int resourceType;
int resourceVal;
int squadIndex;
BWAPI::TilePosition target;
BWAPI::UnitType targetUnit;
TilePosition tilePosition;
BWAPI::Unit unit;
BWAPI::UnitType unitType;
void unsetTargetUnit();
};

View file

@ -510,6 +510,15 @@ void CheckItem::checkWorkers()
Macro::freeUnit(i);
}*/
}
else if (Macro::players.at(Macro::selfID).units.at(i).action == "defend")
{
//@TODO bot doesn't build stuff
int squadIndex = Macro::players.at(Macro::selfID).units.at(i).squadIndex;
if (Military::likelihoodToAttack() < 1 && squadIndex > -1)
{
Macro::squads.at(squadIndex).freeDrones();
}
}
}
//std::chrono::duration<double, std::milli> elapsed = std::chrono::high_resolution_clock::now() - start;
//if(elapsed.count() > 1)

View file

@ -105,7 +105,7 @@ void KoraBot::onStart()
Broodwar << "EXCEPTION: " << e.what() << std::endl;
}
Broodwar << "KoraBot 0.0" << std::endl;
Broodwar << "KoraBot 1.0" << std::endl;
}
}
@ -183,10 +183,10 @@ void KoraBot::onFrame()
if (Broodwar->getFrameCount() % Broodwar->getLatencyFrames() != 0)
return;
// in the top right spawn of jade, exposted to center is false for the natural unless it's run later
// in the top right spawn of jade, exposed to center is false for the natural unless it's run later
if (Broodwar->getFrameCount() == 240 * 24)
{
for (unsigned int i = 0; i < Macro::players.at(Macro::selfID).bases.size(); i++)
for (size_t i = 0; i < Macro::players.at(Macro::selfID).bases.size(); i++)
{
Macro::players.at(Macro::selfID).bases.at(i).exposedToCenter = Macro::players.at(Macro::selfID).bases.at(i).isExposedToCenter();
}

View file

@ -112,6 +112,7 @@ void Macro::analyzeQueue()
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;
}
@ -177,6 +178,11 @@ void Macro::freeUnit(int index)
if (base > -1)
players.at(selfID).bases.at(base).subtractWorker(players.at(selfID).units.at(index).action);
}
if (players.at(selfID).units.at(index).action == "expand")
{
stopProduction = 0;
}
players.at(selfID).units.at(index).action = "";
players.at(selfID).units.at(index).miningBase = -1;
players.at(selfID).units.at(index).target = TilePosition(-1, -1);

View file

@ -131,6 +131,7 @@ void Military::checkDefense()
}*/
}
// returns how much attack power is at the specified CBase
double Military::checkEnemiesAt(CBase b)
{
double score = 0;
@ -186,6 +187,13 @@ void Military::checkSquads()
}
}
// for defending in rushes or other low-eco situations
bool Military::droneDefenseNeeded()
{
return (Util::countUnits(Macro::selfID, BWAPI::UnitTypes::Zerg_Zergling) < 10
&& Util::countUnits(Macro::selfID, BWAPI::UnitTypes::Zerg_Hydralisk) < 10);
}
std::pair<TilePosition, int> Military::getAttackLocation()
{
// start here - pick the most vulnerable base (getbasedefense) and attack
@ -356,12 +364,12 @@ bool Military::inThreatRange(TilePosition tp, CUnit unit)
return Util::getDistance(tp, unit.unit->getTilePosition()) < unit.unit->getType().seekRange() + 1;
}
// returns how likely on a scale of 0 to 1 the enemy is to attack soon
// things to consider:
// how long it's been since the last time they attacked
// how many units the enemy might have
double Military::likelihoodToAttack()
{
// things to consider:
// how long it's been since the last time they attacked
// how many units the enemy might have
double score = 1;
double timeModifier = 0;
double attackTime = 360.0 * 24;
@ -389,6 +397,8 @@ double Military::likelihoodToAttack()
return score * timeModifier;
}
// sends a squad to defend
// things to consider:
// how important the place being attacked is
// if a bigger win can be found by attacking instead (base race)
@ -397,26 +407,36 @@ double Military::likelihoodToAttack()
void Military::sendDefense(TilePosition tp, int attackerScore, int defenseScore)
{
int squadIndex = getClosestSquad(tp);
if (squadIndex == -1) squadIndex = 0;
int padding = 80; // give the defense some breathing room
if (squadIndex == -1)
{
squadIndex = 0;
Macro::squads.push_back(Squad());
}
int padding = 80; // give the defense some breathing room by spotting the attackers some damage
Macro::squads.at(squadIndex).action = "defend";
if (defenseScore + Macro::squads.at(squadIndex).groundDamage < attackerScore + padding)
{
int index = 0;
for (auto u : Macro::players.at(Macro::selfID).units)
{
if (defenseScore + Macro::squads.at(squadIndex).groundDamage < attackerScore + padding)
{
if (Util::isAttackingUnit(u)
&& !u.isInSquad()
)
if ((Util::isAttackingUnit(u) || droneDefenseNeeded()) && !u.isInSquad())
{
Macro::squads.at(squadIndex).addUnit(u);
u.squadIndex = squadIndex;
if (u.unit->getType() == UnitTypes::Zerg_Drone)
{
Macro::freeUnit(index);
u.unsetTargetUnit();
}
/*Macro::squads.at(squadIndex).units.push_back(u);
Macro::squads.at(squadIndex).airDamage += u.unitType.airWeapon().damageAmount();
Macro::squads.at(squadIndex).groundDamage += u.unitType.groundWeapon().damageAmount();*/
}
}
index++;
}
}
for (auto u : Macro::squads.at(squadIndex).units)

View file

@ -17,6 +17,7 @@ public:
static void checkDefense();
static double checkEnemiesAt(CBase base);
static void checkSquads();
static bool droneDefenseNeeded();
static std::pair<TilePosition, int> getAttackLocation();
static int getAttackSquadsIndex();
static double getBaseDefense(CBase b, std::string type, int playerID);

View file

@ -48,6 +48,17 @@ bool Squad::containsType(UnitType ut)
return false;
}
void Squad::freeDrones()
{
for (auto u : this->units)
{
if (u.unit->getType() == UnitTypes::Zerg_Drone)
{
Macro::freeUnit(Util::getUnitIndex(u.unit));
}
}
}
void Squad::updateCenter()
{
int averageX = 0;

View file

@ -21,6 +21,7 @@ public:
void attack(std::pair<TilePosition, int> baseToAttack);;
bool contains(CUnit unit);
bool containsType(UnitType ut);
void freeDrones();
void updateCenter();
void updateDamage();
};

View file

@ -200,6 +200,7 @@ int Util::getQueueIndex(UnitType ut)
return i;
}
}
return -1;
}