示例#1
0
// Finds minimal number of units in 'Extra' that add coverage to 'Initial'.
// We do it by actually executing the units, sometimes more than once,
// because we may be using different coverage-like signals and the only
// common thing between them is that we can say "this unit found new stuff".
UnitVector Fuzzer::FindExtraUnits(const UnitVector &Initial,
                                  const UnitVector &Extra) {
  UnitVector Res = Extra;
  size_t OldSize = Res.size();
  for (int Iter = 0; Iter < 10; Iter++) {
    ShuffleCorpus(&Res);
    ResetCoverage();

    for (auto &U : Initial)
      RunOne(U);

    Corpus.clear();
    for (auto &U : Res)
      if (RunOne(U))
        Corpus.push_back(U);

    char Stat[7] = "MIN   ";
    Stat[3] = '0' + Iter;
    PrintStats(Stat);

    size_t NewSize = Corpus.size();
    assert(NewSize <= OldSize);
    Res.swap(Corpus);

    if (NewSize + 5 >= OldSize)
      break;
    OldSize = NewSize;
  }
  return Res;
}
void BattlecruiserManagerExt::setAverageEnemyPosition(const UnitVector& targets)
{
	if (targets.empty())
	{
		return;
	}

	BWAPI::Position sumPos(0, 0);
	for (int i = 0; i < targets.size(); i++)
	{
		if (targets[i]->getPosition().isValid())
		{
			sumPos += targets[i]->getPosition();
		}
	}

	int xPos = (sumPos.x() / targets.size());
	int yPos = (sumPos.y() / targets.size());

	BWAPI::Position avgPos(xPos, yPos);
	_averageEnemyPosition = avgPos;

	if (!_averageEnemyPosition.isValid())
	{
		_averageEnemyPosition.makeValid();
	}
}
示例#3
0
void	Editor::renderLevel(View& Target)
{
	mWindow.setView(mWindow.getDefaultView());
	UnitVector Units = mLevel.getObjects();
	mWindow.setView(Target);
	for(int i=0;i<mLevel.getBackground().size();i++)
	{
		mWindow.draw(mLevel.getBackground()[i]->draw());
	}
	if(mLevel.ifPlayerExist())
	{
		mLevel.getPlayer()->draw(mWindow, false);
	}
	for(UnitVector::size_type i=0;i < Units.size();i++)
	{
		if(dynamic_cast<Laser*>(mLevel.getObjects()[i])!=0)
		{
			dynamic_cast<Laser*>(mLevel.getObjects()[i])->mLength=dynamic_cast<Laser*>(mLevel.getObjects()[i])->mMaxLength;
		}
		else if(dynamic_cast<DialogueBox*>(mLevel.getObjects()[i])!=0)
		{
			Uint8 alpha=200;
			if(dynamic_cast<DialogueBox*>(mLevel.getObjects()[i])->getVisible())
			{
				alpha=255;
			}
			dynamic_cast<DialogueBox*>(mLevel.getObjects()[i])->forceAlpha(alpha);
		}
		if(Units[i]!=mSelectedUnit.getObject())
		{
			mWindow.draw(Units[i]->getSprite());
		}
	}
	if(mSelectedUnit.isActive())
	{
		if(dynamic_cast<LaserHolder*>(mSelectedUnit.getObject())!=0)
		{
			dynamic_cast<LaserHolder*>(mSelectedUnit.getObject())->getLaser()->mLength=dynamic_cast<LaserHolder*>(mSelectedUnit.getObject())->getLaser()->getLength();
			mWindow.draw(dynamic_cast<LaserHolder*>(mSelectedUnit.getObject())->getLaser()->getSprite());
		}
		else if(dynamic_cast<DialogueBox*>(mSelectedUnit.getObject())!=0)
		{
			Uint8 alpha=255;
			if(dynamic_cast<DialogueBox*>(mSelectedUnit.getObject())->getFadeIn())
			{
				alpha=200;
			}
			dynamic_cast<DialogueBox*>(mSelectedUnit.getObject())->forceAlpha(alpha);
		}
		mWindow.draw(mSelectedUnit.getObject()->getSprite());		
	}
	if(mSelectedPlayer.isActive()&&mSelectedPlayer.getObject()!=mLevel.getPlayer())
	{
		mSelectedPlayer.getObject()->draw(mWindow, false);		
	}
	mWindow.setView(mWindow.getDefaultView());
}
void 
Squad::setAllUnits()
{
	// clean up the units vector just in case one of them died
	UnitVector goodUnits;
	BOOST_FOREACH(BWAPI::Unit * unit, units)
	{
		if( unit->isCompleted() && 
			unit->getHitPoints() > 0 && 
			unit->exists() &&
			unit->getPosition().isValid() &&
			unit->getType() != BWAPI::UnitTypes::Unknown)
		{
			goodUnits.push_back(unit);
		}
	}
	units = goodUnits;
}
void DragoonManager::executeMicro(const UnitVector & targets, BWAPI::Position regroup) 
{
	const UnitVector & dragoons = getUnits();

	// figure out targets
	UnitVector dragoonTargets;
	for (size_t i(0); i<targets.size(); i++) 
	{
		// conditions for targeting
		if (targets[i]->isVisible()) 
		{
			dragoonTargets.push_back(targets[i]);
		}
	}

	// for each zealot
	BOOST_FOREACH(BWAPI::Unit * dragoon, dragoons)
	{
		if (DRAW_UALBERTABOT_DEBUG) BWAPI::Broodwar->drawLineMap(dragoon->getPosition().x(), dragoon->getPosition().y(), 
			dragoon->getTargetPosition().x(), dragoon->getTargetPosition().y(), BWAPI::Colors::White);

		// regroup if we have to regroup and we're not near an enemy
		if (order.type == order.Attack && regroup != BWAPI::Position(0,0))// && !unitNearEnemy(dragoon))
		{
			if (DRAW_UALBERTABOT_DEBUG) BWAPI::Broodwar->drawCircleMap(dragoon->getPosition().x(), dragoon->getPosition().y(), 3, BWAPI::Colors::Orange, true);

			// if the zealot is outside the regroup area
			if (dragoon->getDistance(regroup) > 100)
			{
				// regroup it
				smartMove(dragoon, regroup);
			}
			else
			{
				smartAttackMove(dragoon, dragoon->getPosition());
			}
		}
		// otherwise this unit is not regrouping
		else
		{
			// if the order is to attack or defend
			if (order.type == order.Attack || order.type == order.Defend) {

				// if there are targets
				if (!dragoonTargets.empty())
				{
					// find the best target for this zealot
					BWAPI::Unit * target = getTarget(dragoon, dragoonTargets);
					// attack it
					smartAttackUnit(dragoon, target);
				}
				// if there are no targets
				else
				{
					// if we're not near the order position
					if (dragoon->getDistance(order.position) > 100)
					{
						// move to it
						smartAttackMove(dragoon, order.position);
					}
				}
			}
		}
	}
}
示例#6
0
void VultureManagerExt::executeMicro(const UnitVector & targets)
{
	const UnitVector & selectedUnits = getUnits();


	// figure out targets
	UnitVector selectedUnitTargets;
	UnitVector nearbyTargets;
	for (size_t i(0); i<targets.size(); i++)
	{
		// conditions for targeting
		if (targets[i]->isVisible()
			&& !targets[i]->getType().isFlyer())
		{
			selectedUnitTargets.push_back(targets[i]);
		}
	}

	//setAverageEnemyPosition(selectedUnitTargets);

	// For each unit
	BOOST_FOREACH(BWAPI::Unit * selectedUnit, selectedUnits)
	{
		// Avg enemy pos
		for (size_t i(0); i<targets.size(); i++)
		{
			// conditions for targeting
			if (targets[i]->isVisible()
				&& !targets[i]->getType().isFlyer())
			{
				if (targets[i]->getDistance(selectedUnit) < 500)
				{
					nearbyTargets.push_back(targets[i]);
				}
			}
		}

		if (!nearbyTargets.empty())
		{
			setAverageEnemyPosition(nearbyTargets);
		}
		else
		{
			setAverageEnemyPosition(selectedUnitTargets);
		}

		// eof avg eveeny pos
		// if the order is to attack or defend
		if ((StrategyManager::Instance().getCurrentStrategy() == StrategyManager::Instance().TerranWraithRush1Port)
			&& !isAttack())
		{
			executeTerranWraithRush1Port(selectedUnit, selectedUnitTargets);
		}
		else if (order.type == order.Attack || order.type == order.Defend)
		{
			// if there are targets
			if (!selectedUnitTargets.empty())
			{
				// find the best target for this Marine
				BWAPI::Unit * target = getTarget(selectedUnit, selectedUnitTargets);

				// attack it		
				kiteTarget(selectedUnit, target);


			}
			// if there are no targets
			else
			{
				// if we're not near the order position
				if (selectedUnit->getDistance(order.position) > 100)
				{
					// move to it
					smartAttackMove(selectedUnit, order.position);
				}
			}
		}

		if (Options::Debug::DRAW_UALBERTABOT_DEBUG)
		{
			BWAPI::Broodwar->drawLineMap(selectedUnit->getPosition().x(), selectedUnit->getPosition().y(),
				selectedUnit->getTargetPosition().x(), selectedUnit->getTargetPosition().y(), Options::Debug::COLOR_LINE_TARGET);
		}
	}

}
示例#7
0
void WraithManagerExt::executeMicro(const UnitVector & targets)
{
	const UnitVector & selectedUnits = getUnits();
	_noTurretTargetsNo = 0;

	// figure out targets
	UnitVector selectedUnitTargets;
	for (size_t i(0); i<targets.size(); i++)
	{
		// conditions for targeting
		if (targets[i]->isVisible())
		{
			selectedUnitTargets.push_back(targets[i]);

			if (!isTurret(targets[i]))
			{
				_noTurretTargetsNo++;
			}

		}
	}

	setAverageEnemyPosition(selectedUnitTargets);

	// For each unit
	BOOST_FOREACH(BWAPI::Unit * selectedUnit, selectedUnits)
	{
		// Adjust cloak to the situation
		manageCloak(selectedUnit, selectedUnitTargets);

		// if the order is to attack or defend
		if (order.type == order.Attack || order.type == order.Defend)
		{
			// if there are targets
			if (!selectedUnitTargets.empty())
			{
				// find the best target for this unit
				BWAPI::Unit * target = getTarget(selectedUnit, selectedUnitTargets);

				// attack it				
				kiteTarget(selectedUnit, target);

			}
			// if there are no targets
			else
			{
				// if we're not near the order position
				if (selectedUnit->getDistance(order.position) > 100)
				{
					// move to it	

					// Border movement
					BWAPI::Position movePosition;
					if (order.type == SquadOrder::Attack
						&& (StrategyManager::Instance().getCurrentStrategy() == StrategyManager::Instance().TerranWraithRush1Port))
					{
						movePosition = UnitManagerExt::Instance().getMovePosition(selectedUnit);
					}
					else
					{
						movePosition = order.position;
					}
					// eof Border movement
					if (!movePosition.isValid())
					{
						movePosition.makeValid();
					}

					smartAttackMove(selectedUnit, movePosition);
				}
			}
		}

		if (Options::Debug::DRAW_UALBERTABOT_DEBUG)
		{
			BWAPI::Broodwar->drawLineMap(selectedUnit->getPosition().x(), selectedUnit->getPosition().y(),
				selectedUnit->getTargetPosition().x(), selectedUnit->getTargetPosition().y(), Options::Debug::COLOR_LINE_TARGET);
		}
	}
示例#8
0
void RangedManager::executeMicro(const UnitVector & targets) 
{
	const UnitVector & rangedUnits = getUnits();

	// figure out targets
	UnitVector rangedUnitTargets;
	for (size_t i(0); i<targets.size(); i++) 
	{
		// conditions for targeting
		if (targets[i]->isVisible()) 
		{
			rangedUnitTargets.push_back(targets[i]);
		}
	}

	// for each zealot
	BOOST_FOREACH(BWAPI::Unit * rangedUnit, rangedUnits)
	{
		// train sub units such as scarabs or interceptors
		//trainSubUnits(rangedUnit);

		// if the order is to attack or defend
		if (order.type == order.Attack || order.type == order.Defend) {

			// if there are targets
			if (!rangedUnitTargets.empty())
			{
				

				// find the best target for this zealot
				BWAPI::Unit * target = getTarget(rangedUnit, rangedUnitTargets);

				/*
				if ( rangedUnit->getType().groundWeapon().maxRange() < target->getDistance(rangedUnit))
				{
					if(rangedUnit->getType() == BWAPI::UnitTypes::Zerg_Lurker)
					{
					//BWAPI::Broodwar->printf("############# Lurker in distance: %d ###############",  rangedUnit->getID());
					LurkerBurrow(rangedUnit);
					}
				}
				*/

				// attack it
				kiteTarget(rangedUnit, target);
			}
			// if there are no targets
			else
			{


				// if we're not near the order position
				if (rangedUnit->getDistance(order.position) > 100)
				{
					// move to it
					smartAttackMove(rangedUnit, order.position);
				}
			}
		}

		if (Options::Debug::DRAW_UALBERTABOT_DEBUG) 
		{
			BWAPI::Broodwar->drawLineMap(rangedUnit->getPosition().x(), rangedUnit->getPosition().y(), 
				rangedUnit->getTargetPosition().x(), rangedUnit->getTargetPosition().y(), Options::Debug::COLOR_LINE_TARGET);
		}
	}
}
示例#9
0
void RangedManager::executeMicro(const UnitVector & targets) 
{
	const UnitVector & rangedUnits = getUnits();

	// figure out targets
	UnitVector rangedUnitTargets;
	for (size_t i(0); i<targets.size(); i++) 
	{
		// conditions for targeting
		if (targets[i]->isVisible()) 
		{
			rangedUnitTargets.push_back(targets[i]);
		}
	}

	// for each zealot
	BOOST_FOREACH(BWAPI::Unit * rangedUnit, rangedUnits)
	{
		// train sub units such as scarabs or interceptors
		//trainSubUnits(rangedUnit);

		// if the order is to attack or defend
		if (order.type == order.Attack || order.type == order.Defend || order.type == order.Tanks || order.type == order.Vultures || order.type == order.Goliaths || order.type == order.Marines) {

			// if there are targets
			if (!rangedUnitTargets.empty())
			{
				// find the best target for this zealot
				BWAPI::Unit * target = getTarget(rangedUnit, rangedUnitTargets);

				// attack it
				if (!rangedUnit->getType() == BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode) {
					kiteTarget(rangedUnit, target);
				}
				else {
					smartPositionAndDefend(rangedUnit,order.position);
				}
			}
			// if there are no targets
			else
			{
				// if we're not in range of the position
				if (rangedUnit->getDistance(order.position) > rangedUnit->getInitialType().groundWeapon().maxRange())
				{
					//unsiege tanks if they're sieged
					if (rangedUnit->getType() == BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode) {
						rangedUnit->unsiege();
					}
					// move to it
					if (! (order.type == order.Defend)) {
						smartAttackMove(rangedUnit, order.position);
					}
					else {
						smartPositionAndDefend(rangedUnit,order.position);
					}
				}
				//else if we're in range and we're supposed to s
				else if (rangedUnit->getType() == BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode) {
					rangedUnit->siege();
				}
			}
		}

		if (Options::Debug::DRAW_UALBERTABOT_DEBUG) 
		{
			BWAPI::Broodwar->drawLineMap(rangedUnit->getPosition().x(), rangedUnit->getPosition().y(), 
				rangedUnit->getTargetPosition().x(), rangedUnit->getTargetPosition().y(), Options::Debug::COLOR_LINE_TARGET);
		}
	}
}