Пример #1
0
RenderableObject* Unit::GetClosestEnemy()
{
    std::vector<RenderableObject*> objectInVision = GetPercept();
    std::vector<RenderableObject*> enemyInVision;

    for(std::vector<RenderableObject*>::iterator it = objectInVision.begin(); it != objectInVision.end(); ++it) {
            RenderableObject* currentObject = *it;
            if (currentObject->GetPlayerID() != GetPlayerID() && !currentObject->IsDead()){
                enemyInVision.push_back(currentObject);
            }
    }

    if(!enemyInVision.empty()){

        RenderableObject* closesestUnit = enemyInVision[0];
        for(std::vector<RenderableObject*>::iterator it = enemyInVision.begin(); it != enemyInVision.end(); ++it) {
            RenderableObject* currentObject = *it;
            if (pow(currentObject->getX()- x,2) + pow(currentObject->getY()- y,2) <= pow(closesestUnit->getX()- x,2) + pow(closesestUnit->getY()- y,2)){
                closesestUnit = currentObject;
            }
        }

        return closesestUnit;
    }
    return NULL;
}
Пример #2
0
    void Environment::Step()
    {
      std::vector<Action *> actions(0);
      unsigned int i;
      for(i = 0; i < agents.size(); i++)
	{
	  Percept *percept = GetPercept(agents[i]);
	  Action  *action  = agents[i]->Program(percept);
	  if(action)
	    {
	      actions.push_back(action);
	    }
	  delete percept;
	}
      for(i = 0; i < agents.size(); i++)
	{
	  ApplyAction(agents[i], actions[i]);
	}
      for(i = 0; i < agents.size(); i++)
	{
	  delete actions[i];
	}
      for(i = 0; i < agents.size(); i++)
	{
	  CalculatePerformance(agents[i]);
	}
      UpdateDisplays();
    }