本文整理汇总了C++中bwta::BaseLocation类的典型用法代码示例。如果您正苦于以下问题:C++ BaseLocation类的具体用法?C++ BaseLocation怎么用?C++ BaseLocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseLocation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: drawScoutInformation
void ScoutManager::drawScoutInformation(int x, int y)
{
if (!Config::Debug::DrawScoutInfo)
{
return;
}
BWAPI::Broodwar->drawTextScreen(x, y - 10, "Enemy base timer == %d", patrol_counter);
BWAPI::Broodwar->drawTextScreen(x, y, "ScoutInfo: %s", _scoutStatus.c_str());
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
double distance = 0.0;
if (_workerScout && _workerScout->exists() && enemyBaseLocation)
{
BWAPI::Position tmp = BWAPI::Position(enemyBaseLocation->getTilePosition());
int x1 = _workerScout->getPosition().x;
int y1 = _workerScout->getPosition().y;
int x2 = tmp.x;
int y2 = tmp.y;
distance = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) + 0.0);
}
BWAPI::Broodwar->drawTextScreen(x, y+10, "Distance to enemy base: %.2lf", distance);
for (size_t i(0); i < _enemyRegionVertices.size(); ++i)
{
BWAPI::Broodwar->drawCircleMap(_enemyRegionVertices[i], 4, BWAPI::Colors::Green, false);
BWAPI::Broodwar->drawTextMap(_enemyRegionVertices[i], "%d", i);
}
}
开发者ID:pineal,项目名称:SC_AI_Flash,代码行数:32,代码来源:ScoutManager.cpp
示例2: getNextExpansionLocation
BWAPI::TilePosition getNextExpansionLocation(TilePosition currentExpo)
{
//remove the current expo from the list
//loop through expos and find the nearest one
std::set<BWTA::BaseLocation*> bases;
for (auto &u : allBases)
{
//make sure we delete the current expansion
if (u->getTilePosition() == currentExpo)
{
allBases.erase(u);
}
}
BWTA::BaseLocation *ret = *allBases.begin();
int minDistance = currentExpo.getApproxDistance(ret->getTilePosition());
//make sure we dont accidently find current expansion
for (auto &u : allBases)
{
int tempDistance = currentExpo.getApproxDistance(u->getTilePosition());
if (tempDistance < minDistance && tempDistance > 10)
{
//found a closer base
minDistance = tempDistance;
ret = u;
}
}
return ret->getTilePosition();
}
开发者ID:npham014,项目名称:SampleStarcraftAI,代码行数:31,代码来源:Util.cpp
示例3: getMainAttackLocation
BWAPI::Position CombatCommander::getMainAttackLocation()
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
// First choice: Attack an enemy region if we can see units inside it
if (enemyBaseLocation)
{
BWAPI::Position enemyBasePosition = enemyBaseLocation->getPosition();
// get all known enemy units in the area
BWAPI::Unitset enemyUnitsInArea;
MapGrid::Instance().GetUnits(enemyUnitsInArea, enemyBasePosition, 800, false, true);
bool onlyOverlords = true;
for (auto & unit : enemyUnitsInArea)
{
if (unit->getType() != BWAPI::UnitTypes::Zerg_Overlord)
{
onlyOverlords = false;
}
}
if (!BWAPI::Broodwar->isExplored(BWAPI::TilePosition(enemyBasePosition)) || !enemyUnitsInArea.empty())
{
if (!onlyOverlords)
{
return enemyBaseLocation->getPosition();
}
}
}
// Second choice: Attack known enemy buildings
for (const auto & kv : InformationManager::Instance().getUnitInfo(BWAPI::Broodwar->enemy()))
{
const UnitInfo & ui = kv.second;
if (ui.type.isBuilding() && ui.lastPosition != BWAPI::Positions::None)
{
return ui.lastPosition;
}
}
// Third choice: Attack visible enemy units that aren't overlords
for (auto & unit : BWAPI::Broodwar->enemy()->getUnits())
{
if (unit->getType() == BWAPI::UnitTypes::Zerg_Overlord)
{
continue;
}
if (UnitUtil::IsValidUnit(unit) && unit->isVisible())
{
return unit->getPosition();
}
}
// Fourth choice: We can't see anything so explore the map attacking along the way
return MapGrid::Instance().getLeastExplored();
}
开发者ID:Cdingram,项目名称:GGEZ-Bot,代码行数:59,代码来源:CombatCommander.cpp
示例4: getBuildingLocation
BWAPI::TilePosition BuildingManager::getBuildingLocation(const Building & b)
{
int numPylons = BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Protoss_Pylon);
if (b.isGasSteal)
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
UAB_ASSERT(enemyBaseLocation,"Should have enemy base location before attempting gas steal");
UAB_ASSERT(enemyBaseLocation->getGeysers().size() > 0,"Should have spotted an enemy geyser");
for (auto & unit : enemyBaseLocation->getGeysers())
{
BWAPI::TilePosition tp(unit->getInitialTilePosition());
return tp;
}
}
if (b.type.requiresPsi() && numPylons == 0)
{
return BWAPI::TilePositions::None;
}
//if building a bunker for strategy "Terran_Custom", return one location near an attacked unit
if ((b.type == BWAPI::UnitTypes::Terran_Bunker) && (Config::Strategy::StrategyName == "Terran_Custom"))
{
for (auto & unit : BWAPI::Broodwar->self()->getUnits())
{
if (unit->isUnderAttack())
{
return BuildingPlacer::Instance().getBuildLocationNear(b, 1, false);
break;
}
}
}
if (b.type.isRefinery())
{
return BuildingPlacer::Instance().getRefineryPosition();
}
if (b.type.isResourceDepot())
{
// get the location
BWAPI::TilePosition tile = MapTools::Instance().getNextExpansion();
return tile;
}
// set the building padding specifically
int distance = b.type == BWAPI::UnitTypes::Protoss_Photon_Cannon ? 0 : Config::Macro::BuildingSpacing;
if (b.type == BWAPI::UnitTypes::Protoss_Pylon && (numPylons < 3))
{
distance = Config::Macro::PylonSpacing;
}
// get a position within our region
return BuildingPlacer::Instance().getBuildLocationNear(b,distance,false);
}
开发者ID:ssssuishui,项目名称:SKBot,代码行数:58,代码来源:BuildingManager.cpp
示例5: updateAttackSquads
void CombatCommander::updateAttackSquads()
{
Squad & mainAttackSquad = _squadData.getSquad("MainAttack");
//check for overlord in squad
bool containsoverlord = false;
int numOverlords = 0;
for (auto& unit : mainAttackSquad.getUnits()) {
if (unit->getType() == BWAPI::UnitTypes::Zerg_Overlord)
{
containsoverlord = true;
numOverlords++;
}
}
// BWAPI::Broodwar->printf("Overlords in Attack squad: %d", numOverlords);
for (auto & unit : _combatUnits)
{
if (unit->getType() == BWAPI::UnitTypes::Zerg_Scourge && UnitUtil::GetAllUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) < 30)
{
continue;
}
// get every unit of a lower priority and put it into the attack squad
if (!unit->getType().isWorker() && (unit->getType() != BWAPI::UnitTypes::Zerg_Lurker) && _squadData.canAssignUnitToSquad(unit, mainAttackSquad))
{
if (unit->getType() == BWAPI::UnitTypes::Zerg_Overlord)
{
if (!containsoverlord && numOverlords < 2)
{
_squadData.assignUnitToSquad(unit, mainAttackSquad);
containsoverlord = true;
numOverlords++;
}
}
else {
_squadData.assignUnitToSquad(unit, mainAttackSquad);
}
}
}
// Defend bases until we have 3 lurkers
if (BWAPI::Broodwar->self()->getRace() == BWAPI::Races::Zerg && mainAttackSquad.getUnits().size() < 10) {
BWTA::BaseLocation * pos = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->self());
SquadOrder mainAttackOrder(SquadOrderTypes::Defend, pos->getPosition(), 250, "Defend Region!");
mainAttackSquad.setSquadOrder(mainAttackOrder);
return;
}
SquadOrder mainAttackOrder(SquadOrderTypes::Attack, getMainAttackLocation(), 800, "Attack Enemy Base");
mainAttackSquad.setSquadOrder(mainAttackOrder);
}
开发者ID:cmput350-charles,项目名称:ualbertabot,代码行数:55,代码来源:CombatCommander.cpp
示例6: getEnemyGeyser
BWAPI::Unit ScoutManager::getEnemyGeyser()
{
BWAPI::Unit geyser = nullptr;
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
for (auto & unit : enemyBaseLocation->getGeysers())
{
geyser = unit;
}
return geyser;
}
开发者ID:rcockbur,项目名称:cpp-StarCraft-AI-Competition,代码行数:12,代码来源:ScoutManager.cpp
示例7: getEnemyGeyser
BWAPI::UnitInterface* ScoutManager::getEnemyGeyser()
{
BWAPI::UnitInterface* geyser = NULL;
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
for (BWAPI::UnitInterface* unit : enemyBaseLocation->getGeysers())
{
geyser = unit;
}
return geyser;
}
开发者ID:NextGenIntelligence,项目名称:ualbertabot,代码行数:12,代码来源:ScoutManager.cpp
示例8: check
void ProbeUnit::check()
{
if (backUpMineral == NULL || !backUpMineral->exists())
{
if (Broodwar->getFrameCount() < 10*24*60)
{
BWTA::BaseLocation* b = BWTA::getStartLocation(Broodwar->self());
if (b != NULL && !b->getMinerals().empty())
backUpMineral = *(b->getMinerals().begin());
if (backUpMineral == NULL || !backUpMineral->exists())
backUpMineral = NULL;
}
}
}
开发者ID:AIUR-group,项目名称:BroodwarBotQ,代码行数:14,代码来源:ProbeUnit.cpp
示例9: onRevoke
void ScoutManager::onRevoke( BWAPI::Unit unit, double bid )
{
if ( m_scouts.find( unit ) != m_scouts.end() )
{
BWTA::BaseLocation* lostTarget = m_scouts[unit].m_target;
if ( m_baseLocationsExplored.find( lostTarget ) == m_baseLocationsExplored.end() )
{
m_baseLocationsToScout.push_back( lostTarget );
if ( m_debugMode )
{
BWAPI::Broodwar->printf( "Reassigning ( %d, %d )", lostTarget->getPosition().x, lostTarget->getPosition().y );
}
}
m_scouts.erase( unit );
}
}
开发者ID:Fobbah,项目名称:bwsal,代码行数:16,代码来源:ScoutManager.cpp
示例10: expand
BWTA::BaseLocation* BaseManager::expand(int priority)
{
BWTA::BaseLocation* location = NULL;
BWTA::BaseLocation* locationWithoutGas = NULL;
double minDist=-1;
BWTA::BaseLocation* home = BWTA::getStartLocation(BWAPI::Broodwar->self());
std::set<BWTA::BaseLocation*>::const_iterator i;
for(i = BWTA::getBaseLocations().begin(); i != BWTA::getBaseLocations().end(); i++)
{
BWTA::BaseLocation *baseLocation = (*i);
if (baseLocation->isIsland())
{
continue;
}
double dist = home->getGroundDistance(baseLocation);
if (dist > 0 && getBase(baseLocation) == NULL)
{
if (minDist == -1 || dist < minDist)
{
if (baseLocation->isMineralOnly())
{
locationWithoutGas = baseLocation;
}
else
{
location = baseLocation;
minDist = dist;
}
}
}
}
if (location == NULL && locationWithoutGas != NULL)
{
BWAPI::Broodwar->printf("Expanding to location without gas.");
location = locationWithoutGas;
}
return expand(location, priority);
}
开发者ID:albertouri,项目名称:dementor-bot,代码行数:45,代码来源:BaseManager.cpp
示例11: getBuildingLocation
BWAPI::TilePosition BuildingManager::getBuildingLocation(const Building & b)
{
int numPylons = BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Protoss_Pylon);
if (b.isGasSteal)
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
UAB_ASSERT(enemyBaseLocation,"Should have enemy base location before attempting gas steal");
UAB_ASSERT(enemyBaseLocation->getGeysers().size() > 0,"Should have spotted an enemy geyser");
for (auto & unit : enemyBaseLocation->getGeysers())
{
BWAPI::TilePosition tp(unit->getInitialTilePosition());
return tp;
}
}
if (b.type.requiresPsi() && numPylons == 0)
{
return BWAPI::TilePositions::None;
}
if (b.type.isRefinery())
{
return BuildingPlacer::Instance().getRefineryPosition();
}
if (b.type.isResourceDepot())
{
// get the location
BWAPI::TilePosition tile = MapTools::Instance().getNextExpansion();
return tile;
}
if (b.type == BWAPI::UnitTypes::Terran_Bunker)
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
UAB_ASSERT(enemyBaseLocation, "Should have enemy base location before attempting gas steal");
BWTA::Chokepoint * chokePoint = BWTA::getNearestChokepoint(enemyBaseLocation->getTilePosition());
std::pair<BWAPI::Position, BWAPI::Position> sides = chokePoint->getSides();
BWAPI::Position poi = enemyBaseLocation->getPosition().getDistance(sides.first) > enemyBaseLocation->getPosition().getDistance(sides.second) ? sides.first : sides.second;
//BWAPI::Broodwar->printf("Tisssle Position (%d, %d)", BWAPI::TilePosition(poi).x, BWAPI::TilePosition(poi).y);
return BWAPI::TilePosition(sides.second);
}
// set the building padding specifically
int distance = b.type == BWAPI::UnitTypes::Protoss_Photon_Cannon ? 0 : Config::Macro::BuildingSpacing;
if (b.type == BWAPI::UnitTypes::Protoss_Pylon && (numPylons < 3))
{
distance = Config::Macro::PylonSpacing;
}
// get a position within our region
return BuildingPlacer::Instance().getBuildLocationNear(b,distance,false);
}
开发者ID:SKBot,项目名称:SKBot,代码行数:56,代码来源:BuildingManager.cpp
示例12: isGasStealRefinery
bool WorkerManager::isGasStealRefinery(BWAPI::Unit unit)
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
if (!enemyBaseLocation)
{
return false;
}
if (enemyBaseLocation->getGeysers().empty())
{
return false;
}
for (auto & u : enemyBaseLocation->getGeysers())
{
if (unit->getTilePosition() == u->getTilePosition())
{
return true;
}
}
return false;
}
开发者ID:cmput350-charles,项目名称:ualbertabot,代码行数:23,代码来源:WorkerManager.cpp
示例13: checkEnemyMovedOut
void InformationManager::checkEnemyMovedOut(){
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
BWTA::BaseLocation * ourBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->self());
BWAPI::TilePosition ourBase = BWAPI::TilePosition(ourBaseLocation->getPosition());
if (enemyBaseLocation == nullptr)
{
double baseToBase = 0;
if (_distToFarthestBase < 1.0)
{
double currentBtoB = 0;
for (auto &bases : BWTA::getStartLocations())
{
currentBtoB = BWTA::getGroundDistance(ourBase, bases->getTilePosition());
if (currentBtoB > baseToBase)
{
baseToBase = currentBtoB;
}
}
_distToFarthestBase = baseToBase;
}
baseToBase = _distToFarthestBase;
double baseToUnit;
for (auto &unit : InformationManager::Instance().getUnitInfo(BWAPI::Broodwar->enemy()))
{
if (UnitUtil::IsCombatUnit(unit.second.unit))
{
BWAPI::TilePosition enemyPos = BWAPI::TilePosition(unit.second.lastPosition);
if (_movedOutMap.count(enemyPos) != 0)
{
if (_movedOutMap[enemyPos] == true)
{
//BWAPI::Broodwar->printf("Enemy has moved out!");
_enemyMovedOut = true;
return;
}
}
else
{
baseToUnit = BWTA::getGroundDistance(ourBase, BWAPI::TilePosition(unit.second.lastPosition));
if (baseToUnit < baseToBase)
{
//BWAPI::Broodwar->printf("Enemy has moved out!");
_enemyMovedOut = true;
_movedOutMap[enemyPos] = true;
return;
}
else
{
_movedOutMap[enemyPos] = false;
}
}
}
}
_enemyMovedOut = false;
//BWAPI::Broodwar->printf("Enemy in their base");
}
else
{
BWAPI::TilePosition enemyChoke = BWAPI::TilePosition(BWTA::getNearestChokepoint(enemyBaseLocation->getPosition())->getCenter());
if (_distToEnemyChoke < 1.0)
{
_distToEnemyChoke = BWTA::getGroundDistance(ourBase, enemyChoke);
}
double baseToChoke = _distToEnemyChoke;
double baseToUnit;
for (auto &unit : InformationManager::Instance().getUnitInfo(BWAPI::Broodwar->enemy()))
{
if (UnitUtil::IsCombatUnit(unit.second.unit))
{
BWAPI::TilePosition enemyPos = BWAPI::TilePosition(unit.second.lastPosition);
if (_movedOutMap.count(enemyPos) != 0)
{
if (_movedOutMap[enemyPos] == true)
{
//BWAPI::Broodwar->printf("Enemy has moved out!");
_enemyMovedOut = true;
return;
}
}
else
{
baseToUnit = BWTA::getGroundDistance(ourBase, enemyPos);
if (baseToUnit < baseToChoke)
{
//BWAPI::Broodwar->printf("Enemy has moved out!");
_enemyMovedOut = true;
_movedOutMap[enemyPos] = true;
return;
}
else
{
_movedOutMap[enemyPos] = false;
}
}
}
}
_enemyMovedOut = false;
//BWAPI::Broodwar->printf("Enemy in their base");
}
}
开发者ID:0x4849,项目名称:c350,代码行数:100,代码来源:InformationManager.cpp
示例14: getNextExpansion
BWAPI::TilePosition MapTools::getNextExpansion(BWAPI::Player player)
{
BWTA::BaseLocation * closestBase = nullptr;
double minDistance = 100000;
BWAPI::TilePosition homeTile = player->getStartLocation();
// for each base location
for (BWTA::BaseLocation * base : BWTA::getBaseLocations())
{
// if the base has gas
if (!base->isMineralOnly() && !(base == BWTA::getStartLocation(player)))
{
// get the tile position of the base
BWAPI::TilePosition tile = base->getTilePosition();
bool buildingInTheWay = false;
for (int x = 0; x < BWAPI::Broodwar->self()->getRace().getCenter().tileWidth(); ++x)
{
for (int y = 0; y < BWAPI::Broodwar->self()->getRace().getCenter().tileHeight(); ++y)
{
BWAPI::TilePosition tp(tile.x + x, tile.y + y);
for (auto & unit : BWAPI::Broodwar->getUnitsOnTile(tp))
{
if (unit->getType().isBuilding() && !unit->isFlying())
{
buildingInTheWay = true;
break;
}
}
}
}
if (buildingInTheWay)
{
continue;
}
// the base's distance from our main nexus
BWAPI::Position myBasePosition(player->getStartLocation());
BWAPI::Position thisTile = BWAPI::Position(tile);
double distanceFromHome = MapTools::Instance().getGroundDistance(thisTile,myBasePosition);
// if it is not connected, continue
if (!BWTA::isConnected(homeTile,tile) || distanceFromHome < 0)
{
continue;
}
if (!closestBase || distanceFromHome < minDistance)
{
closestBase = base;
minDistance = distanceFromHome;
}
}
}
if (closestBase)
{
return closestBase->getTilePosition();
}
else
{
return BWAPI::TilePositions::None;
}
}
开发者ID:DantesGearbox,项目名称:ualbertabot,代码行数:68,代码来源:MapTools.cpp
示例15: moveScouts
void ScoutManager::moveScouts()
{
if (!_workerScout || !_workerScout->exists() || !(_workerScout->getHitPoints() > 0))
{
return;
}
int scoutHP = _workerScout->getHitPoints() + _workerScout->getShields();
gasSteal();
// get the enemy base location, if we have one
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
int scoutDistanceThreshold = 30;
if (_workerScout->isCarryingGas())
{
BWAPI::Broodwar->drawCircleMap(_workerScout->getPosition(), 10, BWAPI::Colors::Purple, true);
}
// if we initiated a gas steal and the worker isn't idle,
bool finishedConstructingGasSteal = _workerScout->isIdle() || _workerScout->isCarryingGas();
if (!_gasStealFinished && _didGasSteal && !finishedConstructingGasSteal)
{
return;
}
// check to see if the gas steal is completed
else if (_didGasSteal && finishedConstructingGasSteal)
{
_gasStealFinished = true;
}
// if we know where the enemy region is and where our scout is
if (_workerScout && enemyBaseLocation)
{
int scoutDistanceToEnemy = MapTools::Instance().getGroundDistance(_workerScout->getPosition(), enemyBaseLocation->getPosition());
bool scoutInRangeOfenemy = scoutDistanceToEnemy <= scoutDistanceThreshold;
// we only care if the scout is under attack within the enemy region
// this ignores if their scout worker attacks it on the way to their base
if (scoutHP < _previousScoutHP)
{
_scoutUnderAttack = true;
}
if (!_workerScout->isUnderAttack() && !enemyWorkerInRadius())
{
_scoutUnderAttack = false;
}
// if the scout is in the enemy region
if (scoutInRangeOfenemy)
{
// get the closest enemy worker
BWAPI::Unit closestWorker = closestEnemyWorker();
// if the worker scout is not under attack
if (!_scoutUnderAttack)
{
// if there is a worker nearby, harass it
if (Config::Strategy::ScoutHarassEnemy && (!Config::Strategy::GasStealWithScout || _gasStealFinished) && closestWorker && (_workerScout->getDistance(closestWorker) < 800))
{
_scoutStatus = "Harass enemy worker";
_currentRegionVertexIndex = -1;
Micro::SmartAttackUnit(_workerScout, closestWorker);
}
// otherwise keep moving to the enemy region
else
{
_scoutStatus = "Following perimeter";
followPerimeter();
}
}
// if the worker scout is under attack
else
{
_scoutStatus = "Under attack inside, fleeing";
followPerimeter();
}
}
// if the scout is not in the enemy region
else if (_scoutUnderAttack)
{
_scoutStatus = "Under attack inside, fleeing";
followPerimeter();
}
else
{
_scoutStatus = "Enemy region known, going there";
// move to the enemy region
followPerimeter();
}
}
// for each start location in the level
//.........这里部分代码省略.........
开发者ID:rcockbur,项目名称:cpp-StarCraft-AI-Competition,代码行数:101,代码来源:ScoutManager.cpp
示例16: calculateEnemyRegionVertices
void ScoutManager::calculateEnemyRegionVertices()
{
BWTA::BaseLocation * enemyBaseLocation = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy());
//UAB_ASSERT_WARNING(enemyBaseLocation, "We should have an enemy base location if we are fleeing");
if (!enemyBaseLocation)
{
return;
}
BWTA::Region * enemyRegion = enemyBaseLocation->getRegion();
//UAB_ASSERT_WARNING(enemyRegion, "We should have an enemy region if we are fleeing");
if (!enemyRegion)
{
return;
}
const BWAPI::Position basePosition = BWAPI::Position(BWAPI::Broodwar->self()->getStartLocation());
const std::vector<BWAPI::TilePosition> & closestTobase = MapTools::Instance().getClosestTilesTo(basePosition);
std::set<BWAPI::Position> unsortedVertices;
// check each tile position
for (size_t i(0); i < closestTobase.size(); ++i)
{
const BWAPI::TilePosition & tp = closestTobase[i];
if (BWTA::getRegion(tp) != enemyRegion)
{
continue;
}
// a tile is 'surrounded' if
// 1) in all 4 directions there's a tile position in the current region
// 2) in all 4 directions there's a buildable tile
bool surrounded = true;
if (BWTA::getRegion(BWAPI::TilePosition(tp.x+1, tp.y)) != enemyRegion || !BWAPI::Broodwar->isBuildable(BWAPI::TilePosition(tp.x+1, tp.y))
|| BWTA::getRegion(BWAPI::TilePosition(tp.x, tp.y+1)) != enemyRegion || !BWAPI::Broodwar->isBuildable(BWAPI::TilePosition(tp.x, tp.y+1))
|| BWTA::getRegion(BWAPI::TilePosition(tp.x-1, tp.y)) != enemyRegion || !BWAPI::Broodwar->isBuildable(BWAPI::TilePosition(tp.x-1, tp.y))
|| BWTA::getRegion(BWAPI::TilePosition(tp.x, tp.y-1)) != enemyRegion || !BWAPI::Broodwar->isBuildable(BWAPI::TilePosition(tp.x, tp.y -1)))
{
surrounded = false;
}
// push the tiles that aren't surrounded
if (!surrounded && BWAPI::Broodwar->isBuildable(tp))
{
if (Config::Debug::DrawScoutInfo)
{
int x1 = tp.x * 32 + 2;
int y1 = tp.y * 32 + 2;
int x2 = (tp.x+1) * 32 - 2;
int y2 = (tp.y+1) * 32 - 2;
BWAPI::Broodwar->drawTextMap(x1+3, y1+2, "%d", MapTools::Instance().getGroundDistance(BWAPI::Position(tp), basePosition));
BWAPI::Broodwar->drawBoxMap(x1, y1, x2, y2, BWAPI::Colors::Green, false);
}
unsortedVertices.insert(BWAPI::Position(tp) + BWAPI::Position(16, 16));
}
}
std::vector<BWAPI::Position> sortedVertices;
BWAPI::Position current = *unsortedVertices.begin();
_enemyRegionVertices.push_back(current);
unsortedVertices.erase(current);
// while we still have unsorted vertices left, find the closest one remaining to current
while (!unsortedVertices.empty())
{
double bestDist = 1000000;
BWAPI::Position bestPos;
for (const BWAPI::Position & pos : unsortedVertices)
{
double dist = pos.getDistance(current);
if (dist < bestDist)
{
bestDist = dist;
bestPos = pos;
}
}
current = bestPos;
sortedVertices.push_back(bestPos);
unsortedVertices.erase(bestPos);
}
// let's close loops on a threshold, eliminating death grooves
int distanceThreshold = 100;
while (true)
{
// find the largest index difference whose distance is less than the threshold
int maxFarthest = 0;
int maxFarthestStart = 0;
//.........这里部分代码省略.........
开发者ID:rcockbur,项目名称:cpp-StarCraft-AI-Competition,代码行数:101,代码来源:ScoutManager.cpp
示例17: checkForCompletedBuildings
//.........这里部分代码省略.........
// remove this unit from the under construction vector
toRemove.push_back(b);
}
else
{
if (b.type == 131 && b.buildingUnit->getHitPoints() >= 1050 && !transferredDrones)
{
//BWAPI::Broodwar->printf("Send Drone");
//BWAPI::Unitset candidateProducers;
BWAPI::UnitType sunk = BWAPI::UnitTypes::Zerg_Creep_Colony;
Building z(sunk, createdHatcheriesVector[0]);
//BWAPI::Unit workerToAssign = WorkerManager::Instance().getMoveWorker(BWAPI::Position(createdHatcheriesVector[0]));
//BWAPI::Unit workerToAssign2 = WorkerManager::Instance().getMoveWorker(BWAPI::Position(createdHatcheriesVector[0]));
//WorkerManager::Instance().setMoveWorker(0, 0, BWAPI::Position(createdHatcheriesVector[0]));
//WorkerManager::Instance().setMoveWorker(0, 0, BWAPI::Position(createdHatcheriesVector[0]));
//_reservedMinerals += 75;
BWAPI::Unit workerToAssign = WorkerManager::Instance().getBuilder(z);
BWAPI::Unit workerToAssign2 = WorkerManager::Instance().getBuilder(z);
//WorkerData m;
//m.setWorkerJob(workerToAssign, WorkerData::Minerals, b.type);
/*
for (BWAPI::Unit p : BWAPI::Broodwar->self()->getUnits())
{
WorkerData k;
WorkerData::WorkerJob j = k.getWorkerJob(p);
if (p->getType().isWorker() && j != WorkerData::Scout)
{
*/
const std::set<BWTA::BaseLocation*, std::less<BWTA::BaseLocation*>> locations = BWTA::getBaseLocations();
BWTA::BaseLocation *myLocation;
for (BWTA::BaseLocation *p : locations) {
BWAPI::TilePosition z = p->getTilePosition();
if (z == createdHatcheriesVector[0]){
// This is the BWTA::Location of the first hatchery.
myLocation = p;
}
}
// Get the set of mineral patches closest to BWTA::Location of the hatchery(it will return like 8 mineral patches usually in the set)
const BWAPI::Unitset mineralSet = myLocation->getMinerals();
BWAPI::Unit myMineral;
for (BWAPI::Unit p : mineralSet)
{
myMineral = p;
// Calculate the difference between LeftMostMineralPatch.x - ExpansionHatchery.x and store it in theX
//theX = p->getTilePosition().x - hatchPosition.x;
// Calculate the difference between LeftMostMineralPatch.y - ExpansionHatchery.y and store it in theY
//theY = p->getTilePosition().y - hatchPosition.y;
break;
}
workerToAssign->gather(myMineral);
workerToAssign2->gather(myMineral);
sunkenUnit = workerToAssign;
sunkenUnit2 = workerToAssign2;
//sunkenID = workerToAssign->getID();
transferredDrones = true;
}
if (b.type == 131 && b.buildingUnit->getHitPoints() >= 1225 && !sentFirstDroneForSunken)
{
MetaType type(BWAPI::UnitTypes::Zerg_Creep_Colony);
ProductionManager::Instance()._queue.queueAsHighestPriority(type, true);
//sunkenID2 = workerToAssign2->getID();
//BWAPI::TilePosition tempPosition;
//tempPosition.x = b.finalPosition.x+4;
//tempPosition.y = b.finalPosition.y+4;
//Micro::SmartMove(p, BWAPI::Position(tempPosition));
//Micro::SmartMove(p, BWAPI::Position(tempPosition));
//p->move(BWAPI::Position(tempPosition));
//p->move(BWAPI::Position(tempPosition));
//break;
//candidateProducers.insert(p);
//MetaType type(BWAPI::UnitTypes::Zerg_Creep_Colony);
//ProductionManager::Instance()._queue.queueAsHighestPriority(type, true);
sentFirstDroneForSunken = true;
}
}
}
removeBuildings(toRemove);
}
开发者ID:0x4849,项目名称:c350,代码行数:101,代码来源:BuildingManagergggg.cpp
示例18: onStart
void BasicAIModule::onStart()
{
Broodwar->enableFlag( Flag::UserInput );
BWTA::readMap();
BWTA::analyze();
BWSAL::resetLog();
m_informationManager = InformationManager::create();
m_borderManager = BorderManager::create( m_informationManager );
m_baseManager = BaseManager::create( m_borderManager );
m_buildingPlacer = new BFSBuildingPlacer();
m_reservedMap = ReservedMap::create();
m_unitArbitrator = new UnitArbitrator();
m_unitGroupManager = UnitGroupManager::create();
m_buildUnitManager = BuildUnitManager::create();
m_buildEventTimeline = BuildEventTimeline::create( m_buildUnitManager );
m_taskScheduler = TaskScheduler::create( m_buildEventTimeline, m_buildUnitManager );
m_taskExecutor = TaskExecutor::create( m_unitArbitrator, m_buildEventTimeline, m_reservedMap, m_buildingPlacer );
m_workerManager = WorkerManager::create( m_unitArbitrator, m_baseManager );
m_scoutManager = ScoutManager::create( m_unitArbitrator, m_informationManager );
m_defenseManager = DefenseManager::create( m_unitArbitrator, m_borderManager );
m_buildOrderManager = BuildOrderManager::create( m_taskScheduler, m_taskExecutor, m_buildUnitManager );
m_supplyManager = SupplyManager::create( m_buildOrderManager, m_taskScheduler );
m_enhancedUI = new EnhancedUI();
m_buildEventTimeline->initialize();
m_scoutManager->initialize();
m_modules.push_back( m_informationManager );
m_modules.push_back( m_borderManager );
m_modules.push_back( m_baseManager );
m_modules.push_back( m_buildEventTimeline );
m_modules.push_back( m_reservedMap );
m_modules.push_back( m_unitGroupManager );
m_modules.push_back( m_buildUnitManager );
m_modules.push_back( m_taskScheduler );
m_modules.push_back( m_taskExecutor );
m_modules.push_back( m_workerManager );
m_modules.push_back( m_scoutManager );
m_modules.push_back( m_defenseManager );
BWAPI::Race race = Broodwar->self()->getRace();
BWAPI::Race enemyRace = Broodwar->enemy()->getRace();
double minDist;
BWTA::BaseLocation* natural = NULL;
BWTA::BaseLocation* home = BWTA::getStartLocation( Broodwar->self() );
foreach( BWTA::BaseLocation* bl, BWTA::getBaseLocations() )
{
if ( bl != home )
{
double dist = home->getGroundDistance( bl );
if ( dist > 0 )
{
if ( natural == NULL || dist < minDist)
{
minDist = dist;
natural = bl;
}
}
}
}
int buildID = 1;
if ( race == Races::Zerg )
{
// Send an overlord out if Zerg
m_scoutManager->setScoutCount( 1 );
if (buildID == 1)
{
//morph 5 lurkers (tests dependency resolver, task scheduler)
m_buildOrderManager->build( 8, UnitTypes::Zerg_Drone, 90 );
m_buildOrderManager->buildAdditional( 1, UnitTypes::Zerg_Overlord, 85 );
m_buildOrderManager->build( 12, UnitTypes::Zerg_Drone, 84 );
m_buildOrderManager->buildAdditional( 1, UnitTypes::Zerg_Lair, 82);
m_buildOrderManager->buildAdditional( 5, UnitTypes::Zerg_Lurker, 80);
m_buildOrderManager->build( 12, UnitTypes::Zerg_Drone, 30 );
}
else if (buildID >= 2)
{
//12 pool 6 lings (tests larva task scheduler)
m_buildOrderManager->build( 8, UnitTypes::Zerg_Drone, 90 );
m_buildOrderManager->buildAdditional( 1, UnitTypes::Zerg_Overlord, 85 );
m_buildOrderManager->build( 12, UnitTypes::Zerg_Drone, 84 );
m_buildOrderManager->buildAdditional( 1, UnitTypes::Zerg_Spawning_Pool, 70 );
m_buildOrderManager->buildAdditional( 3, UnitTypes::Zerg_Zergling, 65 );
m_buildOrderManager->build( 40, UnitTypes::Zerg_Drone, 62 );
}
}
else if ( race == Races::Terran )
{
if (buildID == 1)
{
//build 3 comsat stations (tests dependency resolver)
m_buildOrderManager->build(9,UnitTypes::Terran_SCV,90);
m_buildOrderManager->build(1,UnitTypes::Terran_Supply_Depot,85);
m_buildOrderManager->build(20,UnitTypes::Terran_SCV,80);
m_buildOrderManager->buildAdditional(3,UnitTypes::Terran_Comsat_Station,60);
}
else if (buildID == 2)
{
//.........这里部分代码省略.........
开发者ID:Insomniumm,项目名称:bwsal,代码行数:101,代码来源:BasicAIModule.cpp
示例19: updateScoutAssignments
void ScoutManager::updateScoutAssignments()
{
// Remove scout positions if the enemy is not there.
for ( std::map< BWAPI::Unit, ScoutData >::iterator s = m_scouts.begin(); s != m_scouts.end(); s++ )
{
if ( s->second.m_mode == ScoutData::Searching
&& s->first->getPosition().getDistance( s->second.m_target->getPosition() ) < s->first->getType().sightRange() )
{
bool empty = true;
for ( int x = s->second.m_target->getTilePosition().x; x < s->second.m_target->getTilePosition().x + 4; x++ )
{
for ( int y = s->second.m_target->getTilePosition().y; y < s->second.m_target->getTilePosition().y + 3; y++ )
{
for( BWAPI::Unit u : BWAPI::Broodwar->getUnitsOnTile( x, y ) )
{
if ( u->getType().isResourceDepot() )
{
empty = false;
break;
}
}
if ( !empty ) break;
}
if ( !empty ) break;
}
if ( empty )
{
m_informationManager->setBaseEmpty( s->second.m_target );
}
BWTA::BaseLocation* exploredBaseLocation = s->second.m_target;
m_baseLocationsToScout.remove( exploredBaseLocation );
m_baseLocationsExplored.insert( exploredBaseLocation );
s->second.m_mode = ScoutData::Idle;
if ( m_debugMode )
{
BWAPI::Broodwar->printf( "Sucessfully scouted ( %d, %d )", exploredBaseLocation->getPosition().x, exploredBaseLocation->getPosition().y );
}
}
}
// Set scouts to scout.
if ( m_baseLocationsToScout.size() > 0 ) // are there still positions to scout?
{
for ( std::map< BWAPI::Unit, ScoutData >::iterator s = m_scouts.begin(); s != m_scouts.end(); s++ )
{
if ( s->second.m_mode == ScoutData::Idle )
{
double minDist = 100000000;
BWTA::BaseLocation* target = NULL;
for( BWTA::BaseLocation* bl : m_baseLocationsToScout )
{
double distance = s->first->getPosition().getDistance( bl->getPosition() );
if ( distance < minDist )
{
minDist = distance;
target = bl;
}
}
if ( target != NULL )
{
s->second.m_mode = ScoutData::Searching;
s->first->rightClick( target->getPosition() );
s->second.m_target = target;
m_baseLocationsToScout.remove( target );
if ( m_debugMode )
{
BWAPI::Broodwar->printf( "Scouting ( %d, %d )", target->getPosition().x, target->getPosition().y );
}
}
}
}
}
}
开发者ID:Fobbah,项目名称:bwsal,代码行数:75,代码来源:ScoutManager.cpp
示例20: moveScouts
void ScoutManager::moveScouts()
{
if (!_workerScout || !_workerScout->exists() |
|
请发表评论