Class Vroomba

java.lang.Object
  extended by Vroomba

public class Vroomba
extends Object

A Vroomba models a virtual robotic vacuum cleaner.

Vroombas are usually used to clean a Room. A Vroomba is always on, so any DIRT it moves over is always removed, leaving spotlessly clean FLOORs behind!

A Vroomba moves in a turn-based way, deciding which direction to head next each time its move method is called. Because its sensors are short-ranged, the move method only tells the Vroomba what is in its surrounding 8 "squares".

A Vroomba may or may not try to internally map the room based on the information it receives each move/turn. When a Vroomba believes the room to be clean, it may decline to move further. Not all Vroombas stop on their own, however; some just keep cleaning until turned off.

A variety of different Vroombas can be created by extending this class.

Version:
08 Nov 2008
Author:
Zach Tomaszewski
See Also:
Room, Direction

Constructor Summary
Vroomba()
           
 
Method Summary
 Direction move(char[] surroundings)
          Provides this Vroomba its current surroundings and asks it to choose a direction to move.
 void reset()
          Instructs this Vroomba to reset itself, such as when it is being transferred to a new room.
protected  void validateSurroundings(char[] surroundings)
          Handy for double-checking that passed surroundings are valid (though the only reason they wouldn't be is programmer error somewhere).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Vroomba

public Vroomba()
Method Detail

move

public Direction move(char[] surroundings)
               throws IllegalArgumentException
Provides this Vroomba its current surroundings and asks it to choose a direction to move.

The surroundings should contain 8 entries, for surroundings[Direction.N.ordinal()], surroundings[Direction.NE.ordinal()], surroundings[Direction.E.ordinal()], ... surroundings[Direction.NW.ordinal()]. Each character contained should be a valid feature of a Room.

This Vroomba will then return the Direction it would like to move. If it no longer wishes to move (usually because it believes its containing Room is clean), it may return Direction.HERE to stop.

This behavior will depend on the overriding performed by any specific, extending Vroomba. This default Vroomba always returns Direction.HERE.

Throws:
IllegalArgument - if the passed surroundings are invalid
IllegalArgumentException

reset

public void reset()
Instructs this Vroomba to reset itself, such as when it is being transferred to a new room.

This method currently does nothing. It needs to be overridden only by Vroombas that attempt to maintain state about the room they are currently in.


validateSurroundings

protected void validateSurroundings(char[] surroundings)
                             throws IllegalArgumentException
Handy for double-checking that passed surroundings are valid (though the only reason they wouldn't be is programmer error somewhere).

Returns if everything's fine, or throws an IllegalArgumentException if not.

Throws:
IllegalArgumentException
See Also:
move(char[])