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

View file

@ -14,16 +14,16 @@ public:
static double analyze(BWAPI::TechType tech); static double analyze(BWAPI::TechType tech);
static double analyze(BWAPI::UnitType unit); static double analyze(BWAPI::UnitType unit);
static double analyze(BWAPI::UpgradeType upgrade); static double analyze(BWAPI::UpgradeType upgrade);
static double analyzeDrone(); static double analyzeDrone(double likelihoodToAttack);
static double analyzeEvoChamber(); static double analyzeEvoChamber(double likelihoodToAttack);
static double analyzeGas(); static double analyzeGas();
static double analyzeHatchery(); static double analyzeHatchery(double likelihoodToAttack);
static double analyzeHive(); static double analyzeHive();
static double analyzeHydraDen(); static double analyzeHydraDen();
static double analyzeHydralisk(); static double analyzeHydralisk(double likelihoodToAttack);
static double analyzeLair(); static double analyzeLair();
static double analyzeMutalisk(); static double analyzeMutalisk();
static double analyzeOverlord(); static double analyzeOverlord(double likelihoodToAttack);
static double analyzeQueensNest(); static double analyzeQueensNest();
static double analyzeSpawningPool(); static double analyzeSpawningPool();
static double analyzeSpire(); 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 //@TODO save a target build position with each sunken/spore colony
// so that each base gets the right number of each // so that each base gets the right number of each
//@TODO also make sure sunkens don't block off the natural //@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 BuildingPlacement::getPosition(BWAPI::UnitType unit)
{ {
TilePosition tp = Macro::players.at(Macro::selfID).bases.front().tilePosition; 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 (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::queueHas(UnitTypes::Zerg_Extractor))
{ {
Macro::queue.push_back(QueueEntry(UnitTypes::Zerg_Extractor, false, 0.0)); 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, 10, "likelihood: %f", Military::likelihoodToAttack());
Broodwar->drawTextScreen(200, 30, "stop production: %d", Macro::stopProduction); Broodwar->drawTextScreen(200, 30, "stop production: %d", Macro::stopProduction);
for (auto e : Macro::queue) // Util::drawQueue();
{
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++;
}
//for (auto unit : BWAPI::Broodwar->getNeutralUnits()) //for (auto unit : BWAPI::Broodwar->getNeutralUnits())
//{ //{
//Broodwar->drawTextMap(unit->getPosition(), unit->getType().c_str()); //Broodwar->drawTextMap(unit->getPosition(), unit->getType().c_str());

View file

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

View file

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

View file

@ -57,6 +57,20 @@ int Util::countUnits(int playerID, BWAPI::UnitType unitType)
return count; 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 // number of units of a particular type being produced
int Util::eggCount(BWAPI::UnitType unitType) int Util::eggCount(BWAPI::UnitType unitType)
{ {
@ -204,6 +218,28 @@ int Util::getQueueIndex(UnitType ut)
return -1; 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 // return another starting location besides the one provided
// for the purpose of pathing / defense placement // for the purpose of pathing / defense placement
// //

View file

@ -17,6 +17,7 @@ public:
static int buildWorkerIndex(); static int buildWorkerIndex();
static bool completedBuilding(BWAPI::UnitType unitType); static bool completedBuilding(BWAPI::UnitType unitType);
static int countUnits(int playerID, BWAPI::UnitType unitType); static int countUnits(int playerID, BWAPI::UnitType unitType);
static void displayQueue();
static int eggCount(BWAPI::UnitType unitType); static int eggCount(BWAPI::UnitType unitType);
static int findUpgradeBuilding(BWAPI::UpgradeType upgradeType); static int findUpgradeBuilding(BWAPI::UpgradeType upgradeType);
static int getBaseIndex(Unit unit); 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 std::pair<const BWEM::Area*, bool> getNeighborArea(const BWEM::Area* a1, const BWEM::Area* a2);
static CBase getNextExpand(int playerID); static CBase getNextExpand(int playerID);
static int getQueueIndex(UnitType ut); 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 std::pair<const BWEM::Area*, bool> getTargetArea(const BWEM::Area* startingArea, bool startLocation);
static int getUnitIndex(Unit unit); static int getUnitIndex(Unit unit);
static double getWalkDistance(TilePosition tp1, TilePosition tp2); static double getWalkDistance(TilePosition tp1, TilePosition tp2);