Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixes & couple features #77

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions bin/BotConfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

"SC2API" :
{
"BotRace" : "Terran",
"BotRace" : "Protoss",
"EnemyDifficulty" : 2,
"EnemyRace" : "Random",
"MapFile" : "InterloperLE.SC2Map",
Expand All @@ -26,7 +26,8 @@
"Micro" :
{
"KiteWithRangedUnits" : false,
"ScoutHarassEnemy" : true
"ScoutHarassEnemy" : true,
"OverlordScout" : true
},

"Macro" :
Expand Down Expand Up @@ -113,28 +114,28 @@
"Protoss_ZealotRush" :
{
"Race" : "Protoss",
"OpeningBuildOrder" : ["Probe", "Probe", "Pylon", "Probe", "Probe", "Gateway", "Pylon", "Probe", "Gateway", "Probe", "Gateway", "Pylon", "Probe", "Zealot", "Zealot", "Pylon", "Zealot", "Zealot", "Pylon", "Zealot", "Zealot", "Zealot", "Zealot", "Zealot", "Zealot", "Zealot", "Zealot", "Zealot", "Zealot"],
"OpeningBuildOrder" : ["2 Probe", "Pylon", "2 Probe", "Gateway", "Pylon", "Probe", "Gateway", "Probe", "Gateway", "Pylon", "Probe", "2 Zealot", "Pylon", "2 Zealot", "Pylon", "10 Zealot"],
"ScoutCondition" : [ ["Self", "Pylon"], ">", [ 0 ] ],
"AttackCondition" : [ ["Self", "Zealot"], ">=", [ 8 ] ]
},
"Terran_MarineRush" :
{
"Race" : "Terran",
"OpeningBuildOrder" : ["SCV", "SCV", "SupplyDepot", "SCV", "SCV", "Barracks", "Barracks", "Barracks", "Barracks", "SupplyDepot", "SupplyDepot", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine", "Marine"],
"OpeningBuildOrder" : ["2 SCV", "SupplyDepot", "2 SCV", "4 Barracks", "2 SupplyDepot", "20 Marine"],
"ScoutCondition" : [ ["Self", "SupplyDepot"], ">", [ 0 ] ],
"AttackCondition" : [ ["Self", "Marine"], ">=", [ 8 ] ]
},
"Zerg_ZerglingRush" :
{
"Race" : "Zerg",
"OpeningBuildOrder" : ["SpawningPool", "Drone", "Overlord", "Drone", "Zergling", "Zergling", "Zergling", "Zergling", "Zergling", "Zergling", "Zergling", "Zergling"],
"OpeningBuildOrder" : ["SpawningPool", "Drone", "Overlord", "Drone", "8 Zergling"],
"ScoutCondition" : [ ["GameFrame"], ">=", [ 100 ] ],
"AttackCondition" : [ ["Self", "Zergling"], ">", [ 0 ] ]
},
"Zerg_2HatchRoach" :
{
"Race" : "Zerg",
"OpeningBuildOrder" : ["SpawningPool", "Drone", "Overlord", "Drone", "Drone", "Extractor", "Drone", "Drone", "Hatchery", "Drone", "Overlord", "Drone", "RoachWarren", "Drone", "Drone", "Drone", "Drone", "Roach", "Overlord", "Roach", "Roach", "Roach", "Roach", "Overlord", "Roach", "Roach", "Roach", "Roach", "Roach", "Roach", "Roach"],
"OpeningBuildOrder" : ["SpawningPool", "Drone", "Overlord", "2 Drone", "Extractor", "2 Drone", "Hatchery", "Drone", "Overlord", "Drone", "RoachWarren", "4 Drone", "Roach", "Overlord", "4 Roach", "Overlord", "7 Roach"],
"ScoutCondition" : [ ["self", "SpawningPool"], ">=", [ 1 ] ],
"AttackCondition" : [ [["Self", "Roach"], ">=", [ 12 ]], "AND", [["Self", "Overlord"], ">=", [ 1 ]] ]
}
Expand Down
4 changes: 3 additions & 1 deletion src/BaseLocationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void BaseLocationManager::onStart()

// a BaseLocation will be anything where there are minerals to mine
// so we will first look over all minerals and cluster them based on some distance

// TODO: fix for minerals over ledges being included in base
const CCPositionType clusterDistance = Util::TileToPosition(12);

// stores each cluster of resources based on some ground distance
Expand Down Expand Up @@ -44,7 +46,7 @@ void BaseLocationManager::onStart()
if (dist < clusterDistance)
{
// now do a more expensive ground distance check
float groundDist = dist; //m_bot.Map().getGroundDistance(mineral.pos, Util::CalcCenter(cluster));
float groundDist = m_bot.Map().getGroundDistance(mineral.getPosition(), Util::CalcCenter(cluster)); //dist;
if (groundDist >= 0 && groundDist < clusterDistance)
{
cluster.push_back(mineral);
Expand Down
2 changes: 2 additions & 0 deletions src/BotConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ BotConfig::BotConfig()

KiteWithRangedUnits = true;
ScoutHarassEnemy = true;
OverlordScout = true;

ColorLineTarget = CCColor(255, 255, 255);
ColorLineMineral = CCColor(0, 128, 128);
Expand Down Expand Up @@ -94,6 +95,7 @@ void BotConfig::readConfigFile()
const json & micro = j["Micro"];
JSONTools::ReadBool("KiteWithRangedUnits", micro, KiteWithRangedUnits);
JSONTools::ReadBool("ScoutHarassEnemy", micro, ScoutHarassEnemy);
JSONTools::ReadBool("OverlordScout", micro, OverlordScout);
}

// Parse the BWAPI Options
Expand Down
1 change: 1 addition & 0 deletions src/BotConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BotConfig

bool KiteWithRangedUnits;
bool ScoutHarassEnemy;
bool OverlordScout;

int WorkersPerRefinery;
int BuildingSpacing;
Expand Down
9 changes: 4 additions & 5 deletions src/BuildingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ bool BuildingManager::isBeingBuilt(UnitType type)
return true;
}
}

return false;
}

Expand Down Expand Up @@ -167,6 +166,7 @@ void BuildingManager::constructAssignedBuildings()
{
// TODO: in here is where we would check to see if the builder died on the way
// or if things are taking too long, or the build location is no longer valid

}
else
{
Expand All @@ -179,14 +179,15 @@ void BuildingManager::constructAssignedBuildings()
{
if (unit.getType().isGeyser() && Util::Dist(Util::GetPosition(b.finalPosition), unit.getPosition()) < 3)
{
geyser = unit;
break;
geyser = unit;
break;
}
}

if (geyser.isValid())
{
b.builderUnit.buildTarget(b.type, geyser);

}
else
{
Expand Down Expand Up @@ -428,14 +429,12 @@ CCTilePosition BuildingManager::getBuildingLocation(const Building & b)
}
}


// get a position within our region
// TODO: put back in special pylon / cannon spacing
return m_buildingPlacer.getBuildLocationNear(b, m_bot.Config().BuildingSpacing);
}

void BuildingManager::removeBuildings(const std::vector<Building> & toRemove)

{
for (auto & b : toRemove)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using json = nlohmann::json;
typedef sc2::Point2DI CCTilePosition;
typedef sc2::Color CCColor;
typedef sc2::UpgradeID CCUpgrade;
typedef sc2::AbilityID CCAbility;
typedef sc2::Tag CCUnitID;
typedef sc2::Race CCRace;
typedef float CCHealth;
Expand All @@ -31,6 +32,7 @@ using json = nlohmann::json;
typedef BWAPI::Color CCColor;
typedef BWAPI::Race CCRace;
typedef BWAPI::UpgradeType CCUpgrade;
typedef int CCAbility;
typedef int CCUnitID;
typedef int CCHealth;
typedef int CCPositionType;
Expand Down
16 changes: 16 additions & 0 deletions src/GameCommander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ void GameCommander::setScoutUnits()
{
// grab the closest worker to the supply provider to send to scout
Unit workerScout = m_bot.Workers().getClosestMineralWorkerTo(m_bot.GetStartLocation());

// if zerg, use overlord??
if (m_bot.Config().OverlordScout)
{
if (m_bot.GetPlayerRace(Players::Self) == CCRace::Zerg)
{
for (auto & unit : m_bot.UnitInfo().getUnits(Players::Self))
{
if (unit.getType().isOverlord())
{
workerScout = unit;
break;
}
}
}
}

// if we find a worker (which we should) add it to the scout units
if (workerScout.isValid())
Expand Down
2 changes: 1 addition & 1 deletion src/MetaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ MetaType::MetaType(const std::string & name, CCBot & bot)
return;
}

for (const sc2::UpgradeData & data : bot.Observation()->GetUpgradeData())
for (const sc2::UpgradeData & data : bot.Observation()->GetUpgradeData(true))
{
if (name == data.name)
{
Expand Down
66 changes: 54 additions & 12 deletions src/ProductionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ void ProductionManager::setBuildOrder(const BuildOrder & buildOrder)
}
}


void ProductionManager::onStart()
{
m_buildingManager.onStart();
Expand Down Expand Up @@ -132,39 +131,83 @@ void ProductionManager::fixBuildOrderDeadlock()

if (!hasProducer)
{
m_queue.queueAsHighestPriority(MetaType(m_bot.Data(currentItem.type).whatBuilds[0], m_bot), true);
fixBuildOrderDeadlock();
// ignores larva unit
std::string::size_type pos = m_bot.Data(currentItem.type).whatBuilds[0].getName().find("LARVA");
if (pos != std::string::npos)
{

}
else
{
m_queue.queueAsHighestPriority(MetaType(m_bot.Data(currentItem.type).whatBuilds[0], m_bot), true);
fixBuildOrderDeadlock();
}
}

// build a refinery if we don't have one and the thing costs gas
auto refinery = Util::GetRefinery(m_bot.GetPlayerRace(Players::Self), m_bot);
if (m_bot.Data(currentItem.type).gasCost > 0 && m_bot.UnitInfo().getUnitTypeCount(Players::Self, refinery, false) == 0)
if (m_bot.Data(currentItem.type).gasCost > 0 && (m_bot.UnitInfo().getUnitTypeCount(Players::Self, refinery, false) == 0 && !m_buildingManager.isBeingBuilt(refinery)))
{
m_queue.queueAsHighestPriority(MetaType(refinery, m_bot), true);
}

// build supply if we need some
auto supplyProvider = Util::GetSupplyProvider(m_bot.GetPlayerRace(Players::Self), m_bot);
if (m_bot.Data(currentItem.type).supplyCost > (m_bot.GetMaxSupply() - m_bot.GetCurrentSupply()) && !m_buildingManager.isBeingBuilt(supplyProvider))
if (m_bot.Data(currentItem.type).supplyCost > (m_bot.GetMaxSupply() - m_bot.GetCurrentSupply()) && !supplyInProgress(supplyProvider))

//!m_buildingManager.isBeingBuilt(supplyProvider))
{
m_queue.queueAsHighestPriority(MetaType(supplyProvider, m_bot), true);
m_queue.queueAsHighestPriority(MetaType(supplyProvider, m_bot), true);
}
}

bool ProductionManager::supplyInProgress(UnitType type)
{
if (m_buildingManager.isBeingBuilt(type))
{
return true;
}

// zerg egg check for overlords in progress
for (auto & unit : m_bot.UnitInfo().getUnits(Players::Self))
{
if (unit.getType().isEgg())
{

// TODO: work with sc1
#ifdef SC2API
if (unit.getUnitPtr()->orders.front().ability_id == sc2::ABILITY_ID::TRAIN_OVERLORD)
{
return true;
}
#endif
}
}
return false;
}

Unit ProductionManager::getProducer(const MetaType & type, CCPosition closestTo)
{
// get all the types of units that cna build this type
// get all the types of units that can build this type
auto & producerTypes = m_bot.Data(type).whatBuilds;

// make a set of all candidate producers
std::vector<Unit> candidateProducers;
for (auto unit : m_bot.UnitInfo().getUnits(Players::Self))
for (auto & unit : m_bot.UnitInfo().getUnits(Players::Self))
{
// reasons a unit can not train the desired type

// this unit can not build the desired type
if (std::find(producerTypes.begin(), producerTypes.end(), unit.getType()) == producerTypes.end()) { continue; }

// if the unit is not completed it cannot build anything
if (!unit.isCompleted()) { continue; }

// if it's a building that's currently training something, it can't build
if (m_bot.Data(unit).isBuilding && unit.isTraining()) { continue; }
if (unit.isFlying()) { continue; }

// flying buildings cannot build anything
if (m_bot.Data(unit).isBuilding && unit.isFlying()) { continue; }

// TODO: if unit is not powered continue
// TODO: if the type is an addon, some special cases
Expand Down Expand Up @@ -232,9 +275,8 @@ void ProductionManager::create(const Unit & producer, BuildOrderItem & item)
producer.train(item.type.getUnitType());
}
else if (item.type.isUpgrade())
{
// TODO: UPGRADES
//Micro::SmartAbility(producer, m_bot.Data(item.type.getUpgradeID()).buildAbility, m_bot);
{
producer.research(item.type.getUpgrade());
}
}

Expand Down
1 change: 1 addition & 0 deletions src/ProductionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ class ProductionManager
void drawProductionInformation();

Unit getProducer(const MetaType & type, CCPosition closestTo = CCPosition(0, 0));
bool supplyInProgress(UnitType type);
};
27 changes: 27 additions & 0 deletions src/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,33 @@ void Unit::build(const UnitType & buildingType, CCTilePosition pos) const
#endif
}



// these 2 functions are very similar, except being used for different ideas - maybe combine them with a function name that makes sense for both
void Unit::research(const CCUpgrade & ability) const
{
BOT_ASSERT(isValid(), "Unit is not valid");
#ifdef SC2API
m_bot->Actions()->UnitCommand(m_unit, m_bot->Data(ability).buildAbility);
#else
// TODO: have not tested this
// m_unit->upgrade(ability);
#endif
}

//TODO: update to not use sc2 api stuff - should work with both games
void Unit::useAbility(const CCAbility & ability, const CCPosition & targetPosition) const
{
BOT_ASSERT(isValid(), "Unit is not valid");
#ifdef SC2API
m_bot->Actions()->UnitCommand(m_unit, ability, targetPosition);
#else
// TODO
#endif
}



void Unit::buildTarget(const UnitType & buildingType, const Unit & target) const
{
BOT_ASSERT(isValid(), "Unit is not valid");
Expand Down
4 changes: 4 additions & 0 deletions src/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ class Unit
void buildTarget (const UnitType & buildingType, const Unit & target) const;
void train (const UnitType & buildingType) const;
void morph (const UnitType & type) const;

void research(const CCUpgrade & ability) const;
void useAbility(const CCAbility & ability, const CCPosition & targetPosition) const;

};