Robots and Beepers

Robots can pick up and deposit beepers. It uses the instructions:

Picking up beepers

Once a robot is over a beeper it can pick it up:

Collector.java
//
// Pick up Beepers

public class Collector
{
   public static void main(String [] args)
   {
      World table = new World();

      addBeeper(2, 3);

      Robot greedy = new Robot();
      table.add(greedy);

      // Move to the beeper
      greedy.move();
      greedy.move();
      greedy.turnLeft();
      greedy.move();
      greedy.move();
      greedy.move();

      greedy.pickBeeper();

      greedy.move();
   }
}

The robot moves to the beeper and picks it up. If you move the mouse pointer over the robot the status window will tell you how many beepers it's carrying.

Moving beepers

This robot picks up two beepers and drops them both in the same cell.

Mover.java
public class Mover
{
   public static void main(String [] args)
   {
      World field = new World();
      field.addBeeper(2, 2);
      field.addBeeper(2, 3);

      Robot jimmy = new Robot();
      field.add(jimmy);

      // Move to the beeper
      jimmy.move();
      jimmy.move();
      jimmy.turnLeft();
      jimmy.move();
      jimmy.move();

      jimmy.pickBeeper();
      jimmy.move();
      jimmy.pickBeeper();

      jimmy.move();
      jimmy.move();
      jimmy.putBeeper();
      jimmy.putBeeper();
      jimmy.move();
   }
}

Both beepers are picked up and placed on cell(2, 5). Note that two beepers look exactly the same as one beeper. The status window can tell you how many beepers are in the cell (if you move the mouse over the cell).

Spreading them out

Spreader.java
public class Spreader
{
   public static void main(String [] args)
   {
      World field = new World();
      field.addBeeper(2, 0);
      field.addBeeper(2, 0);
      field.addBeeper(2, 0);

      Robot jimmy = new Robot();
      field.add(jimmy);

      jimmy.move();
      jimmy.move();
      jimmy.pickBeeper();
      jimmy.pickBeeper();
      jimmy.pickBeeper();

      jimmy.move();
      jimmy.putBeeper();
      jimmy.move();
      jimmy.putBeeper();
      jimmy.move();
      jimmy.putBeeper();
   }
}

Cell(2, 0) has three beepers. The robot picks them up and then spreads them out in the cells (3, 1), (3, 2) and (3, 3).