CSE 113 - Spring 2010 - Banner
UB -
University at Buffalo, The State University of New York Computer Science and Engineering
  • CSE 113 - Spring 2010
CSE 113 - Spring 2010 - Navigation
CSE 113 - Spring 2010 - Announcements

Lab 4

CSE 113 - Spring 2010 - Announcements

Copy a scenario into your account & Open the Scenario

Go to /eng/class/notes/cse113/scenarios/ and copy the Lab4 directory/scenario to your account and open Greenfoot and the copied scenario

If you are working from home, you can get the Lab 4 scenario from here.


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 during the week of April 5th.

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.

 

Extra Credit Opportunity

If you would like to earn up to 10 points extra credit on this lab assignment, you can implement the following functionality.

Add to the behavior of the enemy so that they stay as close to the food piles as possible when they move about. This way, they will be sure to get to the ants that are coming to the food piles. How you choose to implement this is up to you.

In order to receive credit for this extra credit, you must demonstrate this behavior to a TA in a recitation before the lab is due. You must also show the TAs the code you created for this behavior. Therefore, if you are interested in taking advantage of the extra credit, you should plan ahead so that you can be finished by the time your last recitation is held.

 


Working outside of Bell 340

If you would like to continue this work outside of Bell 340, there are a few options available to you. You can work in Bell 101, which is an engineering public computing site. Information about the differences you may encounter when in Bell 101 are located here.

If you want to work on your own machine, totally independent of the lab environment, you will need several things. This page will explain where to look for information about downloading the files and programs you need to work on your home machine.

It is most advisable for you to create a folder (directory) on your machine where you can put the files needed for your assignments. This way, all work for this course will be in the same place when you go to look for it.


Submission/Grading

Zip up the scenario

Zip up the Lab4 scenario to create a file named Lab4.zip

Submission of zip file

Follow the instructions here and submit your file to the Lab 4 assignment. Note that you can submit your files from any computer that has the zip file and a web-browser. If you are experienced problems with submitting in the past, you need to make sure that you get them resolved before the due date for this lab. NO submissions will be accepted via email under any circumstances.

Grading

There is no in-recitation assessment for this assignment. Grading will be based on the files you submit to Web-CAT.

Due Date

Submissions for this assignment will close at 11:45pm on Sunday, April 25th.


Lab authored by Adrienne Decker

CSE 113 - Spring 2010 - Footer

Page maintained by Adrienne Decker

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