Search in sources :

Example 6 with Vector

use of com.sun.java.util.collections.Vector in project spoon by INRIA.

the class TestBot method bestAttack.

public GAAttack bestAttack(MoveOption es, CEntity target, int search_level) {
    Entity en = es.getEntity();
    int[] attacks = new int[3];
    Vector front = new Vector();
    Vector left = new Vector();
    Vector right = new Vector();
    GAAttack result = null;
    int o_facing = en.getFacing();
    for (Enumeration i = en.getWeapons(); i.hasMoreElements(); ) {
        Mounted mw = (Mounted) i.nextElement();
        Vector c = this.calculateWeaponAttacks(en, mw, true);
        if (c.size() > 0) {
            front.add(c);
            attacks[0] = Math.max(attacks[0], c.size());
        }
        if (!es.getFinalProne() && en.canChangeSecondaryFacing()) {
            en.setSecondaryFacing((o_facing + 5) % 6);
            c = this.calculateWeaponAttacks(en, mw, true);
            if (c.size() > 0) {
                left.add(c);
                attacks[1] = Math.max(attacks[1], c.size());
            }
            en.setSecondaryFacing((o_facing + 1) % 6);
            c = this.calculateWeaponAttacks(en, mw, true);
            if (c.size() > 0) {
                right.add(c);
                attacks[2] = Math.max(attacks[2], c.size());
            }
        } else {
            attacks[1] = 0;
            attacks[2] = 0;
        }
        en.setSecondaryFacing(o_facing);
    }
    Vector arcs = new Vector();
    arcs.add(front);
    if (!es.getFinalProne() && en.canChangeSecondaryFacing()) {
        arcs.add(left);
        arcs.add(right);
    }
    for (int i = 0; i < arcs.size(); i++) {
        Vector v = (Vector) arcs.elementAt(i);
        if (v.size() > 0) {
            GAAttack test = new GAAttack(this, centities.get(en), v, Math.max((v.size() + attacks[i]) * search_level, 20 * search_level), 30 * search_level, en.isEnemyOf((Entity) getEntitiesOwned().get(0)));
            test.setFiringArc(i);
            test.evolve();
            if (target != null) {
                if (result == null || test.getDamageUtility(target) > result.getDamageUtility(target)) {
                    result = test;
                }
            } else if (result == null || test.getFittestChromosomesFitness() > result.getFittestChromosomesFitness()) {
                result = test;
            }
        }
    }
    return result;
}
Also used : Entity(megamek.common.Entity) Enumeration(java.util.Enumeration) Mounted(megamek.common.Mounted) Vector(com.sun.java.util.collections.Vector)

Aggregations

Vector (com.sun.java.util.collections.Vector)6 Entity (megamek.common.Entity)6 Iterator (com.sun.java.util.collections.Iterator)4 Enumeration (java.util.Enumeration)4 ArrayList (com.sun.java.util.collections.ArrayList)1 LinkedList (com.sun.java.util.collections.LinkedList)1 List (com.sun.java.util.collections.List)1 TreeMap (com.sun.java.util.collections.TreeMap)1 Coords (megamek.common.Coords)1 Infantry (megamek.common.Infantry)1 Mounted (megamek.common.Mounted)1 ToHitData (megamek.common.ToHitData)1 WeaponType (megamek.common.WeaponType)1 TorsoTwistAction (megamek.common.actions.TorsoTwistAction)1 WeaponAttackAction (megamek.common.actions.WeaponAttackAction)1