Ejemplo n.º 1
0
  public void handle_sugar() {
    if (self.sugarCarry > 0) { // have sugar => go home:
      moveHome();
    } else { // dont have sugar:
      if (visibleSugar.size() == 0) { // dont see sugar:

        // move, where you were going:
        moveInDirection(dir);
        // if you know about sugar:
        // if (hills.get(0) == null) System.out.print("null\n");
        if (hills.get(HillAI.SUGAR_IND).size() > 0 && time + initialTime > HillAI.STOP_LOOKING) {
          Snapshot target = find_optimal_sugar_hill();
          if (target != null) {
            moveToward(target);
            if (vectorBetween(self, target).length() < self.caste.SIGHT_RANGE) {
              HillAI.add_if_not_contained(hills.get(HillAI.NOSUGAR_IND), target);
              HillAI.delete(hills.get(HillAI.SUGAR_IND), target);
              HillAI.delete(hills.get(HillAI.FULLSUGAR_IND), target);
            }
          }
        }
      } else { // see sugar:
        Sugar sugar = closest(visibleSugar);
        moveToward(sugar); // otherwise move to the first element in the List of visible sugar
        think_about_picking_up(sugar);
        if (!HillAI.contained(hills.get(HillAI.FULLSUGAR_IND), sugar)) {
          HillAI.add_if_not_contained(hills.get(HillAI.SUGAR_IND), sugar);
        }
      }
    }
  }
Ejemplo n.º 2
0
 public void listen() {
   for (AntMessage m : audibleAntMessages) {
     switch (m.content) {
       case HillAI.SUGAR:
         if (!HillAI.contained(hills.get(HillAI.NOSUGAR_IND), m.contentSugar)) {
           HillAI.add_if_not_contained(hills.get(HillAI.SUGAR_IND), m.contentSugar);
         }
         break;
       case HillAI.FULLSUGAR:
         if (!HillAI.contained(hills.get(HillAI.NOSUGAR_IND), m.contentSugar)) {
           if (HillAI.add_if_not_contained(hills.get(HillAI.FULLSUGAR_IND), m.contentSugar)) {
             HillAI.delete(hills.get(HillAI.SUGAR_IND), m.contentSugar);
           }
         }
         break;
       case HillAI.NOSUGAR:
         if (HillAI.add_if_not_contained(hills.get(HillAI.NOSUGAR_IND), m.contentSugar)) {
           HillAI.delete(hills.get(HillAI.SUGAR_IND), m.contentSugar);
           HillAI.delete(hills.get(HillAI.FULLSUGAR_IND), m.contentSugar);
         }
         break;
       case HillAI.HILL:
         HillAI.add_if_not_contained(hills.get(HillAI.HILL_IND), m.contentHill);
         break;
     }
     // System.out.printf("%d: %d\n", self.id, m.content);
   }
 }
Ejemplo n.º 3
0
 public void think_about_picking_up(Sugar sugar) {
   int count = 0;
   for (Ant a : visibleFriends()) {
     if (a.caste == Caste.Gatherer) {
       if (a.id < self.id) count++;
     }
   }
   if (count < HillAI.QUEUELENGTH) {
     pickUpSugar(sugar);
   } else {
     if (count < sugar.amount / (Caste.Gatherer.MAX_SUGAR_CARRY)) {
       Vector pos = sugar.position;
       pos =
           Vector.add(
               pos,
               (new Vector(Math.sin(dir), Math.cos(dir))
                   .scale(parameters.ATTACK_RANGE * HillAI.COMBAT_RADIUS)));
       moveToward(pos);
       if (visibleEnemies().size() > 0) {
         attack(closest(visibleEnemies()));
       }
     } else {
       if (HillAI.add_if_not_contained(hills.get(HillAI.FULLSUGAR_IND), sugar)) {
         HillAI.delete(hills.get(HillAI.SUGAR_IND), sugar);
       }
       Snapshot target = find_optimal_sugar_hill();
       if (target != null) {
         moveToward(target);
       }
     }
   }
 }