本文整理汇总了C++中TilePosition::getDistance方法的典型用法代码示例。如果您正苦于以下问题:C++ TilePosition::getDistance方法的具体用法?C++ TilePosition::getDistance怎么用?C++ TilePosition::getDistance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TilePosition
的用法示例。
在下文中一共展示了TilePosition::getDistance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNextScanLocation
TilePosition StructureAgent::getNextScanLocation()
{
TilePosition ePos = ExplorationManager::getInstance()->getClosestSpottedBuilding(Broodwar->self()->getStartLocation());
if (ePos.x() > -1)
{
//Already found enemy base
return TilePosition(-1, -1);
}
for(set<BaseLocation*>::const_iterator i=getStartLocations().begin();i!=getStartLocations().end();i++)
{
TilePosition basePos = (*i)->getTilePosition();
bool needScan = true;
//1. Check previous scans
for (int i = 0; i < (int)hasScanned.size(); i++)
{
if (hasScanned.at(i).x() == basePos.x() && hasScanned.at(i).y() == basePos.y())
{
needScan = false;
}
}
//2. Check if we have this base
vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
for (int i = 0; i < (int)agents.size(); i++)
{
if (agents.at(i)->isAlive())
{
double dist = basePos.getDistance(agents.at(i)->getUnit()->getTilePosition());
if (dist <= 10)
{
needScan = false;
break;
}
}
}
//3. Check if enemy units are near
for(set<Unit*>::const_iterator j=Broodwar->enemy()->getUnits().begin();j!=Broodwar->enemy()->getUnits().end();j++)
{
if ((*j)->exists())
{
double dist = basePos.getDistance((*j)->getTilePosition());
if (dist <= 10)
{
needScan = false;
break;
}
}
}
if (needScan)
{
return basePos;
}
}
return TilePosition(-1, -1);
}
示例2: findClosestMineral
Unit BuildingPlacer::findClosestMineral(TilePosition workerPos)
{
Unit mineral = NULL;
double bestDist = 10000;
for(BaseLocation* base : getBaseLocations())
{
TilePosition pos = base->getTilePosition();
double cDist = pos.getDistance(workerPos);
if (cDist < bestDist)
{
//Find closest base
BaseAgent* base = AgentManager::getInstance()->getClosestBase(pos);
if (base != NULL)
{
double dist = pos.getDistance(base->getUnit()->getTilePosition());
if (dist <= 12)
{
//We have a base near this base location
//Check if we have minerals available
Unit cMineral = hasMineralNear(pos);
if (cMineral != NULL)
{
mineral = cMineral;
bestDist = cDist;
}
}
}
}
}
//We have no base with minerals, do nothing
return mineral;
}
示例3: checkMinerals
/*
if the mineral fields at our base are getting low then construct a new base
*/
void ProductionManager::checkMinerals()
{
if(!expansionQueued)
{
Unit* closestMineral = NULL;
TilePosition home;
//find main
for(std::set<Unit*>::const_iterator i=Broodwar->self()->getUnits().begin();i!=Broodwar->self()->getUnits().end();i++)
{
if ((*i)->getType().isResourceDepot())
{
home = (*i)->getTilePosition();
for(std::set<BWAPI::Unit*>::iterator m = Broodwar->getMinerals().begin(); m != Broodwar->getMinerals().end(); m++)
{
if (closestMineral==NULL || home.getDistance((*m)->getTilePosition()) < home.getDistance(closestMineral->getTilePosition()))
closestMineral=*m;
}
if (closestMineral!=NULL)
{
if(closestMineral->getResources() < 150)
{
production.queueAsHighestPriority(MetaType(Broodwar->self()->getRace().getCenter()), true);
expansionQueued = true;
}
}
}
}
}
}
示例4: findClosestMineral
Unit* CoverMap::findClosestMineral(TilePosition workerPos)
{
Unit* mineral = NULL;
double bestDist = 10000;
for(set<BWTA::BaseLocation*>::const_iterator i=BWTA::getBaseLocations().begin(); i!= BWTA::getBaseLocations().end(); i++)
{
TilePosition pos = (*i)->getTilePosition();
double cDist = pos.getDistance(workerPos);
if (cDist < bestDist)
{
//Find closest base
BaseAgent* base = AgentManager::getInstance()->getClosestBase(pos);
double dist = pos.getDistance(base->getUnit()->getTilePosition());
if (dist <= 12)
{
//We have a base near this base location
//Check if we have minerals available
Unit* cMineral = hasMineralNear(pos);
if (cMineral != NULL)
{
mineral = cMineral;
bestDist = cDist;
}
}
}
}
//We have no base with minerals, do nothing
return mineral;
}
示例5: matches
bool PathObj::matches(TilePosition cStart, TilePosition cEnd)
{
//Check if end almost matches
double dist = cEnd.getDistance(end);
if (dist > 3) return false;
//Check if start almost matches.
dist = cStart.getDistance(start);
if (dist > 5) return false;
return true;
}
示例6: isOccupied
bool Commander::isOccupied(BWTA::Region* region)
{
BWTA::Polygon p = region->getPolygon();
vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
for (int i = 0; i < (int)agents.size(); i++)
{
BaseAgent* agent = agents.at(i);
if (agent->isAlive() && agent->getUnitType().isResourceDepot())
{
BWTA::Region* aRegion = getRegion(agents.at(i)->getUnit()->getTilePosition());
Position c1 = region->getCenter();
Position c2 = aRegion->getCenter();
if (c2.x() == c1.x() && c2.y() == c1.y())
{
return true;
}
}
}
//Check expansion site
TilePosition expansionSite = ExplorationManager::getInstance()->getExpansionSite();
TilePosition center = TilePosition(region->getCenter());
if (expansionSite.x() >= 0)
{
double dist = expansionSite.getDistance(center);
if (dist <= 15)
{
return true;
}
}
return false;
}
示例7: findExpansionSite
TilePosition CoverMap::findExpansionSite()
{
UnitType baseType = Broodwar->self()->getRace().getCenter();
double bestDist = 100000;
TilePosition bestPos = TilePosition(-1, -1);
//Iterate through all base locations
for(set<BWTA::BaseLocation*>::const_iterator i=BWTA::getBaseLocations().begin(); i!= BWTA::getBaseLocations().end(); i++)
{
TilePosition pos = (*i)->getTilePosition();
bool taken = false;
//Check if own buildings are close
vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
int noBases = 0;
for (int i = 0; i < (int)agents.size(); i++)
{
BaseAgent* agent = agents.at(i);
if (agent->isAlive() && agent->getUnitType().isResourceDepot())
{
double dist = pos.getDistance(agent->getUnit()->getTilePosition());
if (dist <= 12)
{
noBases++;
}
}
}
if (BuildPlanner::isZerg())
{
if (noBases >= 2) taken = true;
}
else
{
if (noBases >= 1) taken = true;
}
//Check if enemy buildings are close
int eCnt = ExplorationManager::getInstance()->spottedBuildingsWithinRange(pos, 20);
if (eCnt > 0)
{
taken = true;
}
//Not taken, calculate ground distance
if (!taken)
{
if (ExplorationManager::canReach(Broodwar->self()->getStartLocation(), pos))
{
double dist = mapData.getDistance(Broodwar->self()->getStartLocation(), pos);
if (dist <= bestDist)
{
bestDist = dist;
bestPos = pos;
}
}
}
}
return bestPos;
}
示例8: operator
int operator()(TilePosition position, TilePosition target)
{
int h = 0;
for each(Unit enemy in mEnemies)
{
h += mMmaxHValue - (int)position.getDistance(enemy->getTilePosition());
}
示例9: isCloseTo
bool Squad::isCloseTo(TilePosition mGoal)
{
double dist = mGoal.getDistance(goal);
if (dist <= 3)
{
return true;
}
return false;
}
示例10: getDistance
int MapDataReader::getDistance(TilePosition t1, TilePosition t2)
{
for (int i = 0; i < (int)data.size(); i++)
{
if (data.at(i).matches(t1, t2))
{
return data.at(i).dist;
}
}
int dist = (int)(t1.getDistance(t2));
return dist;
}
示例11: getClosestEnemyBuilding
TilePosition Commander::getClosestEnemyBuilding(TilePosition start) {
Unit* closestBuilding = NULL;
SpottedObject* closestObj = NULL;
double bestDist = -1;
for(set<Unit*>::const_iterator i=Broodwar->enemy()->getUnits().begin();i!=Broodwar->enemy()->getUnits().end();i++) {
if ((*i)->getType().isBuilding()) {
//V2
double cDist = start.getDistance((*i)->getTilePosition());
//V1 - TODO: Better, but too damn slow
//vector<TilePosition> path = BWTA::getShortestPath(start, (*i)->getTilePosition());
//double cDist = (double)path.size();
if (!ExplorationManager::canReach(start, (*i)->getTilePosition())) {
cDist = -1;
}
if (bestDist < 0 || cDist < bestDist) {
bestDist = cDist;
closestBuilding = (*i);
}
}
}
if (closestBuilding != NULL) {
//Broodwar->printf("[TSC]: Closest enemy building is %s", closestBuilding->getType().getName().c_str());
return closestBuilding->getTilePosition();
}
else if (ExplorationManager::getInstance()->isActive()) {
bestDist = -1;
vector<SpottedObject*> units = ExplorationManager::getInstance()->getSpottedBuildings();
for (int i = 0; i < (int)units.size(); i++) {
SpottedObject* obj = units.at(i);
if (obj->getType().isBuilding() && obj->isActive()) {
double cDist = obj->getDistance(start);
if (bestDist < 0 || cDist < bestDist) {
bestDist = cDist;
closestObj = obj;
}
}
}
//Broodwar->printf("[TSC]: using ExpManager. Closest is %s", closestObj.getType().getName().c_str());
}
else {
//Broodwar->printf("[TSC]: No enemy building found");
return TilePosition(-1, -1);
}
return closestObj->getTilePosition();
}
示例12: searchRefinerySpot
TilePosition CoverMap::searchRefinerySpot()
{
for(int i = 0 ; i < w ; i++)
{
for (int j = 0; j < h; j++)
{
if (cover_map[i][j] == GAS)
{
TilePosition cPos = TilePosition(i,j);
bool found = false;
vector<BaseAgent*> agents = AgentManager::getInstance()->getAgents();
for (int i = 0; i < (int)agents.size(); i++)
{
if (agents.at(i)->getUnitType().isRefinery())
{
double dist = agents.at(i)->getUnit()->getTilePosition().getDistance(cPos);
TilePosition uPos = agents.at(i)->getUnit()->getTilePosition();
if (dist <= 2)
{
found = true;
break;
}
}
}
if (!found)
{
BaseAgent* agent = AgentManager::getInstance()->getClosestBase(cPos);
if (agent != NULL)
{
TilePosition bPos = agent->getUnit()->getTilePosition();
double dist = bPos.getDistance(cPos);
if (dist < 15)
{
if (ExplorationManager::canReach(bPos, cPos))
{
return cPos;
}
}
}
}
}
}
}
return TilePosition(-1, -1);
}
示例13: getChokepointPrio
double Commander::getChokepointPrio(TilePosition center)
{
TilePosition ePos = ExplorationManager::getInstance()->getClosestSpottedBuilding(center);
if (ePos.x() >= 0)
{
double dist = ePos.getDistance(center);
return 1000 - dist;
}
else
{
double dist = Broodwar->self()->getStartLocation().getDistance(center);
return dist;
}
}
示例14: hasMineralNear
Unit BuildingPlacer::hasMineralNear(TilePosition pos)
{
for (auto &u : Broodwar->getMinerals())
{
if (u->exists() && u->getResources() > 0)
{
double dist = pos.getDistance(u->getTilePosition());
if (dist <= 10)
{
return u;
}
}
}
return NULL;
}
示例15: getClosestStartLocation
TilePosition Squad::getClosestStartLocation(TilePosition pos)
{
TilePosition sloc = pos;
double bestDist = 10000;
for(set<BaseLocation*>::const_iterator i=getStartLocations().begin();i!=getStartLocations().end();i++)
{
TilePosition basePos = (*i)->getTilePosition();
double dist = pos.getDistance(basePos);
if (dist < bestDist)
{
bestDist = dist;
sloc = basePos;
}
}
return sloc;
}