Back to Problem Set 4
Task 1 Notes, Hints, Suggestions
- To save yourself time, think carefully about your strategy
before writing any code! Draw lots of pictures and convince
yourself that it works. You are encouraged to develop the strategy
with your classmates, but you must code it on your own.
- You are encouraged to define any auxiliary
Followermethods 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, it is a good idea to define a helper method with the following specification:public boolean isBagelInFront();
Returnstrueif there is a cell with a bagel in front of this buggle andfalseotherwise.This method is similar to the
isFacingTrail()method presented in Lecture #9.It is also a good idea to define methods that check for a bagel to the left or right of a buggle.
- You should not need to write very much code to implement your
strategy. Our solution for the
tick()method takes less than 20 lines, much of which is whitespace, comments, and method headers.
- Strive to make your code as readable and understandable as
possible. Use meaningful method and variable names. Use comments
where appropriate. (Do not comment every line. Only use
comments to explain aspects of the code that are not immediately
obvious.)
- The default grid size is 15×15. You may find it helpful to debug
your strategy in a smaller grid. You can set the grid size by
changing the arguments to
setDimensions()method within thesetup()method of theFollowWorldclass. - The paths are randomly generated by a so-called psuedo-random number generator. The generator is initialized with a seed value that guarantees that you will get the exact same random sequence of paths every time you run the program. This aids debuggability.