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

📄 gaattack.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        int capacity = attacker.entity.getHeatCapacityWithWater();        int currentHeat = attacker.entity.heatBuildup + attacker.entity.heat;        int overheat = currentHeat + heat_total - capacity;        // Don't forget heat from stealth armor...        if (attacker.entity instanceof Mech && ((Mech) attacker.entity).isStealthActive()){            overheat += 10;        }        // ... or infernos...        if (attacker.entity.infernos.isStillBurning()){            overheat += 6;        }        //... or standing in fire...        if (game.getBoard().getHex(attacker.entity.getPosition()) != null){            if (game.getBoard().getHex(attacker.entity.getPosition()).                    terrainLevel(Terrains.FIRE) == 2) {                overheat += 5;            }        }        //... or from engine hits        if (attacker.entity instanceof Mech){            overheat += attacker.entity.getEngineCritHeat();        }        //... or ambient temperature        overheat += game.getTemperatureDifference();        if (attacker.entity.heat > 0 && overheat < 0) {            //always perfer smaller heat numbers            total_utility -= attacker.bv / 1000 * overheat;            //but add clear deliniations at the breaks            if (attacker.entity.heat > 4) {                 total_utility *= 1.2;            }            if (attacker.entity.heat > 7) {                total_utility += attacker.bv / 50;            }            if (attacker.tsm_offset){                if (attacker.entity.heat == 9) {                    total_utility -= attacker.bv/10;                }                if (attacker.entity.heat < 12 && attacker.entity.heat > 9) {                    total_utility -= attacker.bv/20;                }            }            if (attacker.entity.heat > 12) {                total_utility += attacker.bv / 20;            }            if (attacker.entity.heat > 16) {                total_utility += attacker.bv / 10;            }        } else if (overheat > 0) {            if (overheat > 4 && !attacker.tsm_offset) {                total_utility *= (this.overheat_eligible && attacker.jumpMP > 2) ? .9 : .85;            }             if (overheat > 7 && !attacker.tsm_offset) {                double mod = this.overheat_eligible ? + ((attacker.jumpMP > 2) ? 0 : 10) : 40;                if (this.attacker.overheat > CEntity.OVERHEAT_LOW) {                    total_utility -= attacker.bv / mod;                } else {                    total_utility -= attacker.bv / (mod + 10);                }            }            if (attacker.tsm_offset){                if (overheat == 9) {                    total_utility += attacker.bv/10;                }                if (attacker.entity.heat < 12 && attacker.entity.heat > 9) {                    total_utility += attacker.bv/20;                }            }            if (overheat > 12) {                total_utility -= attacker.bv / (this.overheat_eligible ? 45 : 30);            }            if (overheat > 16) {                //only if I am going to die?                total_utility -= attacker.bv / 5;            }            total_utility -= overheat / 100; //small preference for less            // overheat opposed to more        }        return total_utility;    }    /**     * since the low fitness members have the least chance of getting selected,     * but the highest chance of mutation, this is where we use the primary     * target heuristic to drive convergence     */    protected void doRandomMutation(int iChromIndex) {        Chromosome c1 = this.chromosomes[iChromIndex];        // skip if it's an empty chromosome        if (c1.genes.length < 1)            return;        int r1 = (c1.genes.length > 2) ? Compute.randomInt(c1.genes.length - 1) : 0;        CEntity target = null;        boolean done = false;        if (r1 % 2 == 1) {            c1.genes[r1]--;            if (c1.genes[r1] < 0 && attack.size() > r1) {                c1.genes[r1] = ((ArrayList) this.attack.get(r1)).size() - 1;            } else {                c1.genes[r1] = 0; // TODO : what is a good value here?            }            return;        }        //else try to move all to one target        for (int i = 0;(i < c1.genes.length - 1) && !done; i++) {            int iGene = (i + r1) % (c1.genes.length - 1);            AttackOption a = (AttackOption) ((ArrayList) (attack.get(iGene))).get(c1.genes[iGene]);            if (a.target != null) {                target = a.target;                done = true;            }        }        if (target == null) { //then not shooting, so shoot something            if (attack.size() > r1 && r1 > 1) {                c1.genes[r1] = Compute.randomInt(((ArrayList) (attack.get(r1))).size() - 1);            } else {                // TODO : Is this the correct action to take?                c1.genes[r1] = Compute.randomInt(((ArrayList) (attack.get(0))).size() - 1);            }            AttackOption a = (AttackOption) ((ArrayList) (attack.get(r1))).get(c1.genes[r1]);            if (a.target != null) {                c1.genes[c1.genes.length - 1] = a.target.enemy_num;            }        } else { //let's switch as many attacks as we can to this guy            for (int i = 0;(i < (c1.genes.length - 1)) && (i < attack.size()); i++) {                Object[] weapon = ((ArrayList) (attack.get(i))).toArray();                if (c1.genes[i] != weapon.length - 1) {                    done = false;                    for (int w = 0;(w < weapon.length - 1) && !done; w++) {                        AttackOption a = (AttackOption) weapon[w];                        if (a.target.enemy_num == target.enemy_num) {                            c1.genes[i] = w;                            done = true;                        }                    }                }            }            (this.chromosomes[0]).genes[chromosomeDim - 1] = target.enemy_num;        }    }    protected void initPopulation() {        //promote max        for (int iGene = 0; iGene < chromosomeDim - 1; iGene++) {            (this.chromosomes[0]).genes[iGene] = 0;        }        //use first weapon target as primary, not smart but good enough...        AttackOption a = (AttackOption) ((ArrayList) (attack.get(0))).get(0);        (this.chromosomes[0]).genes[chromosomeDim - 1] = a.target.enemy_num;        for (int i = 1; i < populationDim; i++) {            Chromosome cv = this.chromosomes[i];            for (int iGene = 0; iGene < chromosomeDim - 1; iGene++) {                cv.genes[iGene] = Compute.randomInt(((ArrayList) (attack.get(iGene))).size());                if (i <= this.attack.size()) {                    if (iGene + 1 == i)                        cv.genes[iGene] = 0; //fire                    else                        cv.genes[iGene] = ((ArrayList) (attack.get(iGene))).size() - 1;                }            }            cv.genes[chromosomeDim - 1] =                ((Integer) this.valid_target_indexes.get(Compute.randomInt(this.valid_target_indexes.size())))                    .intValue();            this.chromosomes[i].fitness = getFitness(i);        }    }        public int getFiringArc() {        return firing_arc;    }    public void setFiringArc(int firing_arc) {        this.firing_arc = firing_arc;    }    public ArrayList getAttack() {        return attack;    }}

⌨️ 快捷键说明

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