/**
 * This class describes a simple robot that can move forward, turn 90
 * degree to the left and to the right, and test the possibility of a
 * forward move.  The robot has a <a name="#direction"><b>direction</b></a>: it
 * looks either to the north, east, south, or west. In this program,
 * the direction is presented by an integer: <ul> <li>The direction is
 * North if <em>direction mod 4 == 0</em></li> <li>The direction
 * is East if <em>direction mod 4 == 1</em></li> <li>The direction
 * is South if <em>direction mod 4 == 2</em></li> <li>The
 * direction is West if <em>direction mod 4 == 3</em></li> </ul>
 * */

public class Robot implements Labeled {
    int direction;
    Room room;

    /**
     * Creates a new robot that looks to the given <a
     * href="#direction">direction</a>.  */
    public Robot(int direction) {
	this.direction = direction;
    }

    /**
     * In which room is this robot located at?
     * @return the current room containing the robot or
     * <code>null</code> if the robot is in no room.
     */
    public Room getRoom() {
	return room;
    }

    /**
     * Sets the room in which this robot is located at.
     * @param room	the new location of this robot.
     */
    public void setRoom(Room room) {
	this.room = room;
	if (!room.containsObject(this)) {
	    room.addObject(this);
	}
    }

    /**
     * <b>You should implement this in exercise 2.1</b>.  Can this
     * robot move forwards?
     * @return <code>true</code> if a forward move is possible and
     * <code>false</code> if it is not.  */
    public boolean testForward() {
	/* Insert the code here */
    }

    /**
     * <b>You should implement this in exercise 2.1</b>.  Move the
     * robot forwards if it is possible.
     * @return <code>true</code> if a forward move is possible and
     * <code>false</code> if it is not.  */
    public boolean stepForward() {
	/* Insert the code here */
    }

    /**
     * <b>You should implement this in exercise 2.1</b>.  Turn the
     * <a href="#direction">direction</a> of the robot 90 degrees to the left
     * (counterclockwise).  */
    public void turnLeft() {
	/* Insert the code here */
    }

    /**
     * <b>You should implement this in exercise 2.1</b>.  Turn the <a
     * href="#direction">direction</a> of the robot 90 degrees to the
     * right (clockwise).  */
    public void turnRight() {
	/* Insert the code here */
    }

    /**
     * One letter string describing the <a
     * href="#direction">direction</a> of this robot.
     * @return "^" if the robot is looking to the North, ">" if the
     * robot is looking to the East, "v" if the robot is looking to
     * the South, and "<" if the robot is looking to the West.  */
    public String label() {
	if (direction % 4 == 0) {
	    return "^";
	} else if (direction % 4 == 1) {
	    return ">";
	} else if (direction % 4  == 2) {
	    return "v";
	} else {
	    return "<";
	}
    }

    /**
     * Redefine the predefined <code>toString</code> method.
     * @return a string describing this robot
     */
    public String toString() {
	return "Robot(" + label() + ", " + room + ")";
    }

    /**
     * The method tries to move this robot from the current room to
     * the goal room in a maze.  This method should be redefined in
     * the subclasses of Robot.
     * @param m a maze containing the robot
     * @param goal the goal room */
    public void solve(Maze m, Room goal) {}

}
