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; } entNum = bot.game.getNextEntityNum(entNum); } while (entNum != -1 && entNum != first); throw new RuntimeException("Error finding a unit that has a physical option");
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;  } entNum = bot.game.getNextEntityNum(entNum);  } while (entNum != -1 && entNum != first);   return null;
    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.getArmor(Mech.LOC_LLEG) / bestAttack.target.getOArmor(Mech.LOC_LLEG);						double rlarmor =							bestAttack.target.getArmor(Mech.LOC_RLEG) / bestAttack.target.getOArmor(Mech.LOC_RLEG);						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.getArmor(Tank.LOC_FRONT)										/ bestAttack.target.getOArmor(Tank.LOC_FRONT);								break;							case ToHitData.SIDE_LEFT :								mod =									bestAttack.target.getArmor(Tank.LOC_LEFT)										/ bestAttack.target.getOArmor(Tank.LOC_LEFT);								break;							case ToHitData.SIDE_RIGHT :								mod =									bestAttack.target.getArmor(Tank.LOC_RIGHT)										/ bestAttack.target.getOArmor(Tank.LOC_RIGHT);								break;							case ToHitData.SIDE_REAR :								mod =									bestAttack.target.getArmor(Tank.LOC_REAR)										/ bestAttack.target.getOArmor(Tank.LOC_REAR);								break;						}					}					double damage = 2 / (1 + mod) * bestAttack.expectedDmg;					double threat = .2 * en.getWeight() * odds * (1 - cen.base_psr_odds);					//check for head kick					Hex h = bot.game.board.getHex(bestAttack.target.getPosition());					Hex h1 = bot.game.board.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;			}			entNum = bot.game.getNextEntityNum(entNum);		}		while (entNum != -1 && entNum != first);		throw new RuntimeException("Error finding a unit that has a physical option");    }