コード例 #1
0
  public EntityKnowledge getBestTarget() {
    int radius = (int) (WarRocket.AUTONOMY * WarRocket.SPEED);
    EntityKnowledge target = null;

    for (Map<Integer, EntityKnowledge> map : ennemies.values()) {
      for (EntityKnowledge ek : map.values()) {
        if ((ek.getLastUpdateDuration(tick) < 5) && (ek.getDistance(x, y) < radius)) {
          if ((target == null) || (ek.getEnergy() < target.getEnergy())) {
            target = ek;
          }
        }
      }
    }
    return target;
  }
コード例 #2
0
 public EntityKnowledge getNearestEnnemy() {
   EntityKnowledge nearest = null;
   int minDistance = Integer.MAX_VALUE;
   for (Map<Integer, EntityKnowledge> map : ennemies.values()) {
     for (EntityKnowledge ek : map.values()) {
       if (ek.getLastUpdateDuration(tick) < 2) {
         int distance = ek.getDistance(getX(), getY());
         if (distance < minDistance) {
           minDistance = distance;
           nearest = ek;
         }
       }
     }
   }
   return nearest;
 }