option.tv.add(max_threat + " Spec Threat " + e + "\n"); option.tv.add(max_damage + " Spec Damage " + e + "\n");
if(debug) { option.tv.add(max_threat + " Spec Threat " + e + "\n"); option.tv.add(max_damage + " Spec Damage " + e + "\n"); }
    private MoveOption[] fourthPass(CEntity self, ArrayList enemy_array) {        MoveOption[] move_array = self.pass.values().toArray(new MoveOption[0]);        self.pass.clear();        for (int e = 0; e < enemy_array.size(); e++) { // for each enemy            Entity en = (Entity) enemy_array.get(e);            CEntity enemy = centities.get(en);            //engage in speculation on "best choices" when you loose iniative            if (enemy.canMove()) {                Object[] enemy_move_array = enemy.pass.values().toArray();                ArrayList to_check = new ArrayList();                //check some enemy moves                for (int j = 0; j < move_array.length; j++) {                    MoveOption option = null;                    to_check.clear();                    option = move_array[j];                    option.setState();                    //check for damning hexes specifically                    //could also look at intervening defensive                    ArrayList coord = new ArrayList();                    Coords back = option.getFinalCoords().translated((option.getFinalFacing() + 3) % 6);                    coord.add(back);                    coord.add(back.translated((option.getFinalFacing() + 2) % 6));                    coord.add(back.translated((option.getFinalFacing() + 4) % 6));                    coord.add(option.getFinalCoords().translated((option.getFinalFacing())));                    coord.add(option.getFinalCoords().translated((option.getFinalFacing() + 1) % 6));                    coord.add(option.getFinalCoords().translated((option.getFinalFacing() + 2) % 6));                    coord.add(option.getFinalCoords().translated((option.getFinalFacing() + 4) % 6));                    coord.add(option.getFinalCoords().translated((option.getFinalFacing() + 5) % 6));                    Iterator ci = coord.iterator();                    while (ci.hasNext()) {                        Coords test = (Coords) ci.next();                        List c = enemy.findMoves(test);                        if (c.size() != 0)                            to_check.addAll(c);                    }                    int range = option.getFinalCoords().distance(enemy.current.getFinalCoords());                    int compare = 0;                    if ((enemy.long_range) > range - Math.max(enemy.jumpMP, enemy.runMP)) {                        compare = 30;                    } else if (enemy.long_range > range) {                        compare = 10;                    }                    double mod = this.enemies_moved / this.getEnemyEntities().size();                    compare *= (1 + mod);                    for (int k = 0; k <= compare && k < enemy_move_array.length; k++) {                        if (enemy_move_array.length < compare) {                            to_check.add(enemy_move_array[k]);                        } else {                            int value = Compute.randomInt(enemy_move_array.length);                            if (value % 2 == 1) {                                to_check.add(enemy_move_array[value]);                            } else {                                to_check.add(enemy_move_array[k]);                            }                        }                    }                    Iterator eo = to_check.iterator();                    while (eo.hasNext()) {                        MoveOption enemy_option = (MoveOption) eo.next();                        double max_threat = 0;                        double max_damage = 0;                        enemy_option.setState();                        int enemy_hit_arc =                                CEntity.getThreatHitArc(enemy_option.getFinalCoords(),                                        enemy_option.getFinalFacing(),                                        option.getFinalCoords());                        int self_hit_arc =                                CEntity.getThreatHitArc(enemy_option.getFinalCoords(),                                        enemy_option.getFinalFacing(),                                        option.getFinalCoords());                        if (enemy_option.isJumping()) {                            enemy_hit_arc = Compute.ARC_FORWARD;                        }                        int[] modifiers = option.getModifiers(enemy_option.getEntity());                        if (modifiers[1] != ToHitData.IMPOSSIBLE) {                            self.engaged = true;                            if (!enemy_option.isJumping()) {                                max_threat =                                        option.getMaxModifiedDamage(enemy_option,                                                modifiers[1],                                                modifiers[MoveOption.DEFENCE_PC]);                            } else {                                max_threat =                                        .8                                        * enemy.getModifiedDamage((modifiers[MoveOption.DEFENCE_PC] == 1) ? CEntity.TT : ToHitData.SIDE_FRONT,                                                enemy_option.getFinalCoords().distance(option.getFinalCoords()),                                                modifiers[1]);                            }                            max_threat = self.getThreatUtility(max_threat, self_hit_arc);                        }                        if (modifiers[0] != ToHitData.IMPOSSIBLE) {                            self.engaged = true;                            max_damage =                                    enemy_option.getMaxModifiedDamage(option,                                            modifiers[0],                                            modifiers[MoveOption.ATTACK_PC]);                            max_damage = enemy.getThreatUtility(max_damage, enemy_hit_arc);                            if (option.isPhysical) {                                if (centities.get(option.getPhysicalTargetId()).getEntity().getId()                                        == enemy.getEntity().getId()) {                                    max_damage = option.getDamage(enemy);                                } else {                                    max_damage = 0;                                }                            }                        }                        MoveOption.DamageInfo di = option.getDamageInfo(enemy, true);                        di.max_threat = Math.max(max_threat, di.max_threat);                        di.min_damage = Math.min(di.min_damage, max_damage);                        if (max_threat - max_damage > di.threat - di.damage) {                            di.threat = max_threat;                            di.damage = max_damage;                            option.tv.add(max_threat + " Spec Threat " + e + "\n");                            option.tv.add(max_damage + " Spec Damage " + e + "\n");                        }                    }                    //update estimates                    option.damage = 0;                    option.threat = 0;                    for (Iterator i = option.damageInfos.keySet().iterator(); i.hasNext();) {                        //my damage is the average of expected and min                        CEntity cen = (CEntity) i.next();                        //rescale                        MoveOption.DamageInfo di = option.getDamageInfo(cen, true);                        di.min_damage /= cen.strategy.target;                        di.damage /= cen.strategy.target;                        option.damage += (di.min_damage + di.damage) / 2;                        //my threat is average of absolute worst, and expected                        option.threat = Math.max(option.threat, di.max_threat + di.threat) / 2;                        di.threat = (di.max_threat + 2 * di.threat) / 3;                    }                }                //restore enemy                enemy.current.setState();            }            self.current.setState();        } //--end move speculation        return move_array;    }