add likelihoodToAttack as params for a bunch of analysis functions, add a couple to dos, add a few more params for analyzeMuta and analyzeZergling to consider

This commit is contained in:
A 2023-04-13 19:43:30 -05:00
parent 34194b88c7
commit c22cfd8170
9 changed files with 75 additions and 31 deletions

View File

@ -10,26 +10,27 @@ double Analysis::analyze(TechType tech)
double Analysis::analyze(BWAPI::UnitType unit)
{
double score = 0;
double likelihoodToAttack = Military::likelihoodToAttack();
switch (unit)
{
case UnitTypes::Zerg_Drone:
score = analyzeDrone();
score = analyzeDrone(likelihoodToAttack);
break;
case UnitTypes::Zerg_Evolution_Chamber:
score = analyzeEvoChamber();
score = analyzeEvoChamber(likelihoodToAttack);
break;
case UnitTypes::Zerg_Extractor:
score = analyzeGas();
break;
case UnitTypes::Zerg_Hatchery:
score = analyzeHatchery();
score = analyzeHatchery(likelihoodToAttack);
break;
case UnitTypes::Zerg_Hive:
score = analyzeHive();
break;
case UnitTypes::Zerg_Hydralisk:
score = analyzeHydralisk();
score = analyzeHydralisk(likelihoodToAttack);
break;
case UnitTypes::Zerg_Hydralisk_Den:
score = analyzeHydraDen();
@ -41,7 +42,7 @@ double Analysis::analyze(BWAPI::UnitType unit)
score = analyzeMutalisk();
break;
case UnitTypes::Zerg_Overlord:
score = analyzeOverlord();
score = analyzeOverlord(likelihoodToAttack);
break;
case UnitTypes::Zerg_Queens_Nest:
score = analyzeQueensNest();
@ -100,7 +101,7 @@ double Analysis::analyze(UpgradeType upgrade)
return score;
}
double Analysis::analyzeDrone()
double Analysis::analyzeDrone(double likelihoodToAttack)
{
double score = 0;
if (Util::countUnits(Macro::selfID, UnitTypes::Zerg_Drone) < 65)
@ -110,12 +111,12 @@ double Analysis::analyzeDrone()
score -= Util::eggCount(UnitTypes::Zerg_Drone) * 0.02;
if (Military::likelihoodToAttack() > 0.7) score -= 0.4;
if (likelihoodToAttack > 0.7) score -= 0.4;
return score;
}
double Analysis::analyzeEvoChamber()
double Analysis::analyzeEvoChamber(double likelihoodToAttack)
{
double score = 1.0;
if (Military::likelihoodToAttack() > 0.7) score -= 0.4;
@ -132,7 +133,7 @@ double Analysis::analyzeGroundArmor()
return 1.0;
}
double Analysis::analyzeHatchery()
double Analysis::analyzeHatchery(double likelihoodToAttack)
{
double score = 0;
@ -145,7 +146,7 @@ double Analysis::analyzeHatchery()
score = 2;
}
return score - Military::likelihoodToAttack();
return score - likelihoodToAttack;
}
double Analysis::analyzeHive()
@ -164,14 +165,14 @@ double Analysis::analyzeHydraDen()
return score;
}
double Analysis::analyzeHydralisk()
double Analysis::analyzeHydralisk(double likelihoodToAttack)
{
if (Broodwar->self()->supplyUsed() > Broodwar->self()->supplyTotal()) return 0;
double score = 0.8;
score -= Util::eggCount(UnitTypes::Zerg_Hydralisk) * 0.1;
//if (Military::likelihoodToAttack() > 0.7) score += 0.3;
if (Military::likelihoodToAttack() < 0.2) score -= 0.4;
if (likelihoodToAttack < 0.2) score -= 0.4;
if (!Macro::enemyIDs.empty())
{
@ -214,15 +215,18 @@ double Analysis::analyzeMutalisk()
{
score -= Util::countUnits(Macro::enemyIDs.front(), UnitTypes::Protoss_Corsair) * 0.05;
score -= Util::countUnits(Macro::enemyIDs.front(), UnitTypes::Terran_Valkyrie) * 0.05;
int staticD = Util::getStaticDCount(Macro::enemyIDs.front(), "air");
score += (0.5 - (staticD * 0.05));
}
return score;
}
double Analysis::analyzeOverlord()
double Analysis::analyzeOverlord(double likelihoodToAttack)
{
double score = 1.5;
if (Military::likelihoodToAttack() > 0.7) score -= 0.1;
if (likelihoodToAttack > 0.7) score -= 0.1;
return score;
}
@ -289,8 +293,14 @@ double Analysis::analyzeZergling()
else
{
score += Util::countUnits(Macro::enemyIDs.front(), UnitTypes::Protoss_Dragoon) * 0.05;
score += Util::countUnits(Macro::enemyIDs.front(), UnitTypes::Terran_Siege_Tank_Siege_Mode) * 0.05;
score += Util::countUnits(Macro::enemyIDs.front(), UnitTypes::Terran_Siege_Tank_Tank_Mode) * 0.05;
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;
}
if (Util::countUnits(Macro::enemyIDs.front(), UnitTypes::Terran_Factory) > 0)
{
score += 0.2;
}
return score;
}

View File

@ -14,16 +14,16 @@ public:
static double analyze(BWAPI::TechType tech);
static double analyze(BWAPI::UnitType unit);
static double analyze(BWAPI::UpgradeType upgrade);
static double analyzeDrone();
static double analyzeEvoChamber();
static double analyzeDrone(double likelihoodToAttack);
static double analyzeEvoChamber(double likelihoodToAttack);
static double analyzeGas();
static double analyzeHatchery();
static double analyzeHatchery(double likelihoodToAttack);
static double analyzeHive();
static double analyzeHydraDen();
static double analyzeHydralisk();
static double analyzeHydralisk(double likelihoodToAttack);
static double analyzeLair();
static double analyzeMutalisk();
static double analyzeOverlord();
static double analyzeOverlord(double likelihoodToAttack);
static double analyzeQueensNest();
static double analyzeSpawningPool();
static double analyzeSpire();

View File

@ -5,6 +5,7 @@ namespace { auto & map = BWEM::Map::Instance(); }
//@TODO save a target build position with each sunken/spore colony
// so that each base gets the right number of each
//@TODO also make sure sunkens don't block off the natural
//@TODO place hatcheries closer to the main ramp and tech buildings farther back
TilePosition BuildingPlacement::getPosition(BWAPI::UnitType unit)
{
TilePosition tp = Macro::players.at(Macro::selfID).bases.front().tilePosition;

View File

@ -54,7 +54,7 @@ void CheckItem::checkGas()
}
if (Broodwar->self()->supplyUsed() >= 120)
{
if (Util::countUnits(Macro::selfID, UnitTypes::Zerg_Extractor) < 3
if (Util::countUnits(Macro::selfID, UnitTypes::Zerg_Extractor) < Macro::players.at(Macro::selfID).bases.size()
&& !Macro::queueHas(UnitTypes::Zerg_Extractor))
{
Macro::queue.push_back(QueueEntry(UnitTypes::Zerg_Extractor, false, 0.0));

View File

@ -142,14 +142,8 @@ void KoraBot::onFrame()
//}
Broodwar->drawTextScreen(200, 10, "likelihood: %f", Military::likelihoodToAttack());
Broodwar->drawTextScreen(200, 30, "stop production: %d", Macro::stopProduction);
for (auto e : Macro::queue)
{
if(e.unit != UnitTypes::Unknown)
Broodwar->drawTextScreen(200, 50 + (count * 20), "%s: %d", e.unit.c_str(), e.inProgress);
else
Broodwar->drawTextScreen(200, 50 + (count * 20), "%s: %d", e.upgrade.c_str(), e.inProgress);
count++;
}
// Util::drawQueue();
//for (auto unit : BWAPI::Broodwar->getNeutralUnits())
//{
//Broodwar->drawTextMap(unit->getPosition(), unit->getType().c_str());

View File

@ -288,6 +288,7 @@ void Macro::onUnitCreate(Unit unit)
}
//@TODO clean this up
//@TODO bot doesn't seem to re-add gas workers after they die
void Macro::onUnitDestroy(Unit unit)
{
if (unit->getPlayer() != Broodwar->neutral())

View File

@ -214,7 +214,7 @@ std::pair<TilePosition, int> Military::getAttackLocation()
returnPair.second = 1000;
}
Broodwar << " first return: " << returnPair.first << std::endl;
//Broodwar << " first return: " << returnPair.first << std::endl;
return returnPair;
}
else

View File

@ -57,6 +57,20 @@ int Util::countUnits(int playerID, BWAPI::UnitType unitType)
return count;
}
// draws the queue at the top center of the screen
void Util::displayQueue()
{
int count = 0;
for (auto e : Macro::queue)
{
if (e.unit != UnitTypes::Unknown)
Broodwar->drawTextScreen(200, 50 + (count * 20), "%s: %d", e.unit.c_str(), e.inProgress);
else
Broodwar->drawTextScreen(200, 50 + (count * 20), "%s: %d", e.upgrade.c_str(), e.inProgress);
count++;
}
}
// number of units of a particular type being produced
int Util::eggCount(BWAPI::UnitType unitType)
{
@ -204,6 +218,28 @@ int Util::getQueueIndex(UnitType ut)
return -1;
}
int Util::getStaticDCount(int playerID, std::string type = "all")
{
if (type == "air")
{
return (countUnits(playerID, UnitTypes::Terran_Missile_Turret)
+ countUnits(playerID, UnitTypes::Terran_Bunker)
+ countUnits(playerID, UnitTypes::Protoss_Photon_Cannon)
+ countUnits(playerID, UnitTypes::Zerg_Spore_Colony));
}
else if (type == "ground")
{
return (countUnits(playerID, UnitTypes::Terran_Bunker)
+ countUnits(playerID, UnitTypes::Protoss_Photon_Cannon)
+ countUnits(playerID, UnitTypes::Zerg_Sunken_Colony));
}
return (countUnits(playerID, UnitTypes::Terran_Bunker)
+ countUnits(playerID, UnitTypes::Terran_Missile_Turret)
+ countUnits(playerID, UnitTypes::Protoss_Photon_Cannon)
+ countUnits(playerID, UnitTypes::Zerg_Sunken_Colony)
+ countUnits(playerID, UnitTypes::Zerg_Spore_Colony));
}
// return another starting location besides the one provided
// for the purpose of pathing / defense placement
//

View File

@ -17,6 +17,7 @@ public:
static int buildWorkerIndex();
static bool completedBuilding(BWAPI::UnitType unitType);
static int countUnits(int playerID, BWAPI::UnitType unitType);
static void displayQueue();
static int eggCount(BWAPI::UnitType unitType);
static int findUpgradeBuilding(BWAPI::UpgradeType upgradeType);
static int getBaseIndex(Unit unit);
@ -26,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 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);
static double getWalkDistance(TilePosition tp1, TilePosition tp2);