示例#1
0
	List<Command> AI.loop(List<Unit> tMyUnits, List<Unit> tEnemyUnits)
	{
		//resources = tResources;
		myUnits = tMyUnits;
		enemyUnits = tEnemyUnits;
		List<Command> commands = new List<Command> ();
		
		/*//spawn the counter whenever possible
		Command spawnc = new Command ();
		int spawnType = smartSpawn ();
		if (spawnType == 0) {
			if(resources > 119)
			{
				spawnc.addSpawn (2);
				commands.Add (spawnc);
			}
		} else {
			spawnc.addSpawn (spawnType);
			commands.Add (spawnc);
		}*/



		//run attack/move commands
		for (int i=1; i<myUnits.Count; i++) {
			//calculate the ideal enemy to attack


			//gets coordinates and attackRange of unit
			float attackRange = myUnits[i].getAttackRange();
			float tx = myUnits[i].getX ();
			float ty = myUnits[i].getY ();

			int maxScoreIndex = 0;
			float maxScore = -10000.0f;
			for(int j=0; j<enemyUnits.Count;j++)
			{
				float tScore = probabilityOfAttack(tx, ty, enemyUnits[j].getX (), enemyUnits[j].getY (), attackRange) 
							   *
							   rewardOfAttack(myUnits[i].getType(), enemyUnits[j].getType(), canAttack(i, j), enemyUnits[j].getHealth(), enemyUnits[j].getMaxHealth());

				if(tScore > maxScore)
				{
					maxScore = tScore;
					maxScoreIndex = j;
				}
			}
			Command tC = new Command();
			//check if ideal enemy is within range
			if(dist(tx, ty, enemyUnits[maxScoreIndex].getX (), enemyUnits[maxScoreIndex].getY ()) < attackRange)
			{
				//attack enemy
				tC.addAttack(myUnits[i].getID(), enemyUnits[maxScoreIndex].getID());

			}
			else
			{
				//move toward enemy
				tC.addMove(myUnits[i].getID(), getDirection(tx, ty, enemyUnits[maxScoreIndex].getX (), enemyUnits[maxScoreIndex].getY ())); 
			}

			commands.Add(tC);

		}


		return commands;
	}
示例#2
0
	List<Command> AI.loop(List<Unit> myUnits, List<Unit> enemyUnits)
	{
		List<Command> commands = new List<Command>();
		
		//spawn marines whenever possible
		/*Command spawnc = new Command();
		spawnc.addSpawn (3);
		commands.Add (spawnc);*/
		
		float dir = -1.5708f;
		if(myUnits[0].getY () - enemyUnits[0].getY () < 0)
		{
			dir = 1.5708f;
		}
		
		//handle all units
		for (int i=1; i<myUnits.Count; i++) {
			//gets coordinates and attackRange of unit
			float attackRange = myUnits[i].getAttackRange();
			float tx = myUnits[i].getX ();
			float ty = myUnits[i].getY ();
			bool attacked = false;
			for(int j=0; j<enemyUnits.Count;j++)
			{
				//check if enemy is within attack Rnage
				if(dist(tx,ty, enemyUnits[j].getX (), enemyUnits[j].getY ()) < attackRange)
				{
					if(enemyUnits[j].getIsGround())
					{
						if(!myUnits[i].getCanAttackGround())
						{
							continue;
						}
					}
					else
					{
						if(!myUnits[i].getCanAttackAir())
						{
							continue;
						}
					}
					//Sends attack command
					Command tAttack = new Command();
					tAttack.addAttack(myUnits[i].getID(), enemyUnits[j].getID());
					commands.Add (tAttack);
					attacked = true;
					break;
				}
			}
			
			if(!attacked)
			{
				//did not find someone to attack
				
				//move forward
				Command moveC = new Command();
				moveC.addMove(myUnits[i].getID(), getDirection(myUnits[i].getX (), myUnits[i].getY (), enemyUnits[0].getX(), enemyUnits[0].getY()));
				commands.Add (moveC);
			}
			
		}
		
		return commands;
	}