CISC181 F2017 Lab4

From class_wiki
Revision as of 08:38, 3 October 2017 by Cer (talk | contribs)
Jump to: navigation, search

Preliminaries

  • Make a new project with n = 4 (following these instructions)
  • Name your main class "Lab4" (when creating a new module in the instructions above, in the Java class name field)
  • Modify Lab4.java by adding your name in a comment before the Lab4 class body.

Instructions

In this lab you will write a simple AI (artificial intelligence) for a "Creature" that exists in a grid-like world. Similar to the turtle in the last assignment, your Creature lives in a 2-D grid with rectangular borders. However, this time if the Creature tries to cross one of the borders it is not stopped, but rather crosses over to the opposite side. Thus, the world may be thought of as a torus.

Also, in this world each grid square has a different terrain type: DESERT, FOREST, FIELD, WATER, or MOUNTAIN. These are represented as shown below with different colors: yellow, dark green, light green, blue, and red, respectively. The Creature can move through any terrain type, but DESERT and MOUNTAIN grid cells are difficult and thus deplete one energy unit for each turn you spend in them. FOREST cells have shade and berries, and thus regenerate one energy unit for each turn you spend in them. If you get down to an energy level of 0, you can no longer move and are effectively "dead."

Finally, there are a number of food caches scattered around the world (shown as red circles) that will completely replenish your energy if your Creature visits them. However, once you have used a food caches, it disappears forever and cannot be used again.

Bt screenshot.png

The object of this assignment is to write an AI for your Creature that will guide it to get every food cache without dying along the way. This will require you to:

  • Select one of the remaining food caches and move toward it, until there are none left
  • Monitor your current energy level and make sure it does not dwindle to 0 during your quest

We are providing you with several files that implement this simulator, draw the Creature, furnish you with information about the world, and allow you to choose an "action" to move the Creature around. Unlike the previous lab, actual movement is handled by the simulator rather than you. Here are the files you should add to your project (note that you probably need to change the package name to match your own):

  • BioTorus.java
  • Creature.java
  • MyClass.java (this is my name for your Lab4.java -- probably it is easiest to just copy the contents into your own pre-made file)

This code will not compile as is, because it expects a class called MyCreatureBrain that does not exist. You should create this class and change the name to something unique, like your last name instead of "My". This class should extend the abstract class CreatureBrain (defined in Creature.java). CreatureBrain has a number of utility functions that you will inherit and can use, but one abstract method that you must define: void setAction(). This function will be called automatically by the simulator, once per turn, and is the place where your Creature "thinks" about its goals and situation, and makes a decision about which of the following actions to take:

  • Move forward one space
  • Turn left 90 degrees (without moving forward)
  • Turn right 90 degrees
  • Stay in place and do not turn

The way that you say what action you choose is to call one of the following methods inherited from CreatureBrain:

  • setForwardSpeed(int speed), where speed is either 0 (don't move) or 1 (move forward)
  • setTurningSpeed(int turnspeed), where turnspeed is either -1 (turn left), 0 (don't turn), or +1 (turn right)

"Illegal" values will be ignored, and if you try to turn AND move forward at the same time, turning will take precedence.

You may add any "helper" private methods that you need.

Submission

You should only submit your MyCreatureBrain.java. Remember, it should be renamed to something unique like JSmithCreatureBrain.java or StudentXCreatureBrain.java. Just make sure your full name and section number are in a comment in the file.