Пример #1
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);
   }
 }
Пример #2
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);
        }
      }
    }
  }