当前位置: 首页>>代码示例>>C++>>正文


C++ Position::x方法代码示例

本文整理汇总了C++中bwapi::Position::x方法的典型用法代码示例。如果您正苦于以下问题:C++ Position::x方法的具体用法?C++ Position::x怎么用?C++ Position::x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bwapi::Position的用法示例。


在下文中一共展示了Position::x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getSector

char getSector (BWAPI::Position p){
	/*
		Dividindo o mapa em 9 setores:

			   (C1)   (C2)
			  A  |  B  |  C  
			----------------- (L1)
			  K  |  L  |  M  
			----------------- (L2)
			  X  |  Y  |  Z  

		A funcao recebe uma posicao e retorna em qual setor estah
	*/

	int width = centro.x()*2;
	int height = centro.y()*2;

	double C1 = width / 3;
	double C2 = (2*width) / 3;

	double L1 = height / 3;
	double L2 = (2*height) / 3;

	if(p.x() < C1 && p.y() < L1) return 'A';
	if(p.x() > C1 && p.x() < C2 && p.y() < L1) return 'B';
	if(p.x() > C2 && p.y() < L1) return 'C';

	if(p.x() < C1 && p.y() > L1 && p.y() < L2) return 'K';
	if(p.x() > C1 && p.x() < C2 && p.y() > L1 && p.y() < L2) return 'L';
	if(p.x() > C2 && p.y() > L1 && p.y() < L2) return 'M';

	if(p.x() < C1 && p.y() > L2) return 'X';
	if(p.x() > C1 && p.x() < C2 && p.y() > L2) return 'Y';
	if(p.x() > C2 && p.y() > L2) return 'Z';
}
开发者ID:pedroneves,项目名称:bloodbath-and-beyond,代码行数:35,代码来源:MeuAgentePrincipal.cpp

示例2: onSendText

	void AIModule::onSendText(std::string text)
	{
		game->printf(text.c_str());

		if (text == "dbg")
		{
			debug = !debug;

			buildOrderManager->setDebugMode(debug);

			game->printf("Debug turned %s.", (debug) ? "on" : "off");
		}

		if (text == "atc")
		{
			autocam = !autocam;

			game->printf("Autocam turned %s.", (autocam) ? "on" : "off");
		}

		if (text == "gsn")
		{
			localSpeed = 30;
			frameSkip = 0;

			updateGameSpeed();
		}

		if (text == "gsf")
		{
			localSpeed = 0;
			frameSkip = 0;

			updateGameSpeed();
		}

		if (text == "gsfs")
		{
			localSpeed = 0;
			frameSkip = 8;

			updateGameSpeed();
		}

		if (text == "atk")
		{
			BWAPI::Position mousePosition = game->getMousePosition();
			BWAPI::Position screenPosition = game->getScreenPosition();

			BWAPI::Position mapPosition = BWAPI::Position(mousePosition.x() + screenPosition.x(), mousePosition.y() + screenPosition.y());
			agentManager->attackMoveTo(mapPosition);

			game->printf("Issued manual attack at %d %d.", mapPosition.x(), mapPosition.y());
		}
	}
开发者ID:albertouri,项目名称:dementor-bot,代码行数:55,代码来源:AIModule.cpp

示例3: calculate_walk_distances_area

 void calculate_walk_distances_area(const BWAPI::Position& start
                                    , int width
                                    , int height
                                    , int max_distance
                                    , RectangleArray<int>& distance_map)
 {
     Heap<BWAPI::Position, int> heap(true);
     for (unsigned int x = 0;x < distance_map.getWidth();x++) {
         for (unsigned int y = 0;y < distance_map.getHeight();y++) {
             distance_map[x][y] = -1;
         }
     }
     int sx = (int)start.x();
     int sy = (int)start.y();
     for (int x = sx;x < sx + width;x++) {
         for (int y = sy;y < sy + height;y++) {
             heap.push(std::make_pair(BWAPI::Position(x, y), 0));
             distance_map[x][y] = 0;
         }
     }
     while (!heap.empty()) {
         BWAPI::Position pos = heap.top().first;
         int distance = heap.top().second;
         heap.pop();
         int x = (int)pos.x();
         int y = (int)pos.y();
         if (distance > max_distance && max_distance > 0)
             break;
         int min_x = max(x - 1, 0);
         int max_x = min(x + 1, BWAPI::Broodwar->mapWidth() * 4 - 1);
         int min_y = max(y - 1, 0);
         int max_y = min(y + 1, BWAPI::Broodwar->mapHeight() * 4 - 1);
         for (int ix = min_x;ix <= max_x;ix++) {
             for (int iy = min_y;iy <= max_y;iy++) {
                 int f = abs(ix - x) * 10 + abs(iy - y) * 10;
                 if (f > 10) {
                     f = 14;
                 }
                 int v = distance + f;
                 if (distance_map[ix][iy] > v) {
                     heap.set(BWAPI::Position(x, y), v);
                     distance_map[ix][iy] = v;
                 } else {
                     if (distance_map[ix][iy] == -1 && MapData::rawWalkability[ix][iy] == true) {
                         distance_map[ix][iy] = v;
                         heap.push(std::make_pair(BWAPI::Position(ix, iy), v));
                     }
                 }
             }
         }
     }
 }
开发者ID:krasi0,项目名称:bwapi-bwta-map-analyzer,代码行数:52,代码来源:util.cpp

示例4: getMoveTo

	// given a position, get the position we should move to to minimize distance
	BWAPI::Position getMoveTo(const BWAPI::Position p, const int lookAhead = 1) const
	{
		// the initial row an column
		int row = p.y() / 32;
		int col = p.x() / 32;
		
		// for each lookahead
		for (int i=0; i<lookAhead; ++i)
		{
			// get the index
			int index = getIndex(row,col);

			// adjust the row and column accordingly
			if (moveTo[index] == 'L')
			{
				col -= 1;
			} 
			else if (moveTo[index] == 'R')
			{
				col += 1;
			} 
			else if (moveTo[index] == 'U')
			{
				row -= 1;
			} 
			else
			{
				row += 1;
			}
		}

		// return the position
		return BWAPI::Position(col * 32 + 16, row * 32 + 16);
	}
开发者ID:adamjford,项目名称:ualbertabot,代码行数:35,代码来源:DistanceMap.hpp

示例5: onNukeDetect

void StarCraftAIModule::onNukeDetect(BWAPI::Position target)
{
	if (target!=Positions::Unknown)
		Broodwar->printf("Nuclear Launch Detected at (%d,%d)",target.x(),target.y());
	else
		Broodwar->printf("Nuclear Launch Detected");
}
开发者ID:anas-salama,项目名称:IStrategizer,代码行数:7,代码来源:StarCraftAIModule.cpp

示例6: buildGateway

void buildGateway(){
	resourceSemaphore = true;
	Unidade* worker = Protoss_Workers[numWorkers-1];
	Selected_Worker = worker;
	Unidade* Selected_Pylon = Protoss_Pylons[numPylons-1];
	Unidade* nexus = Protoss_Nexus;
	int delta_y;
	int delta_x;
	int desviox=0;
	int desvioy=0;
	delta_y	=	nexus->getPosition().y() - Selected_Pylon->getPosition().y();
	delta_x =	nexus->getPosition().x() - Selected_Pylon->getPosition().x();
	BWAPI::Position setPos = BWAPI::Position(Selected_Pylon->getPosition().x()-delta_x*3/2,Selected_Pylon->getPosition().y()-delta_y*3/2);
	worker->build(BWAPI::TilePosition(setPos),UnitTypes::Protoss_Gateway);
	while(!worker->isConstructing())
	{
		desviox += 5*(rand()%3-1);
		desvioy += 5*(rand()%3-1);
		setPos = BWAPI::Position(Selected_Pylon->getPosition().x()-delta_x*3/2+desviox,Selected_Pylon->getPosition().y()-delta_y*3/2+desvioy);
		worker->build(BWAPI::TilePosition(setPos),UnitTypes::Protoss_Gateway);
	}
	printf("X:%d Y:%d \n",setPos.x(),setPos.y());
	Selected_Worker = NULL;
	resourceSemaphore = false;
}
开发者ID:pedroneves,项目名称:bloodbath-and-beyond,代码行数:25,代码来源:MeuAgentePrincipal.cpp

示例7: calculate_walk_distances

 void calculate_walk_distances(const RectangleArray<bool>& read_map
                               , const BWAPI::Position& start
                               , int max_distance
                               , RectangleArray<int>& distance_map)
 {
     Heap<BWAPI::Position, int> heap(true);
     for (unsigned int x = 0;x < distance_map.getWidth();x++) {
         for (unsigned int y = 0;y < distance_map.getHeight();y++) {
             distance_map[x][y] = -1;
         }
     }
     heap.push(std::make_pair(start, 0));
     int sx = (int)start.x();
     int sy = (int)start.y();
     distance_map[sx][sy] = 0;
     while (!heap.empty()) {
         BWAPI::Position pos = heap.top().first;
         int distance = heap.top().second;
         heap.pop();
         int x = (int)pos.x();
         int y = (int)pos.y();
         if (distance > max_distance && max_distance > 0)
             break;
         int min_x = max(x - 1, 0);
         int max_x = min(x + 1, read_map.getWidth() - 1);
         int min_y = max(y - 1, 0);
         int max_y = min(y + 1, read_map.getHeight() - 1);
         for (int ix = min_x;ix <= max_x;ix++) {
             for (int iy = min_y;iy <= max_y;iy++) {
                 int f = abs(ix - x) * 10 + abs(iy - y) * 10;
                 if (f > 10) {
                     f = 14;
                 }
                 int v = distance + f;
                 if (distance_map[ix][iy] > v) {
                     heap.set(BWAPI::Position(x, y), v);
                     distance_map[ix][iy] = v;
                 } else {
                     if (distance_map[ix][iy] == -1 && read_map[ix][iy] == true) {
                         distance_map[ix][iy] = v;
                         heap.push(std::make_pair(BWAPI::Position(ix, iy), v));
                     }
                 }
             }
         }
     }
 }
开发者ID:krasi0,项目名称:bwapi-bwta-map-analyzer,代码行数:47,代码来源:util.cpp

示例8: moveFormation

void Fireteam::moveFormation(BWAPI::Position pos) {
	mission.objectivePosition = pos;
	for(std::set<BWAPI::Unit*>::const_iterator i=units.begin(); i != units.end(); i++)
	{	
		
		(*i)->move(BWAPI::Position::Position(pos.x() + (int)formation.positionMap[(*i)].xOffset, pos.y() + (int)formation.positionMap[(*i)].yOffset), 0);
	}
}
开发者ID:JonahBrooks,项目名称:ESCAIP,代码行数:8,代码来源:Fireteam.cpp

示例9: onNukeDetect

void BattleBroodAI::onNukeDetect(BWAPI::Position target)
{
	micro->onNukeDetect(target);
    if (target!=Positions::Unknown)
    	Broodwar->printf("Nuclear Launch Detected at (%d,%d)",target.x(),target.y());
    else
    	Broodwar->printf("Nuclear Launch Detected");
}
开发者ID:AIUR-group,项目名称:BroodwarBotQ,代码行数:8,代码来源:MacroProject.cpp

示例10: getSectorCornerPosition

BWAPI::Position getSectorCornerPosition (char s, int c){
	int width = centro.x()*2;
	int height = centro.y()*2;

	double C1 = width / 3;
	double C2 = (2*width) / 3;

	double L1 = height / 3;
	double L2 = (2*height) / 3;

	double halfSectorWidth = (C1 / 2);
	double halfSectorHeight = (L1 / 2);

	BWAPI::Position sectorCenter = getSectorCenter(s);

	if(c == 0) return BWAPI::Position((int) (sectorCenter.x() - halfSectorWidth), (int) (sectorCenter.y() - halfSectorHeight));
	if(c == 1) return BWAPI::Position((int) (sectorCenter.x() + halfSectorWidth), (int) (sectorCenter.y() - halfSectorHeight));
	if(c == 2) return BWAPI::Position((int) (sectorCenter.x() - halfSectorWidth), (int) (sectorCenter.y() + halfSectorHeight));
	if(c == 3) return BWAPI::Position((int) (sectorCenter.x() + halfSectorWidth), (int) (sectorCenter.y() + halfSectorHeight));
}
开发者ID:pedroneves,项目名称:bloodbath-and-beyond,代码行数:20,代码来源:MeuAgentePrincipal.cpp

示例11: nextSpiralPosition

BWAPI::Position nextSpiralPosition (Unidade* u, BWAPI::Position center){
	/*
		Faz o batedor andar em expiral, em torno da primeira unidade encontrada.

		Para cada volta, divide a circunferencia em quatro setores que serao para onde
		o batedor ira se mover. Se no final de uma volta, nao encontrar o centro de comando
		inicia mais uma volta porem dessa vez, com o raio maior em spiralRadiusDelta
	*/

	int spiralRadius = (spiralTurn*spiralRadiusDelta);

	if(distance(u->getPosition(), nextSpiralSectorPosition) > spiralGoalRadius){
		if(distance(u->getPosition(), nextSpiralSectorPosition) >= lastDistanceToNextSpiralSector){
			nextSpiralSectorReachTryAmount = nextSpiralSectorReachTryAmount + 1;
		}

		if(nextSpiralSectorReachTryAmount >= maxAmountTryReachSpiralGoalRadius){
			spiralSector = spiralSector + 1;
			nextSpiralSectorReachTryAmount = 0;
		}
	}else{
		nextSpiralSectorReachTryAmount = 0;
		spiralSector = spiralSector + 1;
	}

	if(spiralSector == 0){
		nextSpiralSectorPosition = BWAPI::Position(center.x(), (center.y() - spiralRadius));
	}else if(spiralSector == 1){
		nextSpiralSectorPosition = BWAPI::Position((center.x() + spiralRadius), center.y());
	}else if(spiralSector == 2){
		nextSpiralSectorPosition = BWAPI::Position(center.x(), (center.y() + spiralRadius));
	}else if(spiralSector == 3){
		nextSpiralSectorPosition = BWAPI::Position((center.x() - spiralRadius), center.y());

		// fim da volta. Incrementa a volta e reinicia o sector
		spiralTurn = spiralTurn + 1;
		spiralSector = -1;
	}

	return nextSpiralSectorPosition;
}
开发者ID:pedroneves,项目名称:bloodbath-and-beyond,代码行数:41,代码来源:MeuAgentePrincipal.cpp

示例12: 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;
 }
开发者ID:Nerfling,项目名称:bwta,代码行数:23,代码来源:BWTA.cpp

示例13: printGraphicDebugInfo

void PlayerSquad::printGraphicDebugInfo() const {
	// Skip if not turned on
	if (config::debug::GRAPHICS_VERBOSITY == config::debug::GraphicsVerbosity_Off || !isDebugOn())
	{
		return;
	}

	// Low
	// Print id, state, number of units and number of supplies.
	if (config::debug::GRAPHICS_VERBOSITY >= config::debug::GraphicsVerbosity_Low) {
		if (!mCenter.empty()) {
			BWAPI::Position squadCenterOnMap = BWAPI::Position(mCenter.front());

			BWAPI::Broodwar->drawTextMap(squadCenterOnMap.x(), squadCenterOnMap.y(), "%s", getDebugString().c_str());
		}
	}


	// Medium
	// Draw line from the front and back center, display the length of this line
	if (config::debug::GRAPHICS_VERBOSITY >= config::debug::GraphicsVerbosity_Medium) {
		if (!mCenter.empty()) {
			pair<Position, Position> squadMovement = make_pair(mCenter.front(), mCenter.back());

			// Length
			double length = (mCenter.front() - mCenter.back()).getLength();

			// Draw line
			Broodwar->drawLineMap(
				squadMovement.first.x(), squadMovement.first.y(),
				squadMovement.second.x(), squadMovement.second.y(),
				Colors::Purple
				);

			int xOffset = -64;

			// Draw text in back of line
			Broodwar->drawTextMap(
				squadMovement.second.x() + xOffset, squadMovement.second.y(),
				"%sLength: %g",
				TextColors::PURPLE.c_str(),
				length
				);

		}
	}
}
开发者ID:Senth,项目名称:bats,代码行数:47,代码来源:PlayerSquad.cpp

示例14: camera

	void AIModule::camera()
	{
		if (game->getMouseState(BWAPI::M_LEFT))
		{
			return;
		}

		const int CENTER_SCREEN_X = 320;
		const int CENTER_SCREEN_Y = 140;

		if (!autocam)
		{
			return;
		}

		UnitGroup interestingUnits = AllUnits()(isAttacking);

		if (interestingUnits.size() == 0)
		{
			return;
		}

		BWAPI::Unit *unit = (*interestingUnits.begin());

		BWAPI::Position unitPosition = unit->getPosition();

		int x, y;
		x = unitPosition.x() - CENTER_SCREEN_X;
		y = unitPosition.y() - CENTER_SCREEN_Y;

		if (x < 0)
		{
			x = 0;
		}

		if (y < 0)
		{
			y = 0;
		}

		BWAPI::Broodwar->setScreenPosition(x, y);
	}
开发者ID:albertouri,项目名称:dementor-bot,代码行数:42,代码来源:AIModule.cpp

示例15: RushDefend

void ProductionManager::RushDefend(BWAPI::UnitType defendBuilding, int buildingCount, BWAPI::UnitType defendUnit, int unitCount)
{
	BWAPI::Position chokePosition = BWTA::getNearestChokepoint(BWAPI::Broodwar->self()->getStartLocation())->getCenter();
	BWAPI::Position basePositon = BWAPI::Position(BWAPI::Broodwar->self()->getStartLocation());

	double2 direc = chokePosition - basePositon;
	double2 direcNormal = direc / direc.len();
	int targetx = (basePositon.x() + int(direcNormal.x * 32 * 10)) / 32;
	int targety = (basePositon.y() + int(direcNormal.y * 32 * 10)) / 32;

	for (int i = 0; i < unitCount; i++)
	{
		queue.queueAsHighestPriority(defendUnit, false);
	}

	for (int i = 0; i < buildingCount; i++)
	{
		queue.queueAsHighestPriority(MetaType(BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TilePosition(targetx, targety)), true);
		queue.queueAsHighestPriority(defendBuilding, false);
	}
}
开发者ID:bitisony,项目名称:Overkill,代码行数:21,代码来源:ProductionManager.cpp


注:本文中的bwapi::Position::x方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。