Example #1
0
        private Job assignJob()
        {
            Job temp = new Job();
            int food_ants = 0;
            int water_ants = 0;
            int stick_ants = 0;
            int idle_ants = 0;

            foreach(Ant bob in anthill.antz)
            {
                if(bob.getJob().getName() == "Idle")
                {
                    idle_ants++;
                }
                else if(bob.getJob().getName() == "Food")
                {
                    food_ants++;
                }
                else if(bob.getJob().getName() == "Water")
                {
                    water_ants++;
                }
                else if(bob.getJob().getName() == "Sticks")
                {
                    stick_ants++;
                }
            }

            if(food_ants < anthill.getNumFoodAnts())
            {
                temp = new Job("Food");
            }

            return temp;
        }
Example #2
0
 public void run()
 {
     if(current_job.getName() == "Idle")
     {
         current_job = assignJob();
     }
     doJob();
 }
Example #3
0
        public Ant(int x, int y, AntHill a)
            : base(x,y, "Ant")
        {
            hasFood = false;
            status = "";
            anthill = a;
            ant_id = init_id++;
            nearestFood = null;

            hasObjects = false;

            current_job = new Job();
        }
Example #4
0
 private void doJob()
 {
     if(current_job.getName() == "Food")
     {
         if(hasFood)
         {
             moveTo(anthill.getX(), anthill.getY());
             status = "Moving to anthill";
             if(atLoc(anthill.getX(), anthill.getY()))
             {
                 hasFood = false;
                 anthill.incFood(food_capacity);
                 current_job = new Job();
                 status = "";
             }
         }
         else
         {
             findnearestfood();
             status = "Moving to nearest food";
             nearestFood = findnearestfood();
             moveTo(nearestFood.getX(), nearestFood.getY());
         }
         if(atLoc(nearestFood.getX(), nearestFood.getY()) && !hasFood)
         {
             gatherFood();
         }
     }
 }