示例#1
0
 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));
                     }
                 }
             }
         }
     }
 }
示例#2
0
	// 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);
	}
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");
}
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;
}
示例#5
0
 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));
                     }
                 }
             }
         }
     }
 }
示例#6
0
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");
}
示例#7
0
	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());
		}
	}
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;
}
示例#9
0
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
				);

		}
	}
}
示例#10
0
	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);
	}
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));
}
示例#12
0
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);
	}
}
示例#13
0
void ExampleAIModule::onNukeDetect(BWAPI::Position target)
{

  // Check if the target is a valid position
  if ( target )
  {

    // if so, print the location of the nuclear strike target
    Broodwar->printf("Nuclear Launch Detected at (%d,%d)", target.x(), target.y() );

  }
  else 
  {

    // Otherwise, ask other players where the nuke is!
    Broodwar->sendText("Where's the nuke?");

  }

  // You can also retrieve all the nuclear missile targets using Broodwar->getNukeDots()!

}
BWAPI::Position getSectorCenter (char s){

	/*
		Dividindo o mapa em 9 setores:

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

		A funcao recebe um setor e retorna o ponto central do setor
	*/

	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);

	if(s == 'A') return BWAPI::Position((int) halfSectorWidth, (int) halfSectorHeight);
	if(s == 'B') return BWAPI::Position((int) (C1 + halfSectorWidth), (int) halfSectorHeight);
	if(s == 'C') return BWAPI::Position((int) (C2 + halfSectorWidth), (int) halfSectorHeight);
	if(s == 'K') return BWAPI::Position((int) halfSectorWidth, (int) (L1 + halfSectorHeight));
	if(s == 'L') return BWAPI::Position((int) (C1 + halfSectorWidth), (int) (L1 + halfSectorHeight));
	if(s == 'M') return BWAPI::Position((int) (C2 + halfSectorWidth), (int) (L1 + halfSectorHeight));
	if(s == 'X') return BWAPI::Position((int) halfSectorWidth, (int) (L2 + halfSectorHeight));
	if(s == 'Y') return BWAPI::Position((int) (C1 + halfSectorWidth), (int) (L2 + halfSectorHeight));
	if(s == 'Z') return BWAPI::Position((int) (C2 + halfSectorWidth), (int) (L2 + halfSectorHeight));
}
示例#15
0
// sets the starting states based on the combat units within a radius of a given position
// this center will most likely be the position of the forwardmost combat unit we control
void CombatSimulation::setCombatUnits(const BWAPI::Position & center, const int radius)
{
	MicroSearch::GameState s;
	s.setMaxUnits(100);

	BWAPI::Broodwar->drawCircleMap(center.x(), center.y(), 10, BWAPI::Colors::Red, true);

	std::vector<BWAPI::Unit *> ourCombatUnits;
	std::vector<UnitInfo> enemyCombatUnits;
	MapGrid::Instance().GetUnits(ourCombatUnits,   center, Options::Micro::COMBAT_REGROUP_RADIUS, true, false);
	InformationManager::Instance().getNearbyForce(enemyCombatUnits, center, BWAPI::Broodwar->enemy(), Options::Micro::COMBAT_REGROUP_RADIUS);


	int y = 0;

	BOOST_FOREACH (BWAPI::Unit * unit, ourCombatUnits)
	{
		if (InformationManager::Instance().isCombatUnit(unit->getType()))
		{
			s.addUnit(MicroSearch::Unit(unit, getPlayer(BWAPI::Broodwar->self()), BWAPI::Broodwar->getFrameCount()));
		}
	}

	y++;

	BOOST_FOREACH (UnitInfo ui, enemyCombatUnits)
	{
		if (!ui.type.isFlyer())
		{
			s.addUnit(getUnit(ui, getPlayer(BWAPI::Broodwar->enemy())));
		}
	}

	s.finishedMoving();

	state = s;
}
示例#16
0
文件: BWTA.cpp 项目: Nerfling/bwta
 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;
 }
int distance (BWAPI::Position p1, BWAPI::Position p2){
	return (int) sqrt(pow((double)(p1.x() - p2.x()), 2) + pow((double)(p1.y() - p2.y()), 2));
}
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';
}
示例#19
0
	Vector Vector::fromPositions(const BWAPI::Position &from, const BWAPI::Position &to) {
		return Vector(to.x() - from.x(), to.y() - from.y());
	}
示例#20
0
BWAPI::Position operator+(const BWAPI::Position &position, const dementor::Vector &vector) {
	return BWAPI::Position(position.x()+vector.getX(), position.y()+vector.getY());
}
示例#21
0
void ColorNode::setCenter(BWAPI::Position regionCenter)
{
	center = BWAPI::Position(regionCenter.x(), regionCenter.y());
	updateAge();
}
示例#22
0
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);
	}
}
示例#23
0
	int getIndex(const BWAPI::Position & p) const
	{
		return getIndex(p.y() / 32, p.x() / 32);
	}