
/**
 * A Robot that fixes up a damaged survey by planting a beeper
 * on any corner where there is not one now and removing a beeper
 * from any corner that has one.
 * 
 * @author Russell C. Bjork 
 * @version January 9, 2006
 */
import kareltherobot.*;

public class SurveyFixerRobot extends Robot
{
    /** Constructor
     *
     *  @param street the starting street for this robot
     *  @param avenue the starting avenue for this robot
     *  @param direction the direction this robot is initially facing
     *  @param beepers the number of beepers this robot has initially
     */
    public SurveyFixerRobot(int street, int avenue, Direction direction, int beepers)
    {
        super(street, avenue, direction, beepers);
    }
    
    /** Perform the fixup task
     */
    public void fixupSurvey()
    {
		fixupOneStreet();
		moveToNextStreetOnLeft();
		fixupOneStreet();
		moveToNextStreetOnRight();
		fixupOneStreet();
		moveToNextStreetOnLeft();
		fixupOneStreet();
		moveToNextStreetOnRight();
		fixupOneStreet();
		moveToNextStreetOnLeft();
		fixupOneStreet();
		moveToNextStreetOnRight();
		fixupOneStreet();
		moveToNextStreetOnLeft();
		fixupOneStreet();
    }

    /** Fix up one street (8 avenues long)
     */
    public void fixupOneStreet()
    {
        fixupOneCorner();
        move();
        fixupOneCorner();
        move();
        fixupOneCorner();
        move();
        fixupOneCorner();
        move();
        fixupOneCorner();
        move();
        fixupOneCorner();
        move();
        fixupOneCorner();
        move();
        fixupOneCorner();
    }
        
    /** Move to the next street (to the left of the one just fixed)
     */
    public void moveToNextStreetOnLeft()
    {
        turnLeft();
        move();
        turnLeft();
    }
      
    /** Move to the next street (to the right of the one just fixed)
     */
    public void moveToNextStreetOnRight()
    {
        turnRight();
        move();
        turnRight();
    }
      
    /** Fix up one corner
     */
    public void fixupOneCorner()
    {
        if (nextToABeeper())
            pickBeeper();
        else
            putBeeper();
    }

    /** Turn right 90 degrees
     */
    public void turnRight()
    {
        turnLeft();
        turnLeft();
        turnLeft();
    }   
    
}