We are going to write code to modify the Ants scenario we worked with in lecture for the past few days.
If you don't remember how to do any of the steps (like, copying, zipping, etc), please refer back to Lab 1.
First, you will need to copy over the scenario for this assignment. If you are working from home, you can download the scenario here. If you are in lab, the scenario is located in /eng/class/notes/cse113/scenarios/Lab10.
It is probably most helpful to have read Chapter 9 before starting this lab, and perhaps even more helpful to have come to the lectures discussing Chapter 9.
You will be implementing an enemy (predator) for the ants that will go after the ants much in the same way the ants go after the food and you will be programming the ants so that they avoid the enemy as much as possible so that they don't become food.
First, you should run the scenario. Notice that the enemies (anteaters) behave exactly the same way as the ants. They go after the same food and take it back to their cave. Change the enemy so that it looks for ants as food, picks them up out of the world (removes them from the world) BUT does NOT take them back to the cave.
You should now run the changed scenario. You will notice that the anteaters will quickly eat up the ants (most likely from the left ant hill first).
We don't want the anteaters to have quite such an easy time, so reduce the number of anteaters in the cave to 5. Now, it will take the anteaters much longer to eat up a lot of the ants (try it and see).
However, we want to make the ants smarter about avoiding the anteaters. First, we will change the way anteaters drop pheromones. Right now, they use them the same way as the ants, to help other anteaters find food. We will not use them this way. We will use them as a clue to the ants that an anteater is around or has been around that area. Create another type of Pheromone called AnteaterScent as a subclass of Actor in your scenario. Its image should be the same as that for the pheromone.
Copy the contents of the Pheromone class into AnteaterScent so that it behaves just as a Pheromone would. Note that you will need to make some changes in order for the AnteaterScent to compile after you've done this.
Now, change the AnteaterScent so that it stays in the world twice as long as the Pheromone did.
Make it so that the anteaters do not pay attention to the pheromones as they search for food. At this point, simply remove the code from the searchForFood method that has anything to do with pheromones. Also, make it so that the anteaters will drop AnteaterScent regardless of whether or not they have food. Run the scenario again to ensure that the anteaters still can find ants. This is the end of the changes you will need for the anteaters.
Now, we need to work on making the ants smarter about avoiding the anteaters. Create an instance variable to hold onto the value of how many steps it has been that we have been smelling an anteater. The initial value of this variable should be zero. Create a method that adds one to this variable if we are intersecting with an anteater smell and resets it to zero if we are no longer intersecting with an anteater smell. Name the method you are writing sniffAnteater.
Call this method in your act() method whether you are carrying food or not. Lastly, you need to make a determination of how long ants should smell the anteater before they turn back towards home. You will need to modify your act method to make the ants turn towards home when they have smelled the anteater for long enough.
Once you have completed your work, you will submit the zipped up version of the Lab 10 scenario.
For directions on submitting, please see here.
Please recall that you must achieve a grade of at least 50% on each of the labs to be allowed to take the third practical exam. This lab is technically due on Monday, May 2nd at 11:59:59pm. You will need mastery of the skills you learn in this lab to be successful at practical exam 3.
Please make sure to look at your grading information on Web-CAT. See the grading information page for more details about how to interpret Web-CAT grade reports.
Lab authored by Adrienne Decker