本文整理汇总了C++中bwapi::Position::getDistance方法的典型用法代码示例。如果您正苦于以下问题:C++ Position::getDistance方法的具体用法?C++ Position::getDistance怎么用?C++ Position::getDistance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bwapi::Position
的用法示例。
在下文中一共展示了Position::getDistance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
bool operator()(const BWAPI::Position lhs, const BWAPI::Position rhs)
{
if (lhs.getDistance(InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy())->getPosition()) <
rhs.getDistance(InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy())->getPosition())) return true;
//ensure each position gets added to the set
if (lhs.getDistance(InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy())->getPosition()) >
rhs.getDistance(InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy())->getPosition())) return false;
return true;
}
示例2: getNearestUnwalkablePosition
BWAPI::Position getNearestUnwalkablePosition(BWAPI::Position position)
{
Polygon* p = BWTA::getNearestUnwalkablePolygon(position.x()/32,position.y()/32);
BWAPI::Position nearest = BWAPI::Positions::None;
if (p == NULL)
{
//use an edge of the map if we don't find a polygon
nearest = BWAPI::Position(0,position.y());
}
else
{
nearest = p->getNearestPoint(position);
}
if (position.x()<position.getDistance(nearest))
nearest=BWAPI::Position(0,position.y());
if (position.y()<position.getDistance(nearest))
nearest=BWAPI::Position(position.x(),0);
if (BWAPI::Broodwar->mapWidth()*32-position.x()<position.getDistance(nearest))
nearest=BWAPI::Position(BWAPI::Broodwar->mapWidth()*32,position.y());
if (BWAPI::Broodwar->mapHeight()*32-position.y()<position.getDistance(nearest))
nearest=BWAPI::Position(position.x(),BWAPI::Broodwar->mapHeight()*32);
return nearest;
}
示例3: initialize_map_points
void BaitManager::initialize_map_points(std::string mapName)
{
//BWAPI::Position mainBaseLocation =
//BWTA::BaseLocation * mainBaseLocation = BWTA::getStartLocation(BWAPI::Broodwar->self());
BWAPI::Position mainBasePosition = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->self())->getPosition();
//BWAPI::Position mainBasePositon = mainBaseLocation->getPosition();
mapLoaded = true;
if (mapName == "(2)Benzene.scx")
{
//set the point where the bait unit will wait for enemies
if (mainBasePosition.getDistance(BWAPI::Position(400, 1953)) > mainBasePosition.getDistance(BWAPI::Position(3180, 1790)))
{
waitPoint = BWAPI::Position(400, 1953);
}
else
{
waitPoint = BWAPI::Position(3180, 1790);
}
//set the points where the bait unit will flee to
chasePoints.push_back(BWAPI::Position(1400, 960));
chasePoints.push_back(BWAPI::Position(1050, 790));
chasePoints.push_back(BWAPI::Position(1110, 500));
chasePoints.push_back(BWAPI::Position(1400, 320));
chasePoints.push_back(BWAPI::Position(1880, 604));
BWAPI::Broodwar->printf("Map Benzene Loaded");
return;
}
else if (mapName == "(2)Destination.scx")
{
//set the point where the bait unit will wait for enemies
if (mainBasePosition.getDistance(BWAPI::Position(1155, 3515)) > mainBasePosition.getDistance(BWAPI::Position(1890, 525)))
{
waitPoint = BWAPI::Position(1155, 3515);
}
else
{
waitPoint = BWAPI::Position(1890, 525);
}
//set the points where the bait unit will flee to
chasePoints.push_back(BWAPI::Position(1115, 1848));
chasePoints.push_back(BWAPI::Position(1170, 1143));
chasePoints.push_back(BWAPI::Position(1200, 2255));
chasePoints.push_back(BWAPI::Position(958, 2770));
chasePoints.push_back(BWAPI::Position(270, 1857));
BWAPI::Broodwar->printf("Map Destination Loaded");
return;
}
else if (mapName == "(2)Heartbreak Ridge.scx")
{
//set the point where the bait unit will wait for enemies
if (mainBasePosition.getDistance(BWAPI::Position(3320, 930)) > mainBasePosition.getDistance(BWAPI::Position(720, 2175)))
{
waitPoint = BWAPI::Position(3320, 930);
}
else
{
waitPoint = BWAPI::Position(720, 2175);
}
//set the points where the bait unit will flee to
chasePoints.push_back(BWAPI::Position(2050, 11));
chasePoints.push_back(BWAPI::Position(3340, 34));
chasePoints.push_back(BWAPI::Position(349, 175));
chasePoints.push_back(BWAPI::Position(3180, 237));
chasePoints.push_back(BWAPI::Position(690, 197));
chasePoints.push_back(BWAPI::Position(373, 376));
chasePoints.push_back(BWAPI::Position(215, 221));
chasePoints.push_back(BWAPI::Position(395, 89));
BWAPI::Broodwar->printf("Map Heartbreak Ridge Loaded");
return;
}
//BWAPI::Position enemyBasePosition = InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy())->getPosition();
if (!InformationManager::Instance().getMainBaseLocation(BWAPI::Broodwar->enemy())->getPosition().isValid())
{
mapLoaded = false;
BWAPI::Broodwar->printf("Cannot load 3-4 player map until enemy base is found");
return;
}
//create a set to add positions to sorted such the the closest one to the enemy base is first
std::set<BWAPI::Position, posComp> basePoints;
if (mapName == "(3)Aztec.scx")
{
//set the point where the bait unit will wait for enemies
basePoints.insert(BWAPI::Position(3097, 366));
basePoints.insert(BWAPI::Position(3321, 3798));
basePoints.insert(BWAPI::Position(294, 1994));
waitPoint = *basePoints.begin();
//set the points where the bait unit will flee to
chasePoints.push_back(BWAPI::Position(2180, 3374));
chasePoints.push_back(BWAPI::Position(1812, 2014));
chasePoints.push_back(BWAPI::Position(2410, 1915));
BWAPI::Broodwar->printf("Map Aztec Loaded");
}
//.........这里部分代码省略.........
示例4: getBuildLocationFarFromChokePoint
//ctx add
BWAPI::TilePosition BuildingPlacer::getBuildLocationFarFromChokePoint(const Building & b, int buildDist, bool horizontalOnly, bool flag) const
{
SparCraft::Timer t;
t.start();
BWAPI::TilePosition startTitlePos = BWAPI::Broodwar->self()->getStartLocation();
BWTA::Chokepoint *chokePoint = BWTA::getNearestChokepoint(startTitlePos);
BWAPI::Position chokeCenterPosition = chokePoint->getCenter();
BWTA::Region *baseRegion = BWTA::getRegion(BWAPI::Broodwar->self()->getStartLocation());
BWTA::Polygon basePolygon = baseRegion->getPolygon();
BWAPI::Position farPosition = BWAPI::Position(0, 0);
BWAPI::TilePosition resultPosition = BWAPI::TilePosition(0, 0);
double dis = 0.0;
for (int i = 0; i < (int)basePolygon.size(); i++) {
BWAPI::Position point = basePolygon[i];
double ms1 = t.getElapsedTimeInMilliSec();
if (point.getDistance(chokeCenterPosition) > dis) {
dis = point.getDistance(chokeCenterPosition);
farPosition = point;
}
}
const std::vector<BWAPI::TilePosition> & closestToBuilding = MapTools::Instance().getClosestTilesTo(BWAPI::Position(b.desiredPosition));
//get best solution
dis = farPosition.getDistance(BWAPI::Position(startTitlePos));
if (flag == true) {
for (size_t i = 0; i < closestToBuilding.size(); ++i)
{
double ms1 = t.getElapsedTimeInMilliSec();
if (canBuildHereWithSpace(closestToBuilding[i], b, buildDist, horizontalOnly) && dis > farPosition.getDistance(BWAPI::Position(closestToBuilding[i])))
{
resultPosition = closestToBuilding[i];
break;
//return closestToBuilding[i];
}
}
}
else {
for (size_t i = 0; i < closestToBuilding.size(); ++i)
{
double ms1 = t.getElapsedTimeInMilliSec();
if (canBuildHereWithSpace(closestToBuilding[i], b, buildDist, horizontalOnly) && dis < farPosition.getDistance(BWAPI::Position(closestToBuilding[i])))
{
resultPosition = closestToBuilding[i];
break;
//return closestToBuilding[i];
}
}
}
if (!basePolygon.isInside(BWAPI::Position(resultPosition))) {
resultPosition = getBuildLocationNear(b, buildDist, horizontalOnly);
}
return resultPosition;
}