dLife Microworld Example

 

public class TurnRightController extends SimpleWorldRobotController {


    public void step(SimpleWorldRobot robot) {

        if (robot.getFrontColor() == SimpleWorld.NONE ||

           (robot.getFrontColor() == SimpleWorld.GREEN &&

            robot.getSmell() == SimpleWorld.SWEET)) {

            robot.moveForward();

        }

        else {

            robot.rotateRight();

        }

    }

}

The example below, for use with the ControlCenter, causes the microworld robot to move forward, consuming food when possible and to turn right when faced with an obstacle, predator or poison.  In order to be used with the ControlCenter this class extends dlife.robot.MicroWorldRobotController and provides one method:

  1. step: This method is executed repeatedly by the ControlCenter after the Run button is clicked.  It accesses microworld robot’s sensors and decides on an action.

Similar code could be used to perform microworld simulations a stand-alone Java program.