entity_num = game.getNextEntityNum(getLocalPlayer(), entity_num);
entity_num = game.getNextEntityNum(entity_num);
  public void calculateFiringTurn() {    int first_entity = game.getFirstEntityNum(getLocalPlayer());    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;    boolean infMoveLast = game.getOptions().booleanOption("inf_move_last");    boolean infMoveMulti = game.getOptions().booleanOption("inf_move_multi");        if (entity_num == -1) { return; }        do {      Entity en = game.getEntity(entity_num);      CEntity cen = this.enemies.get(en);            // Are we firing a non-Infantry entity in      // the middle of an Infantry block?      if ( infMoveMulti && (turnInfMoved % Game.INF_MOVE_MULTI) > 0 &&	   !(en instanceof Infantry) ) {	  // Does this player still have infantry to fire?	  if ( game.hasInfantry(this.local_pn) ) {	      // Yup.  Ignore this entity and check the next one.	      entity_num = game.getNextEntityNum(getLocalPlayer(), entity_num);	      continue;	  }	  else {	      // Nope.  Reset the infantry counter.	      turnInfMoved = 0;	  }      } // End check-inf_move_multi      //if (en.canFlipArms())  //more logic            int attacks[] = new int[3];      Vector front = new Vector();      Vector left = new Vector();      Vector right = new Vector();            int o_facing = en.getFacing();      for (Enumeration i = en.getWeapons();i.hasMoreElements();) {        Mounted mw = (Mounted)i.nextElement();        Vector c = this.calculateWeaponAttacks(en, mw);        if (c.size() > 0) {          front.add(c);          attacks[0] = Math.max(attacks[0], c.size());        }        en.setSecondaryFacing((o_facing + 5)%6);        c = this.calculateWeaponAttacks(en, mw);        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);        if (c.size() > 0) {          right.add(c);          attacks[2] = Math.max(attacks[2], c.size());        }        en.setSecondaryFacing(o_facing);      }      Vector arcs = new Vector();      arcs.add(front);      if (!cen.entity.isProne()){        arcs.add(left);        arcs.add(right);      }      for (int i = 0; i < arcs.size(); i++) {        Vector v = (Vector)arcs.elementAt(i);        if (v.size() > 0) {          try {            GAAttack test = new GAAttack(game, this.enemies.get(en), v, Math.max((v.size()+attacks[i])*4,50), 100, en.isEnemyOf((Entity)getEntitiesOwned().elementAt(0)));            Thread threadTest = new Thread(test);            threadTest.start();            threadTest.join();            if (test.getFittestChromosomesFitness() > max) {              max = test.getFittestChromosomesFitness();              results = test.getResultChromosome();              arc = i;              best_entity = entity_num;              winner = (Vector)arcs.elementAt(arc);            }          } catch (GAException gae) {            System.out.println(gae.getMessage());          } catch (Exception e) {            e.printStackTrace();          }        }      }      entity_num = game.getNextEntityNum(getLocalPlayer(), 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)(Compute.vectorToArray(game.getEntitiesVector())[results[results.length - 1]]);      TreeMap tm = new TreeMap(new TestBot.AttackOptionSorter(this.enemies.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);        }      }      com.sun.java.util.collections.Iterator i = tm.values().iterator();      while (i.hasNext()) {        AttackOption a = (AttackOption)i.next();        av.addElement(new WeaponAttackAction(en.getId(),a.target.entity.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;    }    //System.out.println(max);    sendAttackData(best_entity, av);  }