RobotWorld Lab

Here is a blank RobotWorld which you may print out. It may help with the design of Robot Programs

In this lab you will write, compile and run some introductory RobotWorld problems.

  1. First setup RobotWorld.

  2. Create a file called OneBeeper.java which contains the following code.

    OneBeeper.java
    public class OneBeeper
    {
       public static void main(String [] args)
       {
          World space = new World();
    
          space.addBeeper(5, 2);
       }
    }

    Compile the program. (Type javac OneBeeper.java). If there are any errors, fix them. Run the program. (type java OneBeeper)

  3. Create a world that has a block in the centre completely surrounded by beepers as shown below.
  4. Write a program that makes a robot crash into an edge of the world. If the robot starts at cell(0, 0). What are the fewest number of instructions required to complete the task?

  5. Create a world with a beeper as shown below. Add a robot to the origin, get it to pick up the beeper and return to the origin and drop the beeper.

    What are the fewest number of instructions required to complete the task?

  6. Extra Credit (optional exercise)
    Create the world shown below and move the robot to the beeper.


  7. Extra Credit (optional exercise)
    The robot circus has come to town; and there are four performing robots who wander around in a circle following each other (these are really fascinating robots). After a complete round, these robots will all be back at their original positions. After a quarter round, they will all have taken the position of the robot in front of them.

    Write a program that places the four robots in the world, and then makes each do a quarter round.

    The robots start as shown below, after a quarter turn, they will each have taken the position of the robot in front of them (of course that robot will also have moved on).

    Note: to place a robot in a particular cell facing a particular direction, use a variation of the add method:
    world.add(robotname, x, y, "direction");

    where world is the name of the world, robotname is the name of the robot, x and y are the coordinates of the cell the robot is going to, "direction" is the direction that the robot is to face, one of "north", "south", "east" or "west".

    Here is an example code fragment using this method:

       World stage = new World();
       Robot pferdy = new Robot();
    
       // Place pferdy at cell (2, 8) facing north.
       stage.add(pferdy, 2, 8, "north");