dLife Home Page

dlife.models.simpleworld
Class SimpleWorldRobot

java.lang.Object
  extended by java.util.Observable
      extended by dlife.robot.Robot
          extended by dlife.models.simpleworld.SimpleWorldRobot

public class SimpleWorldRobot
extends Robot

Robot for use in the SimpleWorld microworld. See the documentation for the dlife.models.simpleworld package for information about the use of this class. In addition, several examples of SimpleWorldRobotControllers can be found in the examples.dlife.models.simpleworld package.

Version:
Sep 29, 2010
Author:
Grant Braught, Dickinson College
See Also:
SimpleWorld, SimpleWorldRobotController, examples.dlife.models.simpleworld

Constructor Summary
SimpleWorldRobot()
          Construct a new SimpleWorldRobot with parameters provided by the user via a dialog box.
SimpleWorldRobot(SimpleWorld theWorld, int lifeForce)
          Construct a new SimpleWorldRobot for the provided SimpleWorld.
SimpleWorldRobot(SimpleWorld theWorld, int lifeForce, double smellErrorProb, int smellRange, double colorErrorProb, int colorRange)
          Construct a new SimpleWorldRobot for the provided SimpleWorld.
 
Method Summary
(package private)  void decLifeForce(int amt)
          Decrease the robot's life force.
 double getColorErrorProb()
          Get the probability that this SimpleWorldRobot's color sensors will return an incorrect value.
 int getColorRange()
          Get the range of the color sensors for this SimpleWorldRobot.
 int getFrontColor()
          Get the value of the robot's front color sensor.
 int getLeftColor()
          Get the value of the robot's left color sensor.
 int getLifeForce()
          Get this SimpleWorldRobot's life force.
 int getRightColor()
          Get the value of the robot's right color sensor.
 Device getSensor()
          Get the sensor device that the robot uses to sense the world.
 int getSmell()
          Get the value of the robot's smell sensor.
 double getSmellErrorProb()
          Get the probability that this SimpleWorldRobot's smell sensor will return an incorrect value.
 int getSmellRange()
          Get the range of the smell sensor for this SimpleWorldRobot.
 boolean hasLifeForce()
          Check if this SimpleWorldRobot has any remaining life force.
(package private)  void incLifeForce(int amt)
          Increase the robot's life force.
 void moveForward()
          Move the robot forward one cell in the SimpleWorld.
 void resetLifeforce()
          Reset this robot's life force to its initial value.
 void rotateLeft()
          Rotate the robot to its left by 90 degrees in the SimpleWorld.
 void rotateRight()
          Rotate the robot to its right by 90 degrees in the SimpleWorld.
 boolean runningWithGUI()
          Check if this SimpleWorldRobot is running with a GUI or not.
 int runRobotNoGUI(SimpleWorldRobotController controller, int steps)
          Run the robot without displaying the GUI.
 int runRobotWithGUI(SimpleWorldRobotController controller, int steps)
          Run the robot with the GUI displayed.
 String sendMessage(String msg)
          This method is unused by the SimpleWorldRobot.
(package private)  void setLifeForce(int value)
          Set the robot's life force.
 void startUp()
          Add sensors and effectors to this robot.
 
Methods inherited from class dlife.robot.Robot
addDevice, freeze, getDevices, getRunTime, isAlive, removeDevice, setAlive, shutDown
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleWorldRobot

public SimpleWorldRobot()
Construct a new SimpleWorldRobot with parameters provided by the user via a dialog box.


SimpleWorldRobot

public SimpleWorldRobot(SimpleWorld theWorld,
                        int lifeForce)
Construct a new SimpleWorldRobot for the provided SimpleWorld. The sensor error probabilities and ranges are set to the following default values.

Parameters:
theWorld - the SimpleWorld that will be inhabited by the new robot.
lifeForce - the amount of life force the robot begins with.

SimpleWorldRobot

public SimpleWorldRobot(SimpleWorld theWorld,
                        int lifeForce,
                        double smellErrorProb,
                        int smellRange,
                        double colorErrorProb,
                        int colorRange)
Construct a new SimpleWorldRobot for the provided SimpleWorld.

Parameters:
theWorld - the SimpleWorld that will be inhabited by the new robot.
lifeForce - the amount of life force the robot begins with.
smellErrorProb - the probability of an error in the smell sensor reading.
smellRange - the range of the smell sensor.
colorErrorProb - the probability of an error in the color sensor reading.
colorRange - the range of the color sensor.
Method Detail

startUp

public void startUp()
Add sensors and effectors to this robot. There are 2 sensors, one displays the world and one displays the sensor readings of the robot. There is one effector that allows the robot to be moved around in the world.

Overrides:
startUp in class Robot

resetLifeforce

public void resetLifeforce()
Reset this robot's life force to its initial value.


getSensor

public Device getSensor()
Get the sensor device that the robot uses to sense the world. This method is provided so that the SimpleWorldRobotController class can invoke the update method on the device before invoking step when the GUI is not being used.

Returns:
the Robot's SimpleWorldRobotSensor.

moveForward

public void moveForward()
Move the robot forward one cell in the SimpleWorld. If the robot is alive it is moved forward (if possible). If the robot is not alive this method has no effect. Moving forward consumes one unit of life force.


rotateRight

public void rotateRight()
Rotate the robot to its right by 90 degrees in the SimpleWorld. Rotating consumes one unit of life force. If the robot has no life force then this method will have no effect.


rotateLeft

public void rotateLeft()
Rotate the robot to its left by 90 degrees in the SimpleWorld. Rotating consumes one unit of life force. If the robot has no life force then this method will have no effect.


runningWithGUI

public boolean runningWithGUI()
Check if this SimpleWorldRobot is running with a GUI or not.

Returns:
true if the robot is running with a GUI and false if not.

getSmell

public int getSmell()
Get the value of the robot's smell sensor. See the SimpleWorld documentation for information on the values that may be returned.

Returns:
the robot's smell sensor value.

getLeftColor

public int getLeftColor()
Get the value of the robot's left color sensor. See the SimpleWorld documentation for information on the values that may be returned.

Returns:
the robot's left color sensor value.

getFrontColor

public int getFrontColor()
Get the value of the robot's front color sensor. See the SimpleWorld documentation for information on the values that may be returned.

Returns:
the robot's front color sensor value.

getRightColor

public int getRightColor()
Get the value of the robot's right color sensor. See the SimpleWorld documentation for information on the values that may be returned.

Returns:
the robot's right color sensor value.

sendMessage

public final String sendMessage(String msg)
This method is unused by the SimpleWorldRobot. The SimpleWorld provides methods that access to the sensor values and effector operations directly. Thus messages do not need to be sent.

Specified by:
sendMessage in class Robot
Parameters:
msg - the message to be sent to the robot.
Returns:
the robot's response to the message or null.

incLifeForce

final void incLifeForce(int amt)
Increase the robot's life force.

Parameters:
amt - the amount by which the life force should be increased.

decLifeForce

final void decLifeForce(int amt)
Decrease the robot's life force.

Parameters:
amt - the amount by which the life force should be decreased.

setLifeForce

final void setLifeForce(int value)
Set the robot's life force. This is useful for the reset operation.

Parameters:
value - the new lifeforce.

getLifeForce

public int getLifeForce()
Get this SimpleWorldRobot's life force.

Returns:
the life force.

hasLifeForce

public boolean hasLifeForce()
Check if this SimpleWorldRobot has any remaining life force.

Returns:
true if the life force is greater than 0 and false otherwise.

getSmellErrorProb

public double getSmellErrorProb()
Get the probability that this SimpleWorldRobot's smell sensor will return an incorrect value.

Returns:
the probability of a smell error.

getColorErrorProb

public double getColorErrorProb()
Get the probability that this SimpleWorldRobot's color sensors will return an incorrect value.

Returns:
the probability of a color sensing error.

getSmellRange

public int getSmellRange()
Get the range of the smell sensor for this SimpleWorldRobot.

Returns:
the range of the smell sensor.

getColorRange

public int getColorRange()
Get the range of the color sensors for this SimpleWorldRobot.

Returns:
the range of the color sensor.

runRobotNoGUI

public int runRobotNoGUI(SimpleWorldRobotController controller,
                         int steps)
Run the robot without displaying the GUI. The robot runs under control of the specified SimpleWorldRobotController for the specified number of steps (i.e. calls to the controller's step function) or until its lifeforce is depleted. The simulation will run much faster without the GUI displayed than with the GUI displayed.

If this robot's startUp method has not been invoked yet it will be invoked. The controller's startUp method will then be invoked to associate it with the robot. The controller's step method will then be invoked steps times or until the life force is depleted.

This method may be invoked multiple times on the same robot. When this is done it is equivalent to invoking the method once with the total number of steps. For example, the following calls:

is equivalent to the following single call:

Parameters:
controller - the SimpleWorldRobotController that is to be used to control the robot.
steps - the number of steps to run. Use -1 to run until lifeforce is depleted.
Returns:
the number of steps completed.
Throws:
Exception - if there is an exception starting the controller or invoking step.

runRobotWithGUI

public int runRobotWithGUI(SimpleWorldRobotController controller,
                           int steps)
Run the robot with the GUI displayed. This method displays the GUI for the World while the robot is running.

If this robot's startUp method has not been invoked yet it will be invoked. The GUI will then be displayed. The controller's startUp method will then be invoked to associate it with the robot. The controller's step method will then be invoked steps times or until the life force is depleted.

Parameters:
controller - the SimpleWorldRobotController that is to be used to control the robot.
steps - the number of steps to run. Use -1 to run until lifeforce is depleted.
Returns:
the number of steps completed.
Throws:
Exception - if there is an exception starting the controller or invoking step.

dLife Home Page