diff --git a/Source/Analysis.cpp b/Source/Analysis.cpp index 2ebe911..fd46859 100644 --- a/Source/Analysis.cpp +++ b/Source/Analysis.cpp @@ -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; } diff --git a/Source/Analysis.h b/Source/Analysis.h index c56b15b..429497c 100644 --- a/Source/Analysis.h +++ b/Source/Analysis.h @@ -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(); diff --git a/Source/BuildingPlacement.cpp b/Source/BuildingPlacement.cpp index 9fb45f3..369a612 100644 --- a/Source/BuildingPlacement.cpp +++ b/Source/BuildingPlacement.cpp @@ -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; diff --git a/Source/CheckItem.cpp b/Source/CheckItem.cpp index efbf3b7..83bc3d5 100644 --- a/Source/CheckItem.cpp +++ b/Source/CheckItem.cpp @@ -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)); diff --git a/Source/Korabot.cpp b/Source/Korabot.cpp index 2389052..780d44a 100644 --- a/Source/Korabot.cpp +++ b/Source/Korabot.cpp @@ -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()); diff --git a/Source/Macro.cpp b/Source/Macro.cpp index aedef3a..1a28938 100644 --- a/Source/Macro.cpp +++ b/Source/Macro.cpp @@ -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()) diff --git a/Source/Military.cpp b/Source/Military.cpp index b7747a9..26ce680 100644 --- a/Source/Military.cpp +++ b/Source/Military.cpp @@ -214,7 +214,7 @@ std::pair Military::getAttackLocation() returnPair.second = 1000; } - Broodwar << " first return: " << returnPair.first << std::endl; + //Broodwar << " first return: " << returnPair.first << std::endl; return returnPair; } else diff --git a/Source/Util.cpp b/Source/Util.cpp index 80ce1c7..664d0f0 100644 --- a/Source/Util.cpp +++ b/Source/Util.cpp @@ -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 // diff --git a/Source/Util.h b/Source/Util.h index fd6a421..c53dcd4 100644 --- a/Source/Util.h +++ b/Source/Util.h @@ -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 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 getTargetArea(const BWEM::Area* startingArea, bool startLocation); static int getUnitIndex(Unit unit); static double getWalkDistance(TilePosition tp1, TilePosition tp2);