15-100: Introductory/Intermediate Programming (Section F)
Fall 2006
Exercise    - practice
09/29/2006
Practice on Predicates
Due:  none

Relevant Reading:

  • Handout from class (not available on line) and class notes
  • Chapters 1,2,3, 5 and 6 of  the Karel J. Robot text

Assignment:  (worth 0 exercise points - this exercise is for practice only)

Get the ex-practicePredicates.zip file.  Use the files in this folder as your basis for this assignment.

Define a DiscriminatingRobot class that contains that contains at least one predicate.  The name of the predicate is up to you (but make it descriptive), but it should determine whether or not the robot is on an intersection with exactly two beepers.   Instantiate a DiscriminatingRobot object in Application.java and pass appropriate messages to the object to do the following task:

Specifications:
  • The robot starts at the intersection (avenue = 10, street = 5) with no beepers in the beeper bag, facing West.   This location is one block East of a street of beepers that extends to the Western boundary wall.
  • Each intersection between the robot and the Western boundary wall may have zero or more beepers.
  • The robot must move along the street of beepers  to the Western boundary wall picking only those piles of beepers that have two beepers.  Empty intersections must remain empty and any pile of beepers that has more or less than two beepers must remain unpicked.
  • The robot must move to the origin (intersection 1,1) when beeper picking is finished.  Its final facing direction does not matter.

Testing:

Be sure to test your program on all four provided worlds (street1.txt,  street2.txt, street3.txt, and street4.txt).  There should be no error shutoffs in any of the four worlds.


Extra practice:
  • Ask the user on which street and avenue to start and have the robot start there.
  • Ask the user which direction the robot should start off facing.  (Note: this one is a lot more difficult.)

Handin:
  • None.