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; }
public void run() { if(current_job.getName() == "Idle") { current_job = assignJob(); } doJob(); }
public Ant(int x, int y, AntHill a) : base(x,y) { hasFood = false; status = ""; anthill = a; nearestFood = null; current_job = new Job(); }
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(); } } }