![]() |
Problem Set 4 |
Problem 1 Notes, Hints, Suggestions
Follower
methods that you find helpful. In particular,
you may find it helpful to define methods that return a boolean
value indicating the position of the next bagel relative to the
buggle's current position and heading. For example, here is a
method indicating if the next bagel is in front of the buggle:
public boolean isBagelInFront () { if (isFacingWall()) { return false; } else { brushUp(); // don't change the state of the environment during inquiry forward(); boolean result = isOverBagel(); backward(); brushDown(); // return to original state before inquiry return result; } }
You might also want methods that check for a bagel to the left or right of a buggle.
tick()
method takes less
than 20 lines, much of which is whitespace, comments, and method
headers.
setDimensions()
method within
the setup()
method of the FollowWorld
class, as shown below. Note: this problem requires that both
columns and rows be odd numbers.
public void setup() { setDimensions(columns,rows); }