- ((Double) this.enemy_values.getLast()).doubleValue())) { if (Compute.randomInt(2) == 1) {
- ((Double) this.enemy_values.getLast()).doubleValue())) { if (Compute.randomInt(2) == 1) { centity.strategy.target += .3; }   } else if (friend_sum > .9 * foe_sum) { centity.strategy.target += .15;  } else if (centity.strategy.target < 2) {
    protected void initMovement() {        this.my_mechs_moved = 0;        this.old_moves = null;        this.enemies_moved = 0;        double max_modifier = 1.4;        java.util.Vector entities = game.getEntitiesVector();        double num_entities = Math.sqrt(entities.size()) / 100;        Vector friends = new Vector();        Vector foes = new Vector();        double friend_sum = 0;        double foe_sum = 0;        double max_foe_bv = 0;        CEntity max_foe = null;        for (int i = 0; i < entities.size(); i++) {            Entity entity = (Entity) entities.elementAt(i);            CEntity centity = centities.get(entity);            centity.enemy_num = i;            double old_value = centity.bv * (centity.overall_armor_percent + 1);            centity.reset(); //should get fresh values            double new_value = centity.bv * (centity.overall_armor_percent + 1);            double percent = 1 + (new_value - old_value) / old_value;            if (entity.getOwner().equals(getLocalPlayer())) {                friends.add(centity);                friend_sum += new_value;                if (percent < .85) {                    //small retreat                    centity.strategy.attack = .85;                } else if (percent < .95) {                    centity.strategy.attack = 1;                } else if (percent <= 1 && centity.strategy.attack < max_modifier) {                    if (percent == 1) {                        if (centity.strategy.attack < 1) {                            centity.strategy.attack = Math.min(1.4 * centity.strategy.attack, 1);                        } else {                            centity.strategy.attack *= (1.0 + num_entities);                        }                    } else {                        centity.strategy.attack *= (1.0 + 2 * num_entities);                    }                }            } else if (!entity.getOwner().isEnemyOf(getLocalPlayer())) {                friend_sum += new_value;            } else {                foes.add(centity);                foe_sum += new_value;                if (new_value > max_foe_bv) {                    max_foe_bv = new_value;                    max_foe = centity;                }                if (this.getEntitiesOwned().size() > 2) {                    if (centity.strategy.target > 2) {                        centity.strategy.target = 1 + .5 * (centity.strategy.target - 2);                    }                    if (percent < .85 && centity.strategy.target < max_modifier) {                        centity.strategy.target *= (1.0 + 6 * num_entities);                    } else if (percent < .95 && centity.strategy.target < max_modifier) {                        centity.strategy.target *= (1.0 + 4 * num_entities);                    } else if (percent <= 1) {                        if (percent == 1) {                            centity.strategy.target /= (1.0 + 2 * num_entities);                        } else {                            centity.strategy.target /= (1.0 + num_entities);                        }                    }                    //don't go below one                    if (centity.strategy.target < 1)                        centity.strategy.target = 1;                }            }        }        System.out.println("Us " + friend_sum + " Them " + foe_sum);        //do some more reasoning...        if (this.unit_values.size() == 0) {            this.unit_values.add(new Double(friend_sum));            this.enemy_values.add(new Double(foe_sum));            return;        }        Iterator i = foes.iterator();        if (friends.size() > 1) {            if (Strategy.MainTarget == null || null == game.getEntity(Strategy.MainTarget.getEntity().getId())) {                Strategy.MainTarget = max_foe;            }            Strategy.MainTarget.strategy.target += .2;            while (i.hasNext()) {                CEntity centity = (CEntity) i.next();                // good turn, keep up the work, but randomize to reduce                // predictability                if (friend_sum - foe_sum                    >= .9                        * (((Double) this.unit_values.getLast()).doubleValue()                            - ((Double) this.enemy_values.getLast()).doubleValue())) {                    if (Compute.randomInt(2) == 1) {                        centity.strategy.target += .3;                    }                    //lost that turn, but still in the fight, just get a                    // little more aggressive                } else if (friend_sum > .9 * foe_sum) {                    centity.strategy.target += .15;                    //lost that turn and loosing                } else if (centity.strategy.target < 2) { //go for the gusto                    centity.strategy.target += .3;                }                System.out.println(centity.getEntity().getShortName() + " " + centity.strategy.target);            }        }        double ratio = friend_sum / foe_sum;        double mod = 1;        if (ratio < .9) {            mod = .95;        } else if (ratio < 1) {            //no change        } else { //attack            mod = (1.0 + num_entities);        }        i = friends.iterator();        while (i.hasNext()) {            CEntity centity = (CEntity) i.next();            if (!(mod < 1 && centity.strategy.attack < .6) && !(mod > 1 && centity.strategy.attack >= max_modifier))                centity.strategy.attack *= mod;        }        System.gc(); //just to make sure    }