📄 testbot.java
字号:
} if (((best_left_po.type == PhysicalOption.PUNCH_RIGHT) || (best_left_po.type == PhysicalOption.PUNCH_BOTH)) && (mw.getLocation() == Mech.LOC_RARM)) { left_ra_dmg += ((AttackOption) c.get(c.size() - 2)).value; } } left.add(c); attacks[1] = Math.max(attacks[1], c.size()); } en.setSecondaryFacing((o_facing + 1) % 6); c = this.calculateWeaponAttacks(en, mw, true); if (c.size() > 0) { // Get best physical attack best_right_po = PhysicalCalculator.getBestPhysical(en, game); if ((best_right_po != null) && (en instanceof Mech)) { if (((best_right_po.type == PhysicalOption.PUNCH_LEFT) || (best_right_po.type == PhysicalOption.PUNCH_BOTH)) && (mw.getLocation() == Mech.LOC_LARM)) { right_la_dmg += ((AttackOption) c.get(c.size() - 2)).value; } if (((best_right_po.type == PhysicalOption.PUNCH_RIGHT) || (best_right_po.type == PhysicalOption.PUNCH_BOTH)) && (mw.getLocation() == Mech.LOC_RARM)) { right_ra_dmg += ((AttackOption) c.get(c.size() - 2)).value; } } right.add(c); attacks[2] = Math.max(attacks[2], c.size()); } en.setSecondaryFacing((o_facing + 3) % 6); c = this.calculateWeaponAttacks(en, mw, true); if (c.size() > 0) { rear.add(c); attacks[3] = Math.max(attacks[3], c.size()); } } else { attacks[1] = 0; attacks[2] = 0; } en.setSecondaryFacing(o_facing); } fireOrPhysicalCheck(best_front_po, en, front, front_la_dmg, front_ra_dmg); ArrayList arcs = new ArrayList(); arcs.add(front); if (!es.getFinalProne() && en.canChangeSecondaryFacing()) { fireOrPhysicalCheck(best_left_po, en, left, left_la_dmg, left_ra_dmg); arcs.add(left); fireOrPhysicalCheck(best_right_po, en, right, right_la_dmg, right_ra_dmg); arcs.add(right); // Meks and protos can't twist all the way around. if (!(en instanceof Mech) && !(en instanceof Protomech)) { arcs.add(rear); } } for (int i = 0; i < arcs.size(); i++) { ArrayList v = (ArrayList) arcs.get(i); if (v.size() > 0) { GAAttack test = new GAAttack(this, centities.get(en), v, Math.max((v.size() + attacks[i]) * search_level, 20 * search_level), 30 * search_level, en.isEnemyOf((Entity) getEntitiesOwned().get(0))); test.setFiringArc(i); test.evolve(); if (target != null) { if (result == null || test.getDamageUtility(target) > result.getDamageUtility(target)) { result = test; } } else if ( result == null || test.getFittestChromosomesFitness() > result.getFittestChromosomesFitness()) { result = test; } } } return result; } /** * If the best attack is a punch, then check each * punch damage against the weapons damage from the * appropriate arm; if the punch does more damage, * drop the weapons in that arm to 0 expected damage * Repeat this for left and right twists * * @param best_po * @param entity * @param attackOptions * @param la_dmg * @param ra_dmg */ private void fireOrPhysicalCheck(PhysicalOption best_po, Entity entity, ArrayList attackOptions, double la_dmg, double ra_dmg) { ArrayList c; if ((best_po != null) && (entity instanceof Mech)) { if (best_po.type == PhysicalOption.PUNCH_LEFT) { if ((la_dmg < best_po.expectedDmg) && (attackOptions.size() > 0)) { for (int i = 0; i < attackOptions.size(); i++) { c = (ArrayList) attackOptions.get(i); for (int j = 0; j < c.size(); j++) { if (((AttackOption) c.get(j)).weapon.getLocation() == Mech.LOC_LARM) { ((AttackOption) c.get(j)).expected = 0; ((AttackOption) c.get(j)).primary_expected = 0; } } } } } if (best_po.type == PhysicalOption.PUNCH_RIGHT) { if ((ra_dmg < best_po.expectedDmg) && (attackOptions.size() > 0)) { for (int i = 0; i < attackOptions.size(); i++) { c = (ArrayList) attackOptions.get(i); for (int j = 0; j < c.size(); j++) { if (((AttackOption) c.get(j)).weapon.getLocation() == Mech.LOC_RARM) { ((AttackOption) c.get(j)).expected = 0; ((AttackOption) c.get(j)).primary_expected = 0; } } } } } if (best_po.type == PhysicalOption.PUNCH_BOTH) { if (((la_dmg + ra_dmg) < best_po.expectedDmg) && (attackOptions.size() > 0)) { for (int i = 0; i < attackOptions.size(); i++) { c = (ArrayList) attackOptions.get(i); for (int j = 0; j < c.size(); j++) { if (((AttackOption) c.get(j)).weapon.getLocation() == Mech.LOC_LARM) { ((AttackOption) c.get(j)).expected = 0; ((AttackOption) c.get(j)).primary_expected = 0; } if (((AttackOption) c.get(j)).weapon.getLocation() == Mech.LOC_RARM) { ((AttackOption) c.get(j)).expected = 0; ((AttackOption) c.get(j)).primary_expected = 0; } } } } } } } /* could use best of best strategy instead of expensive ga */ public double attackUtility(MoveOption es, CEntity target) { GAAttack result = bestAttack(es, target, 1); if (result == null) { return 0; } return result.getFittestChromosomesFitness(); } public void calculateFiringTurn() { int first_entity = game.getFirstEntityNum(); int entity_num = first_entity; int best_entity = first_entity; int spin_mode = 0; double max = java.lang.Double.NEGATIVE_INFINITY; int[] results = null; ArrayList winner = null; int arc = 0; WeaponType spinner; if (entity_num == -1) { return; } do { Entity en = game.getEntity(entity_num); CEntity cen = centities.get(en); GAAttack test = bestAttack(cen.current, null, 3); if (test != null && test.getFittestChromosomesFitness() > max) { max = test.getFittestChromosomesFitness(); results = test.getResultChromosome(); arc = test.getFiringArc(); best_entity = entity_num; winner = test.getAttack(); } entity_num = game.getNextEntityNum(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) game.getEntitiesVector().get(results[results.length - 1]); TreeMap tm = new TreeMap(new AttackOption.Sorter(centities.get(primary_target))); for (int i = 0; i < results.length - 1; i++) { AttackOption a = (AttackOption) ((ArrayList) winner.get(i)).get(results[i]); if (a.target != null) { a.target.expected_damage[a.toHit.getSideTable()] += a.value; a.target.hasTakenDamage = true; tm.put(a, a); } } Iterator i = tm.values().iterator(); while (i.hasNext()) { AttackOption a = (AttackOption) i.next(); WeaponAttackAction new_attack = new WeaponAttackAction(en.getId(), a.target.getEntity().getId(), en.getEquipmentNum(a.weapon)); if (en.getEquipment(new_attack.getWeaponId()).getLinked() != null) { spinner = (WeaponType) a.weapon.getType();// If this is an ultra-cannon or rotary cannon, try to spin it up 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, new_attack); super.sendModeChange(en.getId(), en.getEquipmentNum(a.weapon), spin_mode); } Mounted cur_ammo = en.getEquipment(new_attack.getWeaponId()).getLinked(); new_attack.setAmmoId(en.getEquipmentNum(cur_ammo)); Compute.getAmmoAdjDamage(game, new_attack); } av.add(new_attack); } // Use the attack options and weapon attack actions to determine the best aiming point if (av.size() > 0){ getAimPoint(tm, av); } } switch (arc) { case 1: av.add(0, new TorsoTwistAction(en.getId(), (en.getFacing() + 5) % 6)); break; case 2: av.add(0, new TorsoTwistAction(en.getId(), (en.getFacing() + 1) % 6)); break; case 3: av.add(0, new TorsoTwistAction(en.getId(), (en.getFacing() + 3) % 6)); break; } sendAttackData(best_entity, av); } /** * consider how to put more pre-turn logic here */ protected void initMovement() { this.my_mechs_moved = 0; this.old_moves = null; this.enemies_moved = 0; double max_modifier = 1.4; ArrayList entities = new ArrayList(game.getEntitiesVector()); double num_entities = Math.sqrt(entities.size()) / 100; ArrayList friends = new ArrayList(); ArrayList foes = new ArrayList(); double friend_sum = 0; double foe_sum = 0; double max_foe_bv = 0; CEntity max_foe = null; for (int i = 0; i < entities.size(); i++) { Entity entity = (Entity) entities.get(i); CEntity centity = centities.get(entity); centity.enemy_num = i; double old_value = centity.bv * (centity.overall_armor_percent + 1); cen
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -