예제 #1
0
void ExampleAIModule::onStart()
{
  // Hello World!
  Broodwar->sendText("Hello world!");

  // Print the map name.
  // BWAPI returns std::string when retrieving a string, don't forget to add .c_str() when printing!
  Broodwar << "The map is " << Broodwar->mapName() << "!" << std::endl;

  // Enable the UserInput flag, which allows us to control the bot and type messages.
  Broodwar->enableFlag(Flag::UserInput);

  // Uncomment the following line and the bot will know about everything through the fog of war (cheat).
  //Broodwar->enableFlag(Flag::CompleteMapInformation);

  // Set the command optimization level so that common commands can be grouped
  // and reduce the bot's APM (Actions Per Minute).
  Broodwar->setCommandOptimizationLevel(2);

  // Check if this is a replay
  if ( Broodwar->isReplay() )
  {

    // Announce the players in the replay
    Broodwar << "The following players are in this replay:" << std::endl;
    
    // Iterate all the players in the game using a std:: iterator
    Playerset players = Broodwar->getPlayers();
    for(auto p = players.begin(); p != players.end(); ++p)
    {
      // Only print the player if they are not an observer
      if ( !p->isObserver() )
        Broodwar << p->getName() << ", playing as " << p->getRace() << std::endl;
    }

  }
  else // if this is not a replay
  {
    // Retrieve you and your enemy's races. enemy() will just return the first enemy.
    // If you wish to deal with multiple enemies then you must use enemies().
    if ( Broodwar->enemy() ) // First make sure there is an enemy
      Broodwar << "The matchup is " << Broodwar->self()->getRace() << " vs " << Broodwar->enemy()->getRace() << std::endl;
  }

  // attempt to find a chokepoint
  BWAPI::Regionset Regions = Broodwar->getAllRegions();
  for(BWAPI::Regionset::iterator it = Regions.begin(); it != Regions.end() ; ++it)
  {
   
    if(it->getDefensePriority() == 2 && it->isHigherGround())
    {
      Broodwar << "Chokepoint region id: " << it->getRegionGroupID() << std::endl;
      //Broodwar->setScreenPosition(it->getCenter());
      //Broodwar->drawTextMap(it->getCenter(), "Choke");
      BWAPI::Position pos = it->getCenter();
      pos.x = pos.x +2; pos.y = pos.y -2;
      Broodwar->drawBoxMap(it->getCenter(), pos, Colors::Green);
    }
  }
}
예제 #2
0
파일: ForceImpl.cpp 프로젝트: oenayet/bwapi
 Playerset ForceImpl::getPlayers() const
 {
   Playerset players;
   for( int i = 0; i < 12; ++i )
     if ( BWAPI::BWAPIClient.data->players[i].force == id )
       players.insert( ((GameImpl*)Broodwar)->getPlayer(i) );
   return players;
 }
예제 #3
0
 Playerset ForceImpl::getPlayers() const
 {
   Playerset players;
   for (int i = 0; i < std::extent<decltype(BWAPI::BWAPIClient.data->players)>::value; ++i)
     if ( BWAPI::BWAPIClient.data->players[i].force == id )
       players.insert( Broodwar->getPlayer(i) );
   return players;
 }
예제 #4
0
void showForces()
{
  Forceset forces=Broodwar->getForces();
  for(Forceset::iterator i = forces.begin(); i != forces.end(); ++i)
  {
    Playerset players = i->getPlayers();
    Broodwar << "Force " << i->getName() << " has the following players:" << std::endl;
    for(Playerset::iterator j = players.begin(); j != players.end(); ++j)
      Broodwar << "  - Player [" << j->getID() << "]: " << j->getName() << std::endl;
  }
}
void ExampleAIModule::onStart()
{
  // Hello World!
  Broodwar->sendText("Hello world FerranBot!");

  // Print the map name.
  // BWAPI returns std::string when retrieving a string, don't forget to add .c_str() when printing!
  Broodwar << "The map is " << Broodwar->mapName() << "!" << std::endl;

  // Enable the UserInput flag, which allows us to control the bot and type messages.
  Broodwar->enableFlag(Flag::UserInput);

  // Uncomment the following line and the bot will know about everything through the fog of war (cheat).
  //Broodwar->enableFlag(Flag::CompleteMapInformation);

  // Set the command optimization level so that common commands can be grouped
  // and reduce the bot's APM (Actions Per Minute).
  Broodwar->setCommandOptimizationLevel(2);

  // Check if this is a replay
  if ( Broodwar->isReplay() )
  {

    // Announce the players in the replay
    Broodwar << "The following players are in this replay:" << std::endl;
    
    // Iterate all the players in the game using a std:: iterator
    Playerset players = Broodwar->getPlayers();
    for(auto p = players.begin(); p != players.end(); ++p)
    {
      // Only print the player if they are not an observer
      if ( !p->isObserver() )
        Broodwar << p->getName() << ", playing as " << p->getRace() << std::endl;
    }

  }
  else // if this is not a replay
  {
    // Retrieve you and your enemy's races. enemy() will just return the first enemy.
    // If you wish to deal with multiple enemies then you must use enemies().
    if ( Broodwar->enemy() ) // First make sure there is an enemy
      Broodwar << "The matchup is " << Broodwar->self()->getRace() << " vs " << Broodwar->enemy()->getRace() << std::endl;
  }

}
예제 #6
0
int main(int argc, const char* argv[])
{
  std::cout << "Connecting..." << std::endl;;
  reconnect();
  while(true)
  {
    std::cout << "waiting to enter match" << std::endl;
    while ( !Broodwar->isInGame() )
    {
      BWAPI::BWAPIClient.update();
      if (!BWAPI::BWAPIClient.isConnected())
      {
        std::cout << "Reconnecting..." << std::endl;;
        reconnect();
      }
    }
    std::cout << "starting match!" << std::endl;
    Broodwar->sendText("Hello world!");
    Broodwar << "The map is " << Broodwar->mapName() << ", a " << Broodwar->getStartLocations().size() << " player map" << std::endl;
    // Enable some cheat flags
    Broodwar->enableFlag(Flag::UserInput);
    // Uncomment to enable complete map information
    //Broodwar->enableFlag(Flag::CompleteMapInformation);
   
    show_bullets=false;
    show_visibility_data=false;

    if (Broodwar->isReplay())
    {
      Broodwar << "The following players are in this replay:" << std::endl;;
      Playerset players = Broodwar->getPlayers();
      for(Playerset::iterator p = players.begin(); p != players.end(); ++p )
      {
        if ( !p->getUnits().empty() && !p->isNeutral() )
          Broodwar << p->getName() << ", playing as " << p->getRace() << std::endl;
      }
    }
    else
    {
      Broodwar << "The match up is " << Broodwar->self()->getRace() << " vs " << Broodwar->enemy()->getRace() << std::endl;

      //send each worker to the mineral field that is closest to it
      Unitset units    = Broodwar->self()->getUnits();
      Unitset minerals  = Broodwar->getMinerals();
      for ( Unitset::iterator i = units.begin(); i != units.end(); ++i )
      {
        if ( i->getType().isWorker() )
        {
          Unit closestMineral = NULL;

          for( Unitset::iterator m = minerals.begin(); m != minerals.end(); ++m )
          {
            if ( !closestMineral || i->getDistance(*m) < i->getDistance(closestMineral))
              closestMineral = *m;
          }
          if ( closestMineral )
            i->rightClick(closestMineral);
        }
        else if ( i->getType().isResourceDepot() )
        {
          //if this is a center, tell it to build the appropiate type of worker
          i->train(Broodwar->self()->getRace().getWorker());
        }
      }
    }
    while(Broodwar->isInGame())
    {
      for(std::list<Event>::const_iterator e = Broodwar->getEvents().begin(); e != Broodwar->getEvents().end(); ++e)
      {
        switch(e->getType())
        {
          case EventType::MatchEnd:
            if (e->isWinner())
              Broodwar << "I won the game" << std::endl;
            else
              Broodwar << "I lost the game" << std::endl;
            break;
          case EventType::SendText:
            if (e->getText()=="/show bullets")
            {
              show_bullets=!show_bullets;
            } else if (e->getText()=="/show players")
            {
              showPlayers();
            } else if (e->getText()=="/show forces")
            {
              showForces();
            } else if (e->getText()=="/show visibility")
            {
              show_visibility_data=!show_visibility_data;
            } 
            else
            {
              Broodwar << "You typed \"" << e->getText() << "\"!" << std::endl;
            }
            break;
          case EventType::ReceiveText:
            Broodwar << e->getPlayer()->getName() << " said \"" << e->getText() << "\"" << std::endl;
            break;
          case EventType::PlayerLeft:
            Broodwar << e->getPlayer()->getName() << " left the game." << std::endl;
            break;
          case EventType::NukeDetect:
            if (e->getPosition()!=Positions::Unknown)
            {
              Broodwar->drawCircleMap(e->getPosition(), 40, Colors::Red, true);
              Broodwar << "Nuclear Launch Detected at " << e->getPosition() << std::endl;
            }
            else
              Broodwar << "Nuclear Launch Detected" << std::endl;
            break;
          case EventType::UnitCreate:
            if (!Broodwar->isReplay())
              Broodwar << "A " << e->getUnit()->getType() << " [" << e->getUnit() << "] has been created at " << e->getUnit()->getPosition() << std::endl;
            else
            {
              // if we are in a replay, then we will print out the build order
              // (just of the buildings, not the units).
              if (e->getUnit()->getType().isBuilding() && e->getUnit()->getPlayer()->isNeutral()==false)
              {
                int seconds=Broodwar->getFrameCount()/24;
                int minutes=seconds/60;
                seconds%=60;
                Broodwar->sendText("%.2d:%.2d: %s creates a %s", minutes, seconds, e->getUnit()->getPlayer()->getName().c_str(), e->getUnit()->getType().c_str());
              }
            }
            break;
          case EventType::UnitDestroy:
            if (!Broodwar->isReplay())
              Broodwar->sendText("A %s [%x] has been destroyed at (%d,%d)",e->getUnit()->getType().c_str(), e->getUnit(), e->getUnit()->getPosition().x, e->getUnit()->getPosition().y);
            break;
          case EventType::UnitMorph:
            if (!Broodwar->isReplay())
              Broodwar->sendText("A %s [%x] has been morphed at (%d,%d)",e->getUnit()->getType().c_str(), e->getUnit(), e->getUnit()->getPosition().x, e->getUnit()->getPosition().y);
            else
            {
              // if we are in a replay, then we will print out the build order
              // (just of the buildings, not the units).
              if (e->getUnit()->getType().isBuilding() && e->getUnit()->getPlayer()->isNeutral()==false)
              {
                int seconds=Broodwar->getFrameCount()/24;
                int minutes=seconds/60;
                seconds%=60;
                Broodwar->sendText("%.2d:%.2d: %s morphs a %s" ,minutes, seconds, e->getUnit()->getPlayer()->getName().c_str(), e->getUnit()->getType().c_str());
              }
            }
            break;
          case EventType::UnitShow:
            if (!Broodwar->isReplay())
              Broodwar->sendText("A %s [%x] has been spotted at (%d,%d)", e->getUnit()->getType().c_str(), e->getUnit(), e->getUnit()->getPosition().x, e->getUnit()->getPosition().y);
            break;
          case EventType::UnitHide:
            if (!Broodwar->isReplay())
              Broodwar->sendText("A %s [%x] was last seen at (%d,%d)", e->getUnit()->getType().c_str(), e->getUnit(), e->getUnit()->getPosition().x, e->getUnit()->getPosition().y);
            break;
          case EventType::UnitRenegade:
            if (!Broodwar->isReplay())
              Broodwar->sendText("A %s [%x] is now owned by %s", e->getUnit()->getType().c_str(), e->getUnit(), e->getUnit()->getPlayer()->getName().c_str());
            break;
          case EventType::SaveGame:
            Broodwar->sendText("The game was saved to \"%s\".", e->getText().c_str());
            break;
        }
      }

      if (show_bullets)
        drawBullets();

      if (show_visibility_data)
        drawVisibilityData();

      drawStats();
      Broodwar->drawTextScreen(300,0,"FPS: %f",Broodwar->getAverageFPS());

      BWAPI::BWAPIClient.update();
      if (!BWAPI::BWAPIClient.isConnected())
      {
        std::cout << "Reconnecting..." << std::endl;
        reconnect();
      }
    }
    std::cout << "Game ended" << std::endl;
  }
  std::cout << "Press ENTER to continue..." << std::endl;
  std::cin.ignore();
  return 0;
}
예제 #7
0
void showPlayers()
{
  Playerset players = Broodwar->getPlayers();
  for(Playerset::iterator i = players.begin(); i != players.end(); ++i)
    Broodwar << "Player [" << i->getID() << "]: " << i->getName() << " is in force: " << i->getForce()->getName() << std::endl;
}
void FerranBotAIModule::onStart()
{
#if defined(DEBUG)
	int bwapi_rev = BWAPI_getRevision();
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
	//assert(_CrtCheckMemory());

	// Hello World!
	Broodwar->sendText("Hello world FerranBot!");
	
	// Print the map name.
	// BWAPI returns std::string when retrieving a string, don't forget to add .c_str() when printing!
	Broodwar << "The map is " << Broodwar->mapName() << "!" << std::endl;

	// Enable the UserInput flag, which allows us to control the bot and type messages.
	Broodwar->enableFlag(Flag::UserInput);

	// Uncomment the following line and the bot will know about everything through the fog of war (cheat).
	//Broodwar->enableFlag(Flag::CompleteMapInformation);

	// Set the command optimization level so that common commands can be grouped
	// and reduce the bot's APM (Actions Per Minute).
	Broodwar->setCommandOptimizationLevel(2);

	// Check if this is a replay
	if ( Broodwar->isReplay() )
	{

		// Announce the players in the replay
		Broodwar << "The following players are in this replay:" << std::endl;
		
		// Iterate all the players in the game using a std:: iterator
		Playerset players = Broodwar->getPlayers();
		for(auto p = players.begin(); p != players.end(); ++p)
		{
			// Only print the player if they are not an observer
			if ( !p->isObserver() )
				Broodwar << p->getName() << ", playing as " << p->getRace() << std::endl;
		}

	}
	else // if this is not a replay
	{
		// Retrieve you and your enemy's races. enemy() will just return the first enemy.
		// If you wish to deal with multiple enemies then you must use enemies().
		if ( Broodwar->enemy() ) // First make sure there is an enemy
			Broodwar << "The matchup is " << Broodwar->self()->getRace() << " vs " << Broodwar->enemy()->getRace() << std::endl;
	}
	//assert(_CrtCheckMemory());

	//m_unitManager = UnitManager::getInstance();
	//assert(_CrtCheckMemory());
	UnitManager::getInstance();

	//m_squadManager = SquadManager::getInstance();
	////assert(_CrtCheckMemory());
	SquadManager::getInstance()->addSquad(new SquadEntity());
	////assert(_CrtCheckMemory());
	SquadManager::getInstance()->getSquads()->at(0)->addUnits(Broodwar->self()->getUnits());
	////assert(_CrtCheckMemory());
	SquadManager::getInstance()->addEnemySquad(new SquadEntity());

	//m_qLearningMgr = QLearningMgr::getInstance();
	////assert(_CrtCheckMemory());
	QLearningMgr::getInstance()->readFromStream();
}
예제 #9
0
/**
  * Create new Tasks for each enemy units not covered by attack tasks
  * Cleans up attack tasks whose targets are not in position anymore
  * AttackTasks are added at onUnitDiscover()
  */
void ExampleAIModule::updateAttack(){
	//traverse the task list to check if positions are visible and still have enemies
	vector<Task>* preserved = new vector<Task>(); //stores the tasks that should not be removed
	UnitType marineType = UnitTypes::Terran_Marine;

	//Broodwar->drawTextScreen(200,120,"marine seek: %d // sight: %d", marineType.seekRange(), marineType.sightRange());
	
	for(auto task = allTasks[Attack]->begin(); task != allTasks[Attack]->end(); task++){

		if(Broodwar->isVisible(task->getPosition().x / TILE_SIZE , task->getPosition().y / TILE_SIZE)){
			Unitset inRange = Broodwar->getUnitsInRadius(task->getPosition(),  marineType.groundWeapon().maxRange(), Filter::IsEnemy);
			//Broodwar->sendText("%d in range of attack task.", inRange.size());
			
			// Check if the unit can be reached by the marines
			// Sometimes cloacked or burrowed units can be marked as enemy but it cannot be attacked
			bool onlyCloackedUnits = true;
			for(auto u = inRange.begin(); u != inRange.end(); ++u) {
				if(!u->isCloaked() && !u->isBurrowed() & !u->isInvincible()){
					onlyCloackedUnits = false;
					break;
				}
			}
			if (inRange.size() == 0 || onlyCloackedUnits) {
				Broodwar->sendText("Attack task removed");
				//toDelete.push_back(*task);
			}
			else {
				preserved->push_back(*task);
			}

		}
		else { //keeps invisible attack targets, so that they can be investigated
			preserved->push_back(*task);
		}
	}
	

	//brings preserved tasks to the main task vector
	allTasks[Attack]->swap(*preserved);
	delete preserved; //hope this doesn't invalidates tasks...
	//in this point, tasks whose targets are not visible were removed

	// --- Now, adds new tasks for enemy units not covered by existent attack tasks ---

	//obtains a list with all enemies from all players
	Playerset foes = Broodwar->enemies();
	Unitset enemyUnits;
	enemyUnits.clear();

	for(auto foe = foes.begin(); foe != foes.end(); ++foe){
		enemyUnits += foe->getUnits();
	}

	//Broodwar->drawTextScreen(250,45, "#foes: %d", enemyUnits.size());

	//adds a task with a position for every enemy unit in the task list
	for(auto foeUnit = enemyUnits.begin(); foeUnit != enemyUnits.end(); ++foeUnit) {
		bool inRange = false;

		//tests if unit is already included in the area of another 'attack' task
		for(auto task = allTasks[Attack]->begin(); task != allTasks[Attack]->end(); task++){
			//task->
			//foeUnit->getType().groundWeapon().maxRange();
			//PositionTask* atk = static_cast<PositionTask* >( &(*task)) ; 
			if(foeUnit->getDistance(task->getPosition()) < marineType.groundWeapon().maxRange()){
				inRange = true;
				break;
			}
		}

		// Hector : extra validation to ignore unreachable targets
		//TODO: test is reachable 
		Position foePos = foeUnit->getPosition();
		if(! inRange && !foeUnit->isCloaked() && !foeUnit->isBurrowed() && !foeUnit->isInvincible() && Broodwar->isWalkable(foePos.x / 8, foePos.y / 8)){
			Task* atk = new Task(Attack, .8f, foeUnit->getPosition());
			allTasks[Attack]->push_back(*atk);
			//Broodwar->sendText("Attack task added, pos=%d,%d // %d,%d ", unit->getPosition().x, unit->getPosition().y, atk->getPosition().x, atk->getPosition().y);
		}
	}

	/*
	//if unit is enemy, adds it to 'attack' task list, if it isn't in range of an attack task
	//it seems that it works only for buildings... must check for mobile enemy units
	if(unit->getPlayer() != Broodwar->self() && unit->getPlayer() != Broodwar->neutral()){ 
		bool inRange = false;

		//tests if unit is already included in the area of another 'attack' task
		for(auto task = allTasks[Attack]->begin(); task != allTasks[Attack]->end(); task++){
			//task->

			//PositionTask* atk = static_cast<PositionTask* >( &(*task)) ; 
			if(unit->getDistance(task->getPosition()) < 6*TILE_SIZE){
				inRange = true;
				break;
			}
		}

		if(! inRange){
			Task* atk = new Task(Attack, .8f, unit->getPosition());
			allTasks[Attack]->push_back(*atk);
			Broodwar->sendText("Attack task added, pos=%d,%d // %d,%d ", unit->getPosition().x, unit->getPosition().y, atk->getPosition().x, atk->getPosition().y);

			for(auto task = allTasks[Attack]->begin(); task != allTasks[Attack]->end(); task++){
				//PositionTask* atk = static_cast<PositionTask* >( &(*task)) ; 
				Broodwar->sendText("pos=%d,%d", task->getPosition().x, task->getPosition().y);
			}
		}

	}
	*/
}
예제 #10
0
void ExampleAIModule::onStart() {
	// Hello World!
	Broodwar->sendText("TerranSwarm is online!");

	// Print the map name.
	// BWAPI returns std::string when retrieving a string, don't forget to add .c_str() when printing!
	Broodwar << "The map is " << Broodwar->mapName() << "!" << std::endl;
	
  
	// Enable the UserInput flag, which allows us to control the bot and type messages.
	Broodwar->enableFlag(Flag::UserInput);

	// Uncomment the following line and the bot will know about everything through the fog of war (cheat).
	//Broodwar->enableFlag(Flag::CompleteMapInformation);

	// Set the command optimization level so that common commands can be grouped
	// and reduce the bot's APM (Actions Per Minute).
	Broodwar->setCommandOptimizationLevel(2);

	Broodwar->setGUI(false); //disables gui drawing (better performance?)
	Broodwar->setLocalSpeed(0); //fastest speed, rock on!

	// Check if this is a replay
	if ( Broodwar->isReplay() ) {

		// Announce the players in the replay
		Broodwar << "The following players are in this replay:" << std::endl;
    
		// Iterate all the players in the game using a std:: iterator
		Playerset players = Broodwar->getPlayers();
		for(auto p = players.begin(); p != players.end(); ++p) {
		  // Only print the player if they are not an observer
		  if ( !p->isObserver() )
			Broodwar << p->getName() << ", playing as " << p->getRace() << std::endl;
		}
	}
	else {// if this is not a replay
  
		//Broodwar->sendText("show me the money");
		//Broodwar->sendText("operation cwal");

		// Retrieve you and your enemy's races. enemy() will just return the first enemy.
		// If you wish to deal with multiple enemies then you must use enemies().
		if ( Broodwar->enemy() ) // First make sure there is an enemy
			Broodwar << "The matchup is " << Broodwar->self()->getRace() << " vs " << Broodwar->enemy()->getRace() << std::endl;
		
		//cleans the list of command centers
		commandCenters.clear();

		//clears the list of discovered minerals
		discoveredMineralPositions.clear();
		
		//initializes the map of task lists
		//tasks are grouped by taskType
		//insert all TaskTypes into map; all Types will point to empty list
		for(int tt = TrainMarine; tt != GuardBase; ++tt){
			allTasks[static_cast<TaskType>(tt)] = new vector<Task>;
		}

		//TaskTypes with single task instance will point to list with the instance
		//TaskTypes with multiple instances will remain pointing to empty list (will be fulfilled on demand)
		allTasks[TrainMarine]->push_back(Task(TrainMarine, .8f)); 
		allTasks[GatherMinerals]->push_back(Task(GatherMinerals, .6f));
		allTasks[BuildSupplyDepot]->push_back(Task(BuildSupplyDepot, 0));
		allTasks[Explore]->push_back(Task(Explore, 0));
		allTasks[BuildCommandCenter]->push_back(Task(BuildCommandCenter, 0));

		//retrieves the single-instance tasks and stores them in pointers for easier remembering
		trainMarine = &allTasks[TrainMarine]->at(0);
		gatherMinerals = &allTasks[GatherMinerals]->at(0);
		buildCommandCenter = &allTasks[BuildCommandCenter]->at(0);
		buildSupplyDepot = &allTasks[BuildSupplyDepot]->at(0);
		explore = &allTasks[Explore]->at(0);

	}

	// Create the main agents
	_commanderAgent = new CommanderAgent();
	//scvMap = new unordered_map<int, SCVAgent*>;
}
예제 #11
0
void ExampleAIModule::onFrame() {
	//TODO: set rally point of barracks to the nearest command center
	// Called once every game frame
	// Return if the game is paused
	if ( Broodwar->isPaused() )// || !Broodwar->self() )
		return;

	if (Broodwar->isReplay()){

		Playerset plrs = Broodwar->getPlayers();
		Playerset::iterator plr;

		Broodwar->drawTextScreen(290, 20, "Time: ~ %dh%dm%ds", Broodwar->elapsedTime() / 3600, Broodwar->elapsedTime() / 60, Broodwar->elapsedTime() % 60);
		
		int pCount = 1;
		for (plr = plrs.begin(); plr != plrs.end(); plr++, pCount++){
			Broodwar->drawTextScreen(290, 20 + (20 * pCount), "Score p%d - Unit, Building, Resource = %d, %d, %d ", pCount, plr->getUnitScore(), plr->getBuildingScore(), plr->gatheredMinerals() + plr->gatheredGas());
		}
		return;
	}

	_drawStats();

	// Draw bullets
	/*Bulletset bullets = Broodwar->getBullets();
	for(Bulletset::iterator i = bullets.begin(); i != bullets.end(); ++i){
		Position p = i->getPosition();
		double velocityX = i->getVelocityX();
		double velocityY = i->getVelocityY();
		Broodwar->drawLineMap(p, p + Position((int)velocityX, (int)velocityY), i->getPlayer() == Broodwar->self() ? Colors::Green : Colors::Red);
		//Broodwar->drawTextMap(p, "%c%s", i->getPlayer() == Broodwar->self() ? Text::Green : Text::Red, i->getType().c_str());
	}*/

	// Prevent spamming by only running our onFrame once every number of latency frames.
	// Latency frames are the number of frames before commands are processed.
	if ( Broodwar->getFrameCount() % Broodwar->getLatencyFrames() != 0 )
		return;

	// reinsert tasks to prevent errors
	if(allTasks[BuildCommandCenter]->size() <= 0){
		allTasks[BuildCommandCenter]->push_back(Task(BuildCommandCenter, 0));
		buildCommandCenter = &allTasks[BuildCommandCenter]->at(0);
	}
	if(allTasks[BuildSupplyDepot]->size() <= 0){
		allTasks[BuildSupplyDepot]->push_back(Task(BuildSupplyDepot, 0));
		buildSupplyDepot = &allTasks[BuildSupplyDepot]->at(0);
	}
	if(allTasks[Explore]->size() <= 0){
		allTasks[Explore]->push_back(Task(Explore, 0));
		explore = &allTasks[Explore]->at(0);
	}
	
	//sets all rally points of barracks to the nearest command center
	for(auto c = commandCenters.begin(); c != commandCenters.end(); c++){
		Unitset brk = c->getUnitsInRadius(BASE_RADIUS, Filter::IsOwned);

		for (auto b = brk.begin(); b != brk.end(); b++){
			if(b->getType() != UnitTypes::Terran_Barracks || !b->isCompleted()){
				continue;
			}
			b->setRallyPoint(*c);
		}

	}

	//gives up the construction of buildings about to be destroyed
	Unitset all = Broodwar->self()->getUnits();
	for(auto b = all.begin(); b != all.end(); b++){
		//cancels construction if building is incomplete, is under attack and its hit points are low
		if (b->getType().isBuilding() && !b->isCompleted() && b->isUnderAttack() && b->getHitPoints() < .15f * b->getType().maxHitPoints()){
			b->cancelConstruction();
			//Broodwar << "construction canceled" << endl;
		}
	}


	updateTasks();

	_commanderAgent->onFrame(allTasks, trainSCVIncentives);

	//iterates through all marines
	for(auto marine = marines.begin(); marine != marines.end(); marine++){
		marine->second->onFrame(allTasks, marines);
	}

	// Iterate through all the SCV on the map
	unordered_map<int, SCVAgent*>::iterator it = scvMap.begin();
	for(unordered_map<int, SCVAgent*>::iterator iter = scvMap.begin(); iter != scvMap.end(); ++iter){
		int unitId =  iter->first;
		SCVAgent* agent = iter->second;
		Unit u = agent->getUnit();

		agent->onFrame(&allTasks, discoveredMineralPositions, commandCenters, scvMap);

		//Broodwar->drawTextMap(u->getPosition().x, u->getPosition().y, "agentId[%d]", unitId);

		/*if ( u->isLockedDown() || u->isMaelstrommed() || u->isStasised() )
			continue;
		
		if ( u->isIdle() ) {
			// Order workers carrying a resource to return them to the center,
			// otherwise find a mineral patch to harvest.
			if ( u->isCarryingGas() || u->isCarryingMinerals() ) {
				u->returnCargo();
			}
			else if ( !u->getPowerUp() ) { // The worker cannot harvest anything if it
											 // is carrying a powerup such as a flag
					// Harvest from the nearest mineral patch or gas refinery
				if ( !u->gather( u->getClosestUnit( IsMineralField || IsRefinery )) ) {
					// If the call fails, then print the last error message
					Broodwar << Broodwar->getLastError() << std::endl;
				}

			} // closure: has no powerup
		} // closure: if idle
		*/
	}
	
	/*Broodwar->drawTextScreen(20, 90 + yOffset, "Number of SCV in map [%d]", 
		Text::White, scvMap->size()
	);*/
}