⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testbot.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                            option.tv.add(option.getThreat(enemy) + " Revised Threat " + e + " \n");                        if (!option.isPhysical) {                            if (temp != null) {                                option.setDamage(enemy, (option.getDamage(enemy) + temp.getDamageUtility(enemy)) / 2);                            } else {                                //probably zero, but just in case                                option.setDamage(enemy, option.getMinDamage(enemy));                            }                            if(debug)                                option.tv.add(option.getDamage(enemy) + " Revised Damage " + e + " \n");                            //this needs to be reworked                            if (option.getFinalCoords().distance(enemy.current.getFinalCoords()) == 1) {                                PhysicalOption p =                                        PhysicalCalculator.getBestPhysicalAttack(option.getEntity(), enemy.getEntity(), game);                                if (p != null) {                                    option.setDamage(enemy, option.getDamage(enemy) + p.expectedDmg);                                    if(debug)                                        option.tv.add(p.expectedDmg + " Physical Damage " + e + " \n");                                }                                p = PhysicalCalculator.getBestPhysicalAttack(enemy.getEntity(), option.getEntity(), game);                                if (p != null) {                                    option.setThreat(enemy, option.getThreat(enemy) + .5 * p.expectedDmg);                                    if(debug)                                        option.tv.add(.5 * p.expectedDmg + " Physical Threat " + e + " \n");                                }                            }                        }                    } else if (!option.isPhysical) { //enemy can move (not                        if (temp != null) {                            option.setDamage(enemy, (2 * option.getDamage(enemy) + temp.getDamageUtility(enemy)) / 3);                        } else {                            option.setDamage(enemy, option.getMinDamage(enemy));                        }                    } else {                        //get a more accurate estimate                        option.setDamage(enemy,                                option.getDamage(enemy) / Math.sqrt((double) enemy.bv / (double) self.bv));                        option.damage = option.getDamage(enemy);                    }                }                option.threat = 0;                for (Iterator i = option.damageInfos.values().iterator(); i.hasNext();) {                    option.threat += ((MoveOption.DamageInfo) i.next()).threat;                }                if(debug) {                    option.tv.add(option.threat + " Revised Threat Utility\n");                    option.tv.add(option.damage + " Revised Damage Utility\n");                }            }        }        Arrays.sort(move_array, new MoveOption.WeightedComparator(1, 1));        self.current.setState();        return move_array;    }    private void filterMoves(Object[] move_array,                             MoveOption.Table pass,                             MoveOption.WeightedComparator comp,                             int filter) {        Arrays.sort(move_array, comp);        //top 100 utility, mostly conservative        for (int i = 0; i < filter && i < move_array.length; i++) {            pass.put((MoveOption) move_array[i]);        }    }    protected void initFiring() {        ArrayList entities = new ArrayList(game.getEntitiesVector());        for (int i = 0; i < entities.size(); i++) {            Entity entity = (Entity) entities.get(i);            CEntity centity = centities.get(entity);            centity.reset();            centity.enemy_num = i;        }        for (Iterator i = this.getEnemyEntities().iterator(); i.hasNext();) {            Entity entity = (Entity) i.next();            CEntity centity = centities.get(entity);            if (entity.isMakingDfa() || entity.isCharging()) {                //try to prevent a physical attack from happening                //but should take into account the toHit of the attack                centity.strategy.target = 2.5;            }        }    }    protected ArrayList calculateWeaponAttacks(Entity en, Mounted mw, boolean best_only) {        int from = en.getId();        int weaponID = en.getEquipmentNum(mw);        int spin_mode = 0;        int starg_mod;        ArrayList result = new ArrayList();        Enumeration ents = game.getValidTargets(en).elements();        WeaponAttackAction wep_test;        WeaponType spinner;        AttackOption a = null;        AttackOption max = new AttackOption(null, null, 0, null, 1);        while (ents.hasMoreElements()) {            Entity e = (Entity) ents.nextElement();            CEntity enemy = centities.get(e);//            long entry = System.currentTimeMillis();            ToHitData th = WeaponAttackAction.toHit(game, from, e, weaponID);//            long exit = System.currentTimeMillis();//            if (exit != entry)//                System.out.println("Weapon attack toHit took "+(exit-entry));            if (th.getValue() != ToHitData.IMPOSSIBLE && !(th.getValue() >= 13)) {                double expectedDmg;                wep_test = new WeaponAttackAction(from, e.getId(), weaponID);                // If this is an Ultra or Rotary cannon, check for spin up                spinner = (WeaponType) mw.getType();                if ((spinner.getAmmoType() == AmmoType.T_AC_ULTRA)                        || (spinner.getAmmoType() == AmmoType.T_AC_ULTRA_THB)                        || (spinner.getAmmoType() == AmmoType.T_AC_ROTARY)) {                    spin_mode = Compute.spinUpCannon(game, wep_test);                    super.sendModeChange(from, weaponID, spin_mode);                }                // Ammo cycler runs each valid ammo type through the weapon while                 // calling for expected damage on each type; best type by damage is loaded                expectedDmg = Compute.getAmmoAdjDamage(game, wep_test);                                // Get the secondary target modifier for this weapon/target combo                                starg_mod = 1;                                if (en.getFacing() != -1){                    if (en.canChangeSecondaryFacing()){                                                if (!Compute.isInArc(en.getPosition(), en.getSecondaryFacing(), e.getPosition(), Compute.ARC_FORWARD)){                            starg_mod = 2;                        }                    } else {                        if (!Compute.isInArc(en.getPosition(), en.getFacing(), e.getPosition(), Compute.ARC_FORWARD)){                            starg_mod = 2;                        }                                            }                }                                // If the attacker is Mech, it may mount a specialty targeting system                if (en instanceof Mech){                    // Multi-trac I/II have no secondary target penalties                    if (en.getTargSysType() == MiscType.T_TARGSYS_MULTI_TRAC |                             en.getTargSysType() == MiscType.T_TARGSYS_MULTI_TRAC_II){                        starg_mod = 0;                    }                }                                // For good measure, infantry cannot attack multiple targets                if (en instanceof Infantry){                    starg_mod = 13;                }                a = new AttackOption(enemy, mw, expectedDmg, th, starg_mod);                if (a.value > max.value) {                    if (best_only) {                        max = a;                    } else {                        result.add(0, a);                    }                } else {                    result.add(a);                }            }        }        if (best_only && max.target != null) {            result.add(max);        }        if (result.size() > 0) {            result.add(new AttackOption(null, mw, 0, null, 1));        }        return result;    }    public GAAttack bestAttack(MoveOption es) {        return bestAttack(es, null, 2);    }    public GAAttack bestAttack(MoveOption es, CEntity target, int search_level) {        Entity en = es.getEntity();        int attacks[] = new int[4];        ArrayList c = new ArrayList();        ArrayList front = new ArrayList();        ArrayList left = new ArrayList();        ArrayList right = new ArrayList();        ArrayList rear = new ArrayList();        GAAttack result = null;        int o_facing = en.getFacing();        double front_la_dmg = 0;        double front_ra_dmg = 0;        double left_la_dmg = 0;        double left_ra_dmg = 0;        double right_la_dmg = 0;        double right_ra_dmg = 0;        PhysicalOption best_front_po = new PhysicalOption(en);        PhysicalOption best_left_po = new PhysicalOption(en);        PhysicalOption best_right_po = new PhysicalOption(en);        // Get best physical attack        for (Mounted mw :en.getWeaponList()) {            // If this weapon is in the same arm as a            // brush off attack skip to next weapon.            c = this.calculateWeaponAttacks(en, mw, true);                   // Get best physical attack            best_front_po = PhysicalCalculator.getBestPhysical(en, game);            if ((best_front_po != null) && (en instanceof Mech)) {                // If this weapon is in the same arm as a brush off attack                // skip to next weapon                if (((best_front_po.type == PhysicalOption.BRUSH_LEFT) ||                        (best_front_po.type == PhysicalOption.BRUSH_BOTH)) &&                        (mw.getLocation() == Mech.LOC_LARM)) {                    continue;                }                if (((best_front_po.type == PhysicalOption.BRUSH_RIGHT) ||                        (best_front_po.type == PhysicalOption.BRUSH_BOTH)) &&                        (mw.getLocation() == Mech.LOC_RARM)) {                    continue;                }                // Total the damage of all weapons fired from each arm                if (((best_front_po.type == PhysicalOption.PUNCH_LEFT) ||                        (best_front_po.type == PhysicalOption.PUNCH_BOTH)) &&                        (mw.getLocation() == Mech.LOC_LARM)) {                    if (c.size() > 0) {                        front_la_dmg += ((AttackOption) c.get(c.size() - 2)).value;                    }                }                if (((best_front_po.type == PhysicalOption.PUNCH_RIGHT) ||                        (best_front_po.type == PhysicalOption.PUNCH_BOTH)) &&                        (mw.getLocation() == Mech.LOC_RARM)) {                    if (c.size() > 0) {                        front_ra_dmg += ((AttackOption) c.get(c.size() - 2)).value;                    }                }                // If this weapon is a push attack and an arm mounted                // weapon skip to next weapon                if ((best_front_po.type == PhysicalOption.PUSH_ATTACK) &&                        ((mw.getLocation() == Mech.LOC_LARM) ||                        (mw.getLocation() == Mech.LOC_RARM))) {                    continue;                }            }                        // If this weapon is in the same arm as a punch            // attack, add the damage to the running total.            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) {                    // Get best physical attack                    best_left_po = PhysicalCalculator.getBestPhysical(en, game);                    if ((best_left_po != null) && (en instanceof Mech)) {                        if (((best_left_po.type == PhysicalOption.PUNCH_LEFT) ||                                (best_left_po.type == PhysicalOption.PUNCH_BOTH)) &&                                (mw.getLocation() == Mech.LOC_LARM)) {                            left_la_dmg += ((AttackOption) c.get(c.size() - 2)).value;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -