Homework 1: responding

Due Wednesday, 15 Sep, midnight.

General instructions

In this assignment you will only work with the step() method in the Smart class. You should submit one .java file for each part of the assignment. When you are doing a particular part of the assignment, each file will need to be named Smart.java, but before submitting them, you will have to give them different names because you will have them all in the same directory. When you are done, bundle the files into one file using "zip", "tar", or a similar utility. Please include your last name in the name of your file. With "zip", for example, you would do something like this:

zip gasser Smart1.java Smart2.java Smart3.java

Then go to the Vincent page for the class to upload the file.

Specific instructions

Start by downloading the version of the program that you will use for this assignment. The file Smart.java that you will need to edit is not in that archive. You can download it here.

For each part of the assignment you will write a different version of step() that works well for a particular world, always saving the class file with the name Smart.java before you compile and run the program. Because you will have three different versions of the file, you will have to change their names after you test and before submitting them. You should change them to Smart1.java, Smart2.java, and Smart3.java.

Your goal is to have the critter survive as long as possible. Because there is some randomness in the program, you will never be able to guarantee the critter's survival, but you can experiment with your program by clicking on the PLAY button, which runs the program for 250 steps. If your critter usually survives this long, you can consider yourself successful for a given world.

Be sure to save the file you are working on and to compile all of the .java files before testing your program. Remember that you can run your program on a given world by treating the name of the file for that world as an argument to java, for example, for part 1,

java Smarts safe

Before you start, go to the documentation for the built-in methods (in Docs/index.html), and familiarize yourself with the methods in the Beh class that you can use for the assignment.

  1. Write a version of step() that works well in the safe world. This world has plants and rocks, but no predators. When you are done, copy Smart.java to a file named Smart1.java.
  2. Edit step() in Smart.java so the critter does will in the messy world. This world has one predator, as well as plants and rocks. The predator will eat your critter if it comes in contact with it, but it does not know how to chase it. In this world (but not that in part 3), there is some randomness in the predator's movements. When you are done, copy Smart.java to a file named Smart2.java.
  3. Edit step() in Smart.java so the critter does will in the hedges world. This world has three predators that always move up (north) and plants that always appear in the fertile cells that are arranged in two north-south rows. When you are done, copy this version of Smart.java to a file called Smart3.java.

Home

Calendar

Coursework & grading

Assignments

Lecture notes

Other resources


IU home

IU CS home

Contact instructor