Search in sources :

Example 1 with TreeMap

use of com.sun.java.util.collections.TreeMap 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);
}
Also used : Entity(megamek.common.Entity) TreeMap(com.sun.java.util.collections.TreeMap) WeaponAttackAction(megamek.common.actions.WeaponAttackAction) Iterator(com.sun.java.util.collections.Iterator) Vector(com.sun.java.util.collections.Vector) TorsoTwistAction(megamek.common.actions.TorsoTwistAction)

Aggregations

Iterator (com.sun.java.util.collections.Iterator)1 TreeMap (com.sun.java.util.collections.TreeMap)1 Vector (com.sun.java.util.collections.Vector)1 Entity (megamek.common.Entity)1 TorsoTwistAction (megamek.common.actions.TorsoTwistAction)1 WeaponAttackAction (megamek.common.actions.WeaponAttackAction)1