this.NumFriends = friends.size(); Iterator i = foes.iterator();   while(i.hasNext()) { CEntity centity = (CEntity)i.next();    }
this.NumFriends = friends.size();
  protected void preMovement() {    this.my_mechs_moved = 0;    this.old_moves = null;    this.enemies_moved = 0;    double max_modifier = 1.4;    Object[] entities = Compute.vectorToArray(game.getEntitiesVector());    double num_entities = Math.sqrt(entities.length)/100;    Vector friends = new Vector();    Vector foes = new Vector();    double friend_sum = 0;    double foe_sum = 0;    double max_foe_bv = 0;    for (int i = 0; i < entities.length; i++) {      Entity entity = (Entity)entities[i];      CEntity centity = this.enemies.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;        max_foe_bv = Math.max(new_value, max_foe_bv);        if (centity.strategy.target > 2) {          centity.strategy.target = 1 + .5*Math.pow((centity.strategy.target - 2),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;      }    }    this.NumFriends = friends.size();    Iterator i = foes.iterator();    //prefer to hit the most valuable mechs -- this was wrong    //when indifferent, not in general...     while(i.hasNext()) {      CEntity centity = (CEntity)i.next();      //double ratio = centity.bv*(centity.overall_armor_percent + 1)/max_foe_bv;      //centity.strategy.target = Math.max(1, .8*centity.strategy.target) + .2*ratio;      //System.out.println(centity.entity.getName() + " " + centity.strategy.target);    }        this.NumEnemies = foes.size();    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;    }    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.out.println(centity.strategy.attack);    }    System.gc(); //just to make sure  }