bot defends against zergling rushes now, added now, added unsetTargetUnit, droneDefenseNeeded, among others
This commit is contained in:
parent
71f26b01ee
commit
e5c2079866
|
@ -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,10 @@ void CUnit::mine(std::string action, int baseIndex)
|
|||
{
|
||||
this->action = action;
|
||||
this->miningBase = baseIndex;
|
||||
}
|
||||
|
||||
void CUnit::unsetTargetUnit()
|
||||
{
|
||||
this->targetUnit = UnitTypes::None;
|
||||
Macro::queue.at(Util::getQueueIndex(this->targetUnit)).inProgress = 0;
|
||||
}
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
};
|
Loading…
Reference in a new issue