use of megamek.common.actions.WeaponAttackAction in project spoon by INRIA.
the class TestBot method calculateFiringTurn.
public void calculateFiringTurn() {
int first_entity = game.getFirstEntityNum();
int entity_num = first_entity;
int best_entity = first_entity;
double max = java.lang.Double.MIN_VALUE;
int[] results = null;
Vector winner = null;
int arc = 0;
if (entity_num == -1) {
return;
}
do {
Entity en = game.getEntity(entity_num);
CEntity cen = centities.get(en);
GAAttack test = bestAttack(cen.current, null, 3);
if (test != null && test.getFittestChromosomesFitness() > max) {
max = test.getFittestChromosomesFitness();
results = test.getResultChromosome();
arc = test.getFiringArc();
best_entity = entity_num;
winner = test.getAttack();
}
entity_num = game.getNextEntityNum(entity_num);
} while (entity_num != first_entity && entity_num != -1);
java.util.Vector av = new java.util.Vector();
// maximum already selected (or default)
Entity en = game.getEntity(best_entity);
if (results != null) {
Entity primary_target = (Entity) game.getEntitiesVector().elementAt(results[results.length - 1]);
TreeMap tm = new TreeMap(new AttackOption.Sorter(centities.get(primary_target)));
for (int i = 0; i < results.length - 1; i++) {
AttackOption a = (AttackOption) ((Vector) winner.elementAt(i)).elementAt(results[i]);
if (a.target != null) {
a.target.expected_damage[a.toHit.getSideTable()] += a.value;
a.target.hasTakenDamage = true;
tm.put(a, a);
}
}
Iterator i = tm.values().iterator();
while (i.hasNext()) {
AttackOption a = (AttackOption) i.next();
av.addElement(new WeaponAttackAction(en.getId(), a.target.getEntity().getId(), en.getEquipmentNum(a.weapon)));
}
}
switch(arc) {
case 1:
av.insertElementAt(new TorsoTwistAction(en.getId(), (en.getFacing() + 5) % 6), 0);
break;
case 2:
av.insertElementAt(new TorsoTwistAction(en.getId(), (en.getFacing() + 1) % 6), 0);
break;
}
sendAttackData(best_entity, av);
}
Aggregations