
  
-
Show me you have everything working from Part 1 before starting Part 2!
Part 2
Now that you know how all the classes interact change and expand your Ant Farm classes to do the following.
- Give Food and WorkerAnt weight. Start each food item with the weight of 5,000,000 micrograms and each ant with a weight of 1,000 micrograms plus or minus 300 micrograms. Ants can carry up to 20 times their own body weight. When an ant takes a bite from the food, the food weight is decrease by 20 times the ant's body weight, which is the amount carried off by the ant. When the food weight gets to zero have the food removed from the grid.
You do not need the constants BITE_SIZE nor the instance variable bite any more. Remove all reference from the Food, Cake and Cookie classes. Remember to use constants for values you create and to update the toString methods!
- When WorkerAnts come back to a food location they remembered, and the food has disappeared, change the remembered food location to inidicate the food is gone. This information should be propagated to the rest of the ants.
This is tricky to figure out. Do not add any additional instance fields. When a Food's weight becomes zero, it removes itself from the grid. Make sure the food object only shares it's location if it is in the grid! The AntWorker makeMove method now checks to see if the food is not at the location where it is suppose to be. If this is the case, then change the food location to a bogus location that is not found in the grid! The method getDesiredDirection will have to be altered slightly for this process to work, plus the method shareFoodLocation will have to be altered . It might be helpful to write private help methods isFoodLocationInGrid(Location) and isBogusLocation(Location) that determines if a food location is still in the grid or is a bogus location. To get the logic correct for shareFoodLocation create a matrix with all the possiblities:
|
null |
Good |
Bogus |
| null |
|
|
|
| Good |
|
|
|
| Bogus |
|
|
|
Show me you have Part 2 working before starting Part 3!
Part 3
- Add energy to the WorkerAnt class. Ants should start with 100 units of energy and for each step the ant should lose energy by:
- If the ant cannot move it looses 1 unit of energy and 1 microgram of weight.
- If the ant can move and it is not carrying any food it looses 2 units of energy and 2 micrograms of weight.
- If the ant can move and it is carrying food it looses 2 units of energy plus the amount it is carrying divided by 10,000 units of energy. It also losses 3 micrograms of weight.
- Ants gain energy when they find food. They should eat 1/4 of their body weight of food, which in turn is converted into (food eaten) / 1000 units of energy. Weight is increased by (food eaten) / 200 micrograms. Remember the ant's bite of food is still 20 times the ant's body weight.
- Ants die when their energy or weight is reduced to 0. If they are carrying food when they die a food item should be placed in the cell that the ant dies in. The food created should be randomly selected (cake or cookie) with the weight of food being carried by the ant. You could add what kind of food the ant is carrying, then drop that same kind of food when the ant dies.
Show me your results for Part 3!
|