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