Before writing any code, you should think carefully about the kinds of "before and after" rules your buggle should be following. That is, describe the buggle motion in terms of rules like "if the buggle is in configuration A before its move, it should be in configuration B after its move." For example, what should the buggle do when there is a wall to its right? when there is not a wall to its right? when there is a wall in front of it? when there is not a wall in front of it? These conditions are not orthogonal; e.g., the buggle may have a wall both in front of it and to its right.
Try to narrow the number of rules into the smallest number that implement a correct strategy. We strongly encourage you to work with your classmates on this part of the problem.
Once you have figured out a strategy, you should encode that strategy in Java code in the body of the tick() method within DeadEndWorld.java. As always, you should feel free to define any auxiliary methods that you find helpful. In this problem, it is particularly helpful to define the following auxiliary method:
public boolean isWallToRight()
Returns true if there is a wall directly to the right of this buggle, and false otherwise. When this method returns, this buggle should have exactly the same position and heading as it did before the method was called.
It is possible to write a clear and correct solution to this problem in remarkably few lines of code. If you find yourself lost in a rats nest of conditionals, you are probably on the wrong track.
You may want to be able to check if your buggle is headed in a
particular direction. The expression to determine if your buggle is
facing the Direction defined as EAST follows:
this
.getHeading().equals(Direction.EAST)
Here's one suggestion for how to break the problem down into
smaller pieces:
Note that the last goal above is tricky! So, be sure to finish at least the first two goals before spending a lot of time on the last goal. Some things to consider about the last goal: