public boolean match() { if (robot.getOthers() > 5 || targetManager.getAliveTargetCount() == 0) { return false; } Map<Target, Double> dists = new HashMap<Target, Double>(); final java.util.List<Target> aliveTargets = targetManager.getAliveTargets(); for (Target t : aliveTargets) { final Target closest = targetManager.getClosestTergetToT(t); if (closest == null) { return false; } dists.put(t, closest.aDistance(t) + 80); } LXXPoint candidate = dest; Target closest = targetManager.getClosestTarget(); for (int i = 0; i < 20; i++) { double angle = Utils.angle(closest.getPosition(), robot.getPosition()) + Math.random() * LXXConstants.RADIANS_20 - LXXConstants.RADIANS_10; double dist = dists.get(closest); if (candidate == null) { candidate = new LXXPoint(closest.getX() + sin(angle) * dist, closest.getY() + cos(angle) * dist); } for (Target t : aliveTargets) { final double d = t.aDistance(candidate); if (d < dists.get(t)) { candidate = null; break; } } if (candidate != null && robot.getBattleField().contains(candidate)) { break; } candidate = new LXXPoint(closest.getX() + sin(angle) * dist, closest.getY() + cos(angle) * dist); } dest = candidate; return candidate != null && robot.getBattleField().contains(candidate) && StaticData.robot.getDestination().aDistance(dest) > 20; }
public void paint(Graphics2D g) { if (targetManager.getAliveTargetCount() == 0) { return; } g.setColor(Color.RED); for (Target t : targetManager.getAliveTargets()) { final Target another = targetManager.getClosestTergetToT(t); final double dist = another.aDistance(t) * 2 + 20; g.drawOval((int) (t.getX() - dist / 2), (int) (t.getY() - dist / 2), (int) dist, (int) dist); g.drawLine((int) t.getX(), (int) t.getY(), (int) another.getX(), (int) another.getY()); } }