BWAPI
|
#include <Strategizer.h>
Public Member Functions | |
void | update () |
void | draw () |
void | onMatchStart () |
void | onMatchEnd (bool isWinner) |
void | onEvent (GameEvent &e) |
Static Public Member Functions | |
static Strategizer & | instance () |
Public Attributes | |
BuildManager | buildManager |
CombatManager | combatManager |
GasManager | gasManager |
ProductionManager | productionManager |
ResourceManager | resourceManager |
ScoutManager | scoutManager |
SupplyManager | supplyManager |
Private Member Functions | |
Strategizer () | |
Strategizer (const Strategizer &other) | |
void | operator= (const Strategizer &other) |
void | updateUnitAgentMap () |
void | updateAgentManagerMap () |
void | redistributeAgents () |
void | updateManagers () |
bool | remap (BWAPI::UnitType type, Manager &src, Manager &dst) |
bool | checkForfeit () |
Private Attributes | |
UnitAgentMap | unitAgentMap |
AgentManagerMap | agentManagerMap |
Definition at line 15 of file Strategizer.h.
Strategizer::Strategizer | ( | ) | [inline, private] |
Definition at line 55 of file Strategizer.h.
{ }
Strategizer::Strategizer | ( | const Strategizer & | other | ) | [private] |
bool Strategizer::checkForfeit | ( | ) | [private] |
Definition at line 334 of file Strategizer.cpp.
{ // TODO: will eventually be using productionMgr inside buildMgr? // if so, that change will mess this up AgentSet pmCC(productionManager.getAgentsOfType(UnitTypes::Terran_Command_Center)); return pmCC.size() == 0; }
void Strategizer::draw | ( | ) |
Definition at line 307 of file Strategizer.cpp.
{ buildManager.draw(); combatManager.draw(); gasManager.draw(); resourceManager.draw(); supplyManager.draw(); }
static Strategizer& Strategizer::instance | ( | ) | [inline, static] |
Definition at line 36 of file Strategizer.h.
Referenced by BasicAIModule::onEnd(), BasicAIModule::onFrame(), BasicAIModule::onStart(), and SupplyManager::update().
{ static Strategizer s; return s; }
void Strategizer::onEvent | ( | GameEvent & | e | ) |
Definition at line 100 of file Strategizer.cpp.
{ }
void Strategizer::onMatchEnd | ( | bool | isWinner | ) |
Definition at line 109 of file Strategizer.cpp.
Referenced by BasicAIModule::onEnd().
{ // Cleanup agents // Note: this is the safe way to do this // erasing by iterator invalidates the iterator, // so if we just use map.erase(it), the loop gets screwed up, // postfix increment inside the loop keeps the // iterator valid as it traverses the map // Source: Effective STL (Scott Meyers - 2001) AgentManagerMapIter it = agentManagerMap.begin(); AgentManagerMapIter end = agentManagerMap.end(); for(; it != end;) { Agent* agent = it->first; agentManagerMap.erase(it++); delete agent; } }
void Strategizer::onMatchStart | ( | ) |
buildManager.build(UnitTypes::Terran_Battlecruiser);
Definition at line 57 of file Strategizer.cpp.
Referenced by BasicAIModule::onStart().
{ buildManager.onMatchStart(); combatManager.onMatchStart(); gasManager.onMatchStart(); productionManager.onMatchStart(); resourceManager.onMatchStart(); scoutManager.onMatchStart(); supplyManager.onMatchStart(); // Barracks do not ever leave idle state (for now), so 1 per unit type // Marines buildManager.build(UnitTypes::Terran_Barracks); buildManager.build(UnitTypes::Terran_Marine); // Marines buildManager.build(UnitTypes::Terran_Barracks); buildManager.build(UnitTypes::Terran_Marine); // Firebat buildManager.build(UnitTypes::Terran_Barracks); buildManager.build(UnitTypes::Terran_Firebat); // Expand buildManager.build(UnitTypes::Terran_Command_Center); // Vultures buildManager.build(UnitTypes::Terran_Factory); buildManager.build(UnitTypes::Terran_Vulture); buildManager.build(UnitTypes::Terran_Factory); buildManager.build(UnitTypes::Terran_Vulture); buildManager.build(UnitTypes::Terran_Battlecruiser); }
void Strategizer::operator= | ( | const Strategizer & | other | ) | [private] |
void Strategizer::redistributeAgents | ( | ) | [private] |
Definition at line 268 of file Strategizer.cpp.
References Manager::addAgent(), and Agent::setParentManager().
{ // Revoke all agents from managers buildManager.removeAllAgents(); combatManager.removeAllAgents(); gasManager.removeAllAgents(); productionManager.removeAllAgents(); // remove once build mgr is more complete resourceManager.removeAllAgents(); scoutManager.removeAllAgents(); supplyManager.removeAllAgents(); // Redistribute agents AgentManagerMapIter it = agentManagerMap.begin(); AgentManagerMapIter end = agentManagerMap.end(); for(; it != end; ++it) { pair<Agent*, Manager*> agentManager = *it; Agent *a = agentManager.first; Manager *m = agentManager.second; // TODO : Change this to assert if (a != NULL) { m->addAgent(*a); a->setParentManager(m); } } }
bool Strategizer::remap | ( | BWAPI::UnitType | type, |
Manager & | src, | ||
Manager & | dst | ||
) | [private] |
Definition at line 316 of file Strategizer.cpp.
References Agent::getUnit().
{ UnitAgentMapIter it = unitAgentMap.begin(); UnitAgentMapIter end = unitAgentMap.end(); for(; it != end; ++it) { pair<Unit*, Agent*> unitAgent = *it; Agent *a = unitAgent.second; UnitType ut = a->getUnit().getType(); if (ut == type && agentManagerMap[a] == &src) { agentManagerMap[a] = &dst; return false; } } return true; }
void Strategizer::update | ( | ) |
Definition at line 23 of file Strategizer.cpp.
References BWAPI::Broodwar, TacticalBuildingPlacer::instance(), and TacticalBuildingPlacer::update().
Referenced by BasicAIModule::onFrame().
{ // Draw "GUI" Broodwar->drawTextScreen(300, 0, "\x17 APM=%d", Broodwar->getAPM()); Broodwar->drawTextScreen(300,10, "\x17 FPS=%d", Broodwar->getFPS()); TacticalBuildingPlacer::instance().update(); // draw reserved map draw(); // draw managers if (Broodwar->getFrameCount() % 10 == 0) { // Find new units, remove inactive ones updateUnitAgentMap(); // Remap Agents to Managers (bid war) updateAgentManagerMap(); // Give Agents to updated Managers redistributeAgents(); // Let Managers manager updateManagers(); if( checkForfeit() ) { Broodwar->sendText("Surrendering match..."); Broodwar->leaveGame(); } } }
void Strategizer::updateAgentManagerMap | ( | ) | [private] |
Definition at line 187 of file Strategizer.cpp.
References BWAPI::Broodwar, and Agent::getUnit().
{ // Normally, we would shuffle Units around by bid here.. for (UnitAgentMapIter agent = unitAgentMap.begin(); agent != unitAgentMap.end(); agent++) { Agent *a = (*agent).second; UnitType ut = a->getUnit().getType(); // if Agent hasn't been assigned a manager if (agentManagerMap[a] == NULL) { // Resources: // SCV -> ResourceManager if (a->getUnit().getType().isWorker()) agentManagerMap[a] = &buildManager; // Refinery -> Gas Manager else if (ut.isRefinery()) agentManagerMap[a] = &gasManager; // Command Center -> Production Manager // TODO: this is the wrong ProductionManager // we want to assign it to the one in BuildManager // // Left here until we find a way to generate SCVs in BM. // -mike else if (ut.isResourceDepot()) agentManagerMap[a] = &productionManager; // Army: // Barracks -> BuildManager else if (ut == UnitTypes::Terran_Barracks) agentManagerMap[a] = &buildManager; else if (ut.isBuilding()) agentManagerMap[a] = &buildManager; // Combat: // Marines -> CombatManager else if (ut == UnitTypes::Terran_Marine) agentManagerMap[a] = &combatManager; // Firebat -> CombatManager else if (ut == UnitTypes::Terran_Firebat) agentManagerMap[a] = &combatManager; // Medic -> CombatManager else if (ut == UnitTypes::Terran_Medic) agentManagerMap[a] = &combatManager; else agentManagerMap[a] = &combatManager; } } // If we are running low on supply, give an SCV to the SupplyManager /* const int remainingSupply = Broodwar->self()->supplyTotal() - Broodwar->self()->supplyUsed(); if (remainingSupply < 6 && supplyManager.numAgents(UnitTypes::Terran_SCV) < 1) { remap(UnitTypes::Terran_SCV, resourceManager, supplyManager); } */ // If we have enough SCVs, let's try creating a Barracks/Army // if (Broodwar->self()->supplyUsed() >= 20 && // combatManager.numAgents(UnitTypes::Terran_SCV) < 1 ) // { // remap(UnitTypes::Terran_SCV, resourceManager, combatManager); // } // take one of the resourceManager SCV's and give it to the gas manager if (Broodwar->self()->supplyUsed() >= 30 && gasManager.numAgents(UnitTypes::Terran_SCV) < 1) { remap(UnitTypes::Terran_SCV, buildManager, gasManager); } }
void Strategizer::updateManagers | ( | ) | [private] |
Definition at line 296 of file Strategizer.cpp.
{ buildManager.update(); combatManager.update(); gasManager.update(); productionManager.update(); // remove once build mgr is more complete resourceManager.update(); scoutManager.update(); supplyManager.update(); }
void Strategizer::updateUnitAgentMap | ( | ) | [private] |
Definition at line 134 of file Strategizer.cpp.
References BWAPI::Broodwar.
{ // Create agents for newly found, friendly units. Delete dead ones UnitSet units = Broodwar->self()->getUnits(); for (UnitSetIter unit = units.begin(); unit != units.end(); ++unit) { Unit *u = *unit; // Only construct active units if (!u->isCompleted()) // TODO: Determine a more robust conditional { continue; } // New agent if (unitAgentMap[u] == NULL) { UnitType ut = u->getType(); Agent *a = NULL; if (ut.isWorker()) a = new SCVAgent(*u); else if (ut.isResourceDepot()) a = new CommandCenterAgent(*u); else if (ut == UnitTypes::Terran_Refinery) a = new RefineryAgent(*u); else if (ut == UnitTypes::Terran_Barracks) a = new BarracksAgent(*u); else if (ut == UnitTypes::Terran_Marine) a = new MarineAgent(*u); else if (ut == UnitTypes::Terran_Firebat) a = new FirebatAgent(*u); else if (ut == UnitTypes::Terran_Medic) a = new MedicAgent(*u); else if (ut.isBuilding()) a = new StructureAgent(*u); else a = new ActorAgent(*u); if (a != NULL) unitAgentMap[u] = a; } } // TODO: Cleanup inactive agents }
AgentManagerMap Strategizer::agentManagerMap [private] |
Definition at line 28 of file Strategizer.h.
Definition at line 18 of file Strategizer.h.
Referenced by SupplyManager::update().
Definition at line 19 of file Strategizer.h.
Definition at line 20 of file Strategizer.h.
Definition at line 21 of file Strategizer.h.
Definition at line 22 of file Strategizer.h.
Definition at line 23 of file Strategizer.h.
Definition at line 24 of file Strategizer.h.
UnitAgentMap Strategizer::unitAgentMap [private] |
Definition at line 27 of file Strategizer.h.