当前位置: 首页>>代码示例>>C#>>正文


C# Command.addAttack方法代码示例

本文整理汇总了C#中Command.addAttack方法的典型用法代码示例。如果您正苦于以下问题:C# Command.addAttack方法的具体用法?C# Command.addAttack怎么用?C# Command.addAttack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Command的用法示例。


在下文中一共展示了Command.addAttack方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Command

	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;
	}
开发者ID:andykat,项目名称:AICraftv1.1,代码行数:68,代码来源:GreedyAndyAI.cs

示例2: Command

	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;
	}
开发者ID:andykat,项目名称:AICraftv1.1,代码行数:64,代码来源:DumbMarinesAI.cs


注:本文中的Command.addAttack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。