GRIDWORLD Question: Java experts needed ASAP!

<p>Hi guys so I'm trying to figure out the answer to this gridworld Free Response question (there's three parts a, b, and c) and need some major help! Can someone please provide the answers to the three parts and EXPLAIN how they got to their answer? I have an actual test on Monday so please help ASAP!</p>

<p>Here's the link to the GridWorld Question: <a href="http://www.scribd.com/doc/47785815/zigzag%5B/url%5D"&gt;http://www.scribd.com/doc/47785815/zigzag&lt;/a&gt;&lt;/p>

<p>I don’t have actual code (I don’t have gridworld atm), but I can explain how to answer it?</p>

<p>(a) First in your move() method, check if the bug can move by calling canMove()
If it it is true, check turnRight. If false, move your bug diagonally left (actors have that method built in using degrees: setDirection(int newDirection) OR using the Location class’s constants and then to move: moveTo(Location newLocation) ) check canMove() again, if it is true, turn right.</p>

<p>If canMove() returns false, call the turn() method then loop through what i just stated before. </p>

<p>(b)
THis is basically the same as the original bug’s canMove() method, just change the location that the bug is checking to the diagonal (left diagonal if turnRight==false, right if turnRight==true).</p>

<p>(c)
setDirection(HALF_CIRCLE);
is basically it. </p>

<p>I hope this helps >></p>

<p>Oh and you probably have the API and source code already, but I’ll link it for reference:
<a href=“College Board - SAT, AP, College Search and Admission Tools”>College Board - SAT, AP, College Search and Admission Tools;
[Generated</a> Documentation (Untitled)](<a href=“http://www.horstmann.com/gridworld/javadoc/]Generated”>Generated Documentation (Untitled))</p>

<p>



//~MatthewGrossman</p>

<p>import info.gridworld.actor.Bug;</p>

<p>public class ZigZagBug extends Bug {
    int counter = -1;</p>

<pre><code>public ZigZagBug(){
    turn();
}

public void act(){
    if(canMove()){
        moveTo(getLocation().getAdjacentLocation(getDirection()));
        setDirection(getDirection() + 90 + ((counter++)%2 * 180));
    }else{
        setDirection(getDirection() + 180);
    }
}
</code></pre>

<p>}

</p>

<p>What is the counter for?</p>

<p>Rather -</p>

<p>What is this for?


int counter = -1

and this?


setDirection(getDirection() + 90 + ((counter++)%2 * 180));

</p>