alice.kareltherobot
Class WallFollower

java.lang.Object
  extended by edu.cmu.cs.dennisc.pattern.DefaultReleasable
      extended by edu.cmu.cs.dennisc.pattern.AbstractElement
          extended by edu.cmu.cs.dennisc.pattern.DefaultInstancePropertyOwner
              extended by org.alice.apis.moveandturn.Element
                  extended by org.alice.apis.moveandturn.Composite
                      extended by org.alice.apis.moveandturn.AbstractTransformable
                          extended by org.alice.apis.moveandturn.Transformable
                              extended by org.alice.apis.moveandturn.Model
                                  extended by org.alice.apis.moveandturn.PolygonalModel
                                      extended by org.alice.apis.moveandturn.gallery.GalleryModel
                                          extended by org.alice.apis.moveandturn.gallery.scifi.KoalaRobot
                                              extended by alice.kareltherobot.UrRobot
                                                  extended by alice.kareltherobot.Robot
                                                      extended by alice.kareltherobot.WallFollower
All Implemented Interfaces:
edu.cmu.cs.dennisc.codec.ReferenceableBinaryEncodableAndDecodable, edu.cmu.cs.dennisc.pattern.Nameable, edu.cmu.cs.dennisc.pattern.NameChangeListenable, edu.cmu.cs.dennisc.pattern.Releasable, edu.cmu.cs.dennisc.property.InstancePropertyOwner, edu.cmu.cs.dennisc.property.PropertyOwner, org.alice.apis.moveandturn.ReferenceFrame

public class WallFollower
extends alice.kareltherobot.Robot

A robot that follows a wall using the right-hand rule and thus escapes from a maze that has no traps (a connected maze).

Author:
Cay Horstmann, updated by Joe Bergin

Nested Class Summary
 
Nested classes/interfaces inherited from class org.alice.apis.moveandturn.gallery.scifi.KoalaRobot
org.alice.apis.moveandturn.gallery.scifi.KoalaRobot.Part
 
Field Summary
 
Fields inherited from class org.alice.apis.moveandturn.gallery.GalleryModel
MODELED_BY_CREDIT_PROPERTY, PAINTED_BY_CREDIT_PROPERTY, PROGRAMMED_BY_CREDIT_PROPERTY
 
Fields inherited from class org.alice.apis.moveandturn.PolygonalModel
POLYGONS_PROPERTY
 
Fields inherited from class org.alice.apis.moveandturn.Model
COLOR_PROPERTY, FILLING_STYLE_PROPERTY, IS_BOUNDING_BOX_SHOWING_PROPERTY, IS_BOUNDING_SPHERE_SHOWING_PROPERTY, IS_SHOWING_PROPERTY, OPACITY_PROPERTY, POTENTIAL_SURFACE_TEXTURES_PROPERTY, SHADING_STYLE_PROPERTY, SURFACE_TEXTURE_PROPERTY, VISUAL_SCALE_PROPERTY
 
Fields inherited from class org.alice.apis.moveandturn.Transformable
DEFAULT_ORIGIN_INCLUSION_POLICY, DEFAULT_RESIZE_POLICY, DEFAULT_SET_SIZE_POLICY
 
Fields inherited from class org.alice.apis.moveandturn.AbstractTransformable
LOCAL_POINT_OF_VIEW_PROPERTY
 
Fields inherited from class org.alice.apis.moveandturn.Composite
COMPONENTS_PROPERTY, DEFAULT_DURATION, DEFAULT_HOW_MUCH, DEFAULT_SPEED_STYLE, DEFAULT_STYLE, RIGHT_NOW
 
Fields inherited from class org.alice.apis.moveandturn.Element
NAME_PROPERTY
 
Constructor Summary
WallFollower(int street, int avenue, alice.kareltherobot.Direction direction)
          Create a robot on a specific street and avenue, facing a given direction with no beepers.
WallFollower(int street, int avenue, alice.kareltherobot.Direction direction, int beepers)
          Create a robot on a specific street and avenue, facing a given direction with a given number of beepers.
WallFollower(int street, int avenue, alice.kareltherobot.Direction direction, int beepers, org.alice.apis.moveandturn.Color color)
          Create a robot on a specific street and avenue, facing a given direction with a given number of beepers and a given body color.
 
Method Summary
 void followWallRight()
          Follow the wall to the right.
 boolean rightIsClear()
          Return true if there is no wall to the immediate right of this robot
 void step()
          Make one step of progress toward the goal.
 void turnRight()
          Turns this robot right.
 
Methods inherited from class alice.kareltherobot.Robot
anyBeepersInBeeperBag, facingEast, facingNorth, facingSouth, facingWest, frontIsClear, nextToABeeper, nextToARobot
 
Methods inherited from class alice.kareltherobot.UrRobot
addToWorld, assertFacingEast, assertFacingNorth, assertFacingSouth, assertFacingWest, assertFrontIsBlocked, assertFrontIsClear, assertHasBeepers, assertHasNoBeepers, assertNextToABeeper, assertNextToARobot, assertOnAvenue, assertOnStreet, draw, getCamera, move, pickBeeper, putBeeper, setTracing, toString, turnLeft, turnOff
 
Methods inherited from class org.alice.apis.moveandturn.gallery.scifi.KoalaRobot
getPart
 
Methods inherited from class org.alice.apis.moveandturn.gallery.GalleryModel
getGalleryRootDirectory, getModeledByCredit, getPaintedByCredit, getProgrammedByCredit, main, setModeledByCredit, setPaintedByCredit, setProgrammedByCredit
 
Methods inherited from class org.alice.apis.moveandturn.PolygonalModel
getPolygons, setPolygons
 
Methods inherited from class org.alice.apis.moveandturn.Model
addMouseButtonListener, addPotentialSurfaceTexture, clearPotentialSurfaceTextures, getColor, getFillingStyle, getMouseButtonListeners, getOpacity, getOriginalScale, getPart, getPotentialSurfaceTextureIterable, getPotentialSurfaceTextures, getResizeDepthAmount, getResizeHeightAmount, getResizeWidthAmount, getSGSingleAppearance, getSGVisual, getShadingStyle, getSurfaceTexture, getVisualScale, isShowing, removeMouseButtonListener, removePotentialSurfaceTexture, setColor, setColor, setColor, setColor, setFillingStyle, setName, setOpacity, setOpacity, setOpacity, setOpacity, setPotentialSurfaceTextures, setShadingStyle, setShowing, setSurfaceTexture, setVisualScale
 
Methods inherited from class org.alice.apis.moveandturn.Transformable
addKeyListener, getAxisAlignedMinimumBoundingBox, getAxisAlignedMinimumBoundingBox, getAxisAlignedMinimumBoundingBox, getAxisAlignedMinimumBoundingBox, getBoundingSphere, getBoundingSphere, getBoundingSphere, getBoundingSphere, getDepth, getDistanceAbove, getDistanceBehind, getDistanceBelow, getDistanceInFrontOf, getDistanceTo, getDistanceToTheLeftOf, getDistanceToTheRightOf, getHeight, getKeyListeners, getSGAbstractTransformable, getSGTransformable, getVehicle, getWidth, isAbove, isAbove, isAtLeastThresholdAwayFrom, isBehind, isBehind, isBelow, isBelow, isBoundingBoxShowing, isBoundingSphereShowing, isInFrontOf, isInFrontOf, isLargerThan, isNarrowerThan, isShorterThan, isSmallerThan, isTallerThan, isThickerThan, isThinnerThan, isToTheLeftOf, isToTheLeftOf, isToTheRightOf, isToTheRightOf, isWiderThan, isWithinThresholdOf, realizeIfNecessary, removeKeyListener, resize, resize, resize, resize, resizeDepth, resizeDepth, resizeDepth, resizeDepth, resizeDepth, resizeHeight, resizeHeight, resizeHeight, resizeHeight, resizeHeight, resizeWidth, resizeWidth, resizeWidth, resizeWidth, resizeWidth, say, say, say, say, say, say, setBoundingBoxShowing, setBoundingSphereShowing, setDepth, setDepth, setDepth, setDepth, setDepth, setHeight, setHeight, setHeight, setHeight, setHeight, setVehicle, setWidth, setWidth, setWidth, setWidth, setWidth, think, think, think, think, think, think
 
Methods inherited from class org.alice.apis.moveandturn.AbstractTransformable
getLocalPointOfView, getLocalTransformation, getOrientation, getOwner, getPosition, getScene, getSGComposite, getTransformation, getTransformation, isPivotShowing, move, move, move, move, moveAndOrientTo, moveAndOrientTo, moveAndOrientTo, moveAtSpeed, moveAtSpeed, moveAtSpeed, moveAwayFrom, moveAwayFrom, moveAwayFrom, moveTo, moveTo, moveTo, moveToward, moveToward, moveToward, orientTo, orientTo, orientTo, orientToUpright, orientToUpright, orientToUpright, orientToUpright, pointAt, pointAt, pointAt, roll, roll, roll, roll, rollAtSpeed, rollAtSpeed, rollAtSpeed, setLocalPointOfView, setLocalTransformation, setPivotShowing, turn, turn, turn, turn, turnAtSpeed, turnAtSpeed, turnAtSpeed, turnToFace, turnToFace, turnToFace
 
Methods inherited from class org.alice.apis.moveandturn.Composite
addComponent, clearComponents, createOffsetStandIn, createOffsetStandIn, createOffsetStandIn, createOffsetStandIn, createOffsetStandIn, createOffsetStandIn, createOffsetStandIn, createOffsetStandInIfNecessary, delay, findAllMatches, findAllMatches, findAllMatches, findAllMatches, findAllMatches, findFirstDescendantNamed, findFirstMatch, findFirstMatch, findFirstMatch, findFirstMatch, findPathsToAllDescendants, getActualReferenceFrame, getBooleanFromUser, getComponentIterable, getComponents, getDescendant, getDoubleFromUser, getGlobalSimulationSpeedFactor, getIntegerFromUser, getLookingGlass, getName, getPointOfView, getSGReferenceFrame, getStringFromUser, print, removeComponent, setComponents, setGlobalSimulationSpeedFactor, transformFromAWT, transformFromAWT, transformToAWT, transformToAWT
 
Methods inherited from class org.alice.apis.moveandturn.Element
getElement, isComposedOfGetterAndSetterProperties
 
Methods inherited from class edu.cmu.cs.dennisc.pattern.DefaultInstancePropertyOwner
accessListPropertyListeners, accessPropertyListeners, addListPropertyListener, addPropertyListener, decode, encode, equals, fireAdded, fireAdding, fireCleared, fireClearing, firePropertyChanged, firePropertyChanging, fireRemoved, fireRemoving, fireSet, fireSetting, getInstancePropertyNamed, getProperties, getPropertyNamed, isEquivalentTo, lookupNameFor, removeListPropertyListener, removePropertyListener
 
Methods inherited from class edu.cmu.cs.dennisc.pattern.AbstractElement
accessNameListeners, addNameListener, removeNameListener
 
Methods inherited from class edu.cmu.cs.dennisc.pattern.DefaultReleasable
accessReleaseListeners, addReleaseListener, release, removeReleaseListener
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WallFollower

public WallFollower(int street,
                    int avenue,
                    alice.kareltherobot.Direction direction)
Create a robot on a specific street and avenue, facing a given direction with no beepers.

Parameters:
street - the street on which to place the robot
avenue - the avenue on which to place the robot
direction - the direction the robot will initially face

WallFollower

public WallFollower(int street,
                    int avenue,
                    alice.kareltherobot.Direction direction,
                    int beepers)
Create a robot on a specific street and avenue, facing a given direction with a given number of beepers.

Parameters:
street - the street on which to place the robot
avenue - the avenue on which to place the robot
direction - the direction the robot will initially face
beepers - the initial number of beepers in the beeper bag

WallFollower

public WallFollower(int street,
                    int avenue,
                    alice.kareltherobot.Direction direction,
                    int beepers,
                    org.alice.apis.moveandturn.Color color)
Create a robot on a specific street and avenue, facing a given direction with a given number of beepers and a given body color.

Parameters:
street - the street on which to place the robot
avenue - the avenue on which to place the robot
direction - the direction the robot will initially face
beepers - the initial number of beepers in the beeper bag
color - the color of this robot
Method Detail

turnRight

public void turnRight()
Turns this robot right.


rightIsClear

public boolean rightIsClear()
Return true if there is no wall to the immediate right of this robot

Returns:
true if the right has no wall

followWallRight

public void followWallRight()
Follow the wall to the right. Precondition. The robot must be in contact with the wall initially.


step

public void step()
Make one step of progress toward the goal. Moving a minimal amount and turning as necessary to keep the wall to the right. Returns if a beeper is found along the way.