Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Two robots pick up piles of beepers.
- * The "top" robot picks up piles that have exactly two beepers.
- * The "bottom" robot picks up piles that do NOT have exactly two beepers.
- Written by Scott McElfresh
- */
- package kareltherobot;
- public class PilesOfTwo implements Directions
- {
- public static void main(String[] args)
- {
- World.readWorld("street2.txt");
- World.setVisible(true);
- World.setTrace(false);
- World.setDelay(10);
- LabRobot topRobot = new LabRobot(5,10,West,0);
- while (topRobot.frontIsClear())
- {
- topRobot.move();
- if (topRobot.exactlyTwoBeepersHere())
- {
- topRobot.pickBeeper();
- topRobot.pickBeeper();
- }
- }
- topRobot.turnLeft();
- while (topRobot.frontIsClear())
- topRobot.move();
- topRobot.turnOff();
- LabRobot bottomRobot = new LabRobot(3,10,West,0);
- while (bottomRobot.frontIsClear())
- {
- bottomRobot.move();
- if (! bottomRobot.exactlyTwoBeepersHere())
- {
- while (bottomRobot.nextToABeeper())
- bottomRobot.pickBeeper();
- }
- }
- bottomRobot.turnLeft();
- while (bottomRobot.frontIsClear())
- bottomRobot.move();
- bottomRobot.turnOff();
- }
- }
Add Comment
Please, Sign In to add comment