make checkEnemiesAt radius smaller, add Util::getQueueIndex, setDefenseLocation doesn't compare an area to itself anymore

This commit is contained in:
A 2023-12-02 11:04:28 -06:00
parent 55c78f610b
commit 10a15f585a
6 changed files with 22 additions and 23 deletions

View file

@ -293,6 +293,7 @@ double Analysis::analyzeZergling()
else
{
score += Util::countUnits(Macro::enemyIDs.front(), UnitTypes::Protoss_Dragoon) * 0.05;
score += Util::countUnits(Macro::enemyIDs.front(), UnitTypes::Terran_Machine_Shop) * 0.2;
score += Util::countUnits(Macro::enemyIDs.front(), UnitTypes::Terran_Siege_Tank_Siege_Mode) * 0.1;
score += Util::countUnits(Macro::enemyIDs.front(), UnitTypes::Terran_Siege_Tank_Tank_Mode) * 0.1;
}

View file

@ -264,7 +264,7 @@ void CBase::setDefenseLocation()
const BWEM::Area* targetArea = target.first;
bool foundTarget = target.second;
if (foundTarget)
if (foundTarget && area != targetArea)
{
std::pair<const BWEM::Area*, bool> neighbor = Util::getNeighborArea(area, targetArea);
const BWEM::Area* neighborArea = neighbor.first;
@ -283,10 +283,9 @@ void CBase::setDefenseLocation()
else
{
Broodwar << "Couldn't find neighbor area in CBase::setDefenseLocation()" << std::endl;
Broodwar << targetArea->TopLeft() << std::endl;
}
}
else
else if(!foundTarget)
{
//Broodwar << area->TopLeft() << std::endl;
Broodwar << "Couldn't find target area in CBase::setDefenseLocation()" << std::endl;

View file

@ -312,15 +312,7 @@ void Macro::onUnitDestroy(Unit unit)
newBase = false;
stopProduction = false;
}
int queueIndex = -1;
for (size_t i = 0; i < queue.size(); i++)
{
if (queue.at(i).unit == players.at(id).units.at(index).targetUnit)
{
queueIndex = i;
break;
}
}
int queueIndex = Util::getQueueIndex(players.at(id).units.at(index).targetUnit);
if (queueIndex > -1) queue.erase(queue.begin() + queueIndex);
}
@ -360,15 +352,8 @@ void Macro::onUnitDestroy(Unit unit)
{
squads.at(squadindex).units.erase(squads.at(squadindex).units.begin() + unitindex);
}
int scoutindex = -1;
for (size_t j = 0; j < scouts.size(); j++)
{
if (scouts.at(j).unit->getID() == unit->getID())
{
scoutindex = j;
break;
}
}
int scoutindex = Util::getScoutIndex(unit->getID());
if (scoutindex > -1) scouts.erase(scouts.begin() + scoutindex);
}

View file

@ -90,7 +90,7 @@ void Military::checkDefense()
{
Macro::players.at(Macro::selfID).bases.at(i).getDefense();
double attackerScore = checkEnemiesAt(Macro::players.at(Macro::selfID).bases.at(i));
if (attackerScore > 5)
if (attackerScore >= 5)
{
attacking = true;
Macro::setLastAttack(Broodwar->getFrameCount());
@ -135,7 +135,7 @@ void Military::checkDefense()
double Military::checkEnemiesAt(CBase b)
{
double score = 0;
for (auto u : b.base->getUnitsInRadius(32*20, Filter::IsEnemy))
for (auto u : b.base->getUnitsInRadius(32*15, Filter::IsEnemy))
{
if (u->getType().groundWeapon() != WeaponTypes::None)
{
@ -422,6 +422,7 @@ void Military::sendDefense(TilePosition tp, int attackerScore, int defenseScore)
{
if (defenseScore + Macro::squads.at(squadIndex).groundDamage < attackerScore + padding)
{
// this is pulling drones when it shouldn't be
if ((Util::isAttackingUnit(u) || droneDefenseNeeded()) && !u.isInSquad())
{
Macro::squads.at(squadIndex).addUnit(u);

View file

@ -218,6 +218,18 @@ int Util::getQueueIndex(UnitType ut)
return -1;
}
int Util::getScoutIndex(int unitID)
{
for (size_t j = 0; j < Macro::scouts.size(); j++)
{
if (Macro::scouts.at(j).unit->getID() == unitID)
{
return j;
}
}
return -1;
}
int Util::getStaticDCount(int playerID, std::string type = "all")
{
if (type == "air")

View file

@ -27,6 +27,7 @@ public:
static std::pair<const BWEM::Area*, bool> getNeighborArea(const BWEM::Area* a1, const BWEM::Area* a2);
static CBase getNextExpand(int playerID);
static int getQueueIndex(UnitType ut);
static int getScoutIndex(int unitID);
static int getStaticDCount(int playerID, std::string type);
static std::pair<const BWEM::Area*, bool> getTargetArea(const BWEM::Area* startingArea, bool startLocation);
static int getUnitIndex(Unit unit);