CSE 113 - Fall 2010 - Banner
  • CSE 113 - Fall 2010
CSE 113 - Fall 2010 - Navigation
CSE 113 - Fall 2010 - Lab 9

Lab 9
Last modified: December 01 2010 02:18:15 PM

CSE 113 - Fall 2010 - Lab 9

We are going to write code to modify the Ants scenario we worked with in lecture for the past few weeks.

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/Lab9.


Required Lab Tasks

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) and takes 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 and bring them back to their cave. 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.


Submitting the Assignment

Once you have completed your work, you will submit the zipped up version of the Lab 9 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 second practical exam. This means, that your labs are technically all due by the last day of class (December 10th). However, if you want to stay current with the course, I would recommend having this assignment completed within a week.


Grading Information

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.

  1. The anteaters look for ants as food (6.25 points)
  2. When anteaters find an ant, they pick it up (6.25 points)
  3. The anteaters take the ant back to their cave in their mouth (6.25 points).
  4. A maximum of 5 ants only should be allowed in the anteater home. (6.25 points)
  5. The AnteaterScent stays on the screen twice as long as the original pheromone did. (6.25 points)
  6. The anteaters ignore the pheromones the ants drop. (12.5 points)
  7. As the anteater moves about the screen, it drops AnteaterScent (like Ants do with Pheromone when they have food), except the anteaters drop whether they have food or not. (12.5 points)
  8. There is a method named sniffAnteater created in the Ant class. (6.25 points)
  9. The sniffAnteater method adds one to the instance variable if smelling an anteater (6.25 points)
  10. The sniffAnteater method resets the instance variable to zero if not smelling an anteater (6.25 points).
  11. Ants call the sniffAnteater method when carrying food (6.25 points)
  12. Ants also call the sniffAnteater method when they are not (6.25 points).
  13. Ants will turn away from anteaters if the ant has smelled the anteater for a specific length of time. (12.5 points)

Lab authored by Adrienne Decker

CSE 113 - Fall 2010 - Footer

Page maintained by Adrienne Decker

Contact: adrienne@buffalo.edu | 130 Bell Hall | (716)645-3184