if (bestAttack.type == PhysicalOption.KICK_LEFT || bestAttack.type == PhysicalOption.KICK_RIGHT) { int side = CEntity.getThreatHitArc( bestAttack.target.getPosition(), bestAttack.target.getFacing(), en.getPosition()); double odds = 1.0 - (double) Compute.oddsAbove( KickAttackAction .toHit(bot.game, entNum, bestAttack.target, bestAttack.type - 3) .getValue()) / 100;   double mod = 1.0; if (bestAttack.target instanceof Mech) { double llarmor = (bestAttack.target.getOArmor(Mech.LOC_LLEG) > 0) ? (bestAttack.target.getArmor(Mech.LOC_LLEG) / bestAttack.target.getOArmor(Mech.LOC_LLEG)):0; double rlarmor = (bestAttack.target.getOArmor(Mech.LOC_RLEG) > 0) ? (bestAttack.target.getArmor(Mech.LOC_RLEG) / bestAttack.target.getOArmor(Mech.LOC_RLEG)):0; switch (side) { case ToHitData.SIDE_FRONT : mod = (llarmor + rlarmor) / 2; break; case ToHitData.SIDE_LEFT : mod = llarmor; break; case ToHitData.SIDE_RIGHT : mod = rlarmor; break; } } else if (bestAttack.target instanceof Infantry) { mod = 0.0; } else if (bestAttack.target instanceof Tank) { switch (side) { case ToHitData.SIDE_FRONT : mod = (bestAttack.target.getOArmor(Tank.LOC_FRONT) > 0) ? ((bestAttack.target.getArmor(Tank.LOC_FRONT) / bestAttack.target.getOArmor(Tank.LOC_FRONT))) : 0; break; case ToHitData.SIDE_LEFT : mod = (bestAttack.target.getOArmor(Tank.LOC_LEFT) > 0) ? bestAttack.target.getArmor(Tank.LOC_LEFT) / bestAttack.target.getOArmor(Tank.LOC_LEFT) : 0; break; case ToHitData.SIDE_RIGHT : mod = (bestAttack.target.getOArmor(Tank.LOC_RIGHT) > 0) ? bestAttack.target.getArmor(Tank.LOC_RIGHT) / bestAttack.target.getOArmor(Tank.LOC_RIGHT) : 0; break; case ToHitData.SIDE_REAR : mod = (bestAttack.target.getOArmor(Tank.LOC_REAR) > 0) ? bestAttack.target.getArmor(Tank.LOC_REAR) / bestAttack.target.getOArmor(Tank.LOC_REAR) : 0; break; } } double damage = 2 / (1 + mod) * bestAttack.expectedDmg; double threat = .2 * en.getWeight() * odds * (1 - cen.base_psr_odds);  IHex h = bot.game.getBoard().getHex(bestAttack.target.getPosition()); IHex h1 = bot.game.getBoard().getHex(en.getPosition()); if (h1.getElevation() > h.getElevation()) { damage *= 2; } Enumeration e = bot.game.getEntities(); double temp_threat = 0; int number = 0; while (e.hasMoreElements()) { Entity enemy = (Entity) e.nextElement();  if (null == enemy.getPosition()) continue;  if (!enemy.isProne() && enemy.getPosition().distance(en.getPosition()) < 3) { if (enemy.isEnemyOf(en)) { number++; } else { number--; } } } if (number > 0) { threat += number * temp_threat; } if (!((damage > threat && !(cen.overall_armor_percent > .8 && odds > .9)) || (odds < .5 && cen.base_psr_odds > .5))) { boolean left = false; boolean right = false; ToHitData toHit = PunchAttackAction.toHit(bot.game, en.getId(), bestAttack.target, PunchAttackAction.LEFT); if (toHit.getValue() != ToHitData.IMPOSSIBLE) { left = true; } toHit = PunchAttackAction.toHit(bot.game, en.getId(), bestAttack.target, PunchAttackAction.RIGHT); if (toHit.getValue() != ToHitData.IMPOSSIBLE) { right = true; } if (left) { if (right) { bestAttack.type = PhysicalOption.PUNCH_BOTH; } else { bestAttack.type = PhysicalOption.PUNCH_LEFT; } } else if (right) { bestAttack.type = PhysicalOption.PUNCH_RIGHT; } else { return new PhysicalOption(en); } } }
    PhysicalOption calculatePhysicalTurn(TestBot bot) {        int entNum = bot.game.getFirstEntityNum();        int first = entNum;        do {            // take the first entity that can do an attack            Entity en = bot.game.getEntity(entNum);            CEntity cen = bot.centities.get(en);            PhysicalOption bestAttack = getBestPhysical(en, bot.game);            if (bestAttack != null) {                if (bestAttack.type == PhysicalOption.KICK_LEFT || bestAttack.type == PhysicalOption.KICK_RIGHT) {                    int side =                        CEntity.getThreatHitArc(                                                bestAttack.target.getPosition(),                                                bestAttack.target.getFacing(),                                                en.getPosition());                    double odds =                        1.0                        - (double) Compute.oddsAbove(                                                     KickAttackAction                                                     .toHit(bot.game, entNum, bestAttack.target, bestAttack.type - 3)                                                     .getValue())                        / 100;                    // Meks can kick Vehicles and Infantry, too!                    double mod = 1.0;                    if (bestAttack.target instanceof Mech) {                        double llarmor = (bestAttack.target.getOArmor(Mech.LOC_LLEG) > 0) ?                            (bestAttack.target.getArmor(Mech.LOC_LLEG) / bestAttack.target.getOArmor(Mech.LOC_LLEG)):0;                        double rlarmor = (bestAttack.target.getOArmor(Mech.LOC_RLEG) > 0) ?                            (bestAttack.target.getArmor(Mech.LOC_RLEG) / bestAttack.target.getOArmor(Mech.LOC_RLEG)):0;                        switch (side) {                        case ToHitData.SIDE_FRONT :                            mod = (llarmor + rlarmor) / 2;                            break;                        case ToHitData.SIDE_LEFT :                            mod = llarmor;                            break;                        case ToHitData.SIDE_RIGHT :                            mod = rlarmor;                            break;                        }                    } else if (bestAttack.target instanceof Infantry) {                        mod = 0.0;                    } else if (bestAttack.target instanceof Tank) {                        switch (side) {                        case ToHitData.SIDE_FRONT :                            mod = (bestAttack.target.getOArmor(Tank.LOC_FRONT) > 0) ?                                ((bestAttack.target.getArmor(Tank.LOC_FRONT)                                / bestAttack.target.getOArmor(Tank.LOC_FRONT))) : 0;                            break;                        case ToHitData.SIDE_LEFT :                            mod = (bestAttack.target.getOArmor(Tank.LOC_LEFT) > 0) ?                                bestAttack.target.getArmor(Tank.LOC_LEFT)                                / bestAttack.target.getOArmor(Tank.LOC_LEFT) : 0;                            break;                        case ToHitData.SIDE_RIGHT :                            mod = (bestAttack.target.getOArmor(Tank.LOC_RIGHT) > 0) ?                                bestAttack.target.getArmor(Tank.LOC_RIGHT)                                / bestAttack.target.getOArmor(Tank.LOC_RIGHT) : 0;                            break;                        case ToHitData.SIDE_REAR :                            mod = (bestAttack.target.getOArmor(Tank.LOC_REAR) > 0) ?                                bestAttack.target.getArmor(Tank.LOC_REAR)                                / bestAttack.target.getOArmor(Tank.LOC_REAR) : 0;                            break;                        }                    }                    double damage = 2 / (1 + mod) * bestAttack.expectedDmg;                    double threat = .2 * en.getWeight() * odds * (1 - cen.base_psr_odds);                    //check for head kick                    IHex h = bot.game.getBoard().getHex(bestAttack.target.getPosition());                    IHex h1 = bot.game.getBoard().getHex(en.getPosition());                    if (h1.getElevation() > h.getElevation()) {                        damage *= 2;                    }                    Enumeration e = bot.game.getEntities();                    double temp_threat = 0;                    int number = 0;                    while (e.hasMoreElements()) {                        Entity enemy = (Entity) e.nextElement();                        if (null == enemy.getPosition())                            continue;                        if (!enemy.isProne() && enemy.getPosition().distance(en.getPosition()) < 3) {                            if (enemy.isEnemyOf(en)) {                                number++;                            } else {                                number--;                            }                        }                    }                    if (number > 0) {                        threat += number * temp_threat;                    }                    if (!((damage > threat && !(cen.overall_armor_percent > .8 && odds > .9))                          || (odds < .5 && cen.base_psr_odds > .5))) {                        boolean left = false;                        boolean right = false;                        ToHitData toHit =                            PunchAttackAction.toHit(bot.game, en.getId(), bestAttack.target, PunchAttackAction.LEFT);                        if (toHit.getValue() != ToHitData.IMPOSSIBLE) {                            left = true;                        }                        toHit =                            PunchAttackAction.toHit(bot.game, en.getId(), bestAttack.target, PunchAttackAction.RIGHT);                        if (toHit.getValue() != ToHitData.IMPOSSIBLE) {                            right = true;                        }                        if (left) {                            if (right) {                                bestAttack.type = PhysicalOption.PUNCH_BOTH;                            } else {                                bestAttack.type = PhysicalOption.PUNCH_LEFT;                            }                        } else if (right) {                            bestAttack.type = PhysicalOption.PUNCH_RIGHT;                        } else {                            return new PhysicalOption(en);                        }                    }                }                return bestAttack;            } // End no-attack            entNum = bot.game.getNextEntityNum(entNum);        }        while (entNum != -1 && entNum != first);        // Didn't find any physical attack.        return null;    }