
/**
 * A Robot that replants missing beepers
 * 
 * @author Russell C. Bjork 
 * @version January 9, 2006
 */
import kareltherobot.*;

public class ReplanterRobot 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 ReplanterRobot(int street, int avenue, Direction direction, int beepers)
    {
        super(street, avenue, direction, beepers);
    }

   /** Perform the replanting task
     */
    public void replant()
    {
        checkFurrow();
        moveToNextFurrowOnLeft();
        checkFurrow();
        moveToNextFurrowOnRight();
        checkFurrow();
        moveToNextFurrowOnLeft();
        checkFurrow();
        moveToNextFurrowOnRight();
        checkFurrow();
        moveToNextFurrowOnLeft();
        checkFurrow();
    }
    
    /** Handle one furrow
     */
    public void checkFurrow()
    {
        replantBeeperIfNecessary();
        move();
        replantBeeperIfNecessary();
        move();
        replantBeeperIfNecessary();
        move();
        replantBeeperIfNecessary();
        move();
        replantBeeperIfNecessary();
    }
    
    /** Move to the next furrow (on the left)
     */
    public void moveToNextFurrowOnLeft()
    {
        turnLeft();
        move();
        turnLeft();
    }
      
    /** Move to the next furrow (on the right)
     */
    public void moveToNextFurrowOnRight()
    {
        turnRight();
        move();
        turnRight();
    }

    /** Replant a beeper if one is missing on the current corner
     */
    public void replantBeeperIfNecessary()
    {
        if (! nextToABeeper())
            putBeeper();
    }
      
 
    /** Turn right 90 degrees
     */
    public void turnRight()
    {
        turnLeft();
        turnLeft();
        turnLeft();
    }      
}



