Guest User

Untitled

a guest
Jun 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. /*
  2. * Two robots pick up piles of beepers.
  3. * The "top" robot picks up piles that have exactly two beepers.
  4. * The "bottom" robot picks up piles that do NOT have exactly two beepers.
  5.  
  6. Written by Scott McElfresh
  7. */
  8.  
  9. package kareltherobot;
  10.  
  11.  
  12. public class PilesOfTwo implements Directions
  13. {
  14. public static void main(String[] args)
  15. {
  16. World.readWorld("street2.txt");
  17. World.setVisible(true);
  18. World.setTrace(false);
  19. World.setDelay(10);
  20.  
  21. LabRobot topRobot = new LabRobot(5,10,West,0);
  22.  
  23. while (topRobot.frontIsClear())
  24. {
  25. topRobot.move();
  26. if (topRobot.exactlyTwoBeepersHere())
  27. {
  28. topRobot.pickBeeper();
  29. topRobot.pickBeeper();
  30. }
  31. }
  32. topRobot.turnLeft();
  33. while (topRobot.frontIsClear())
  34. topRobot.move();
  35. topRobot.turnOff();
  36.  
  37.  
  38. LabRobot bottomRobot = new LabRobot(3,10,West,0);
  39.  
  40. while (bottomRobot.frontIsClear())
  41. {
  42. bottomRobot.move();
  43. if (! bottomRobot.exactlyTwoBeepersHere())
  44. {
  45. while (bottomRobot.nextToABeeper())
  46. bottomRobot.pickBeeper();
  47. }
  48. }
  49. bottomRobot.turnLeft();
  50. while (bottomRobot.frontIsClear())
  51. bottomRobot.move();
  52. bottomRobot.turnOff();
  53. }
  54.  
  55. }
Add Comment
Please, Sign In to add comment