Advertisement
GARC923

C1

Nov 16th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. /*
  2. * Carlos Garcia
  3. * Challenge 1
  4. * OCD Karel
  5. * */
  6.  
  7. package Challenges;
  8. import kareltherobot.World;
  9.  
  10.  
  11. public class Challenge1 extends EsperBot1 {
  12.     public Challenge1(int street, int avenue, Direction direction, int beeperCount) {
  13.         super(street, avenue, direction, beeperCount);
  14.     }
  15.  
  16.  
  17.     public static void main(String[] args) {
  18.         World.setDelay(5);
  19.         World.setVisible();
  20.         World.setSize(10, 10);
  21.         World.showSpeedControl(true);
  22.         World.readWorld("KarelChallenges1.kwld");
  23.  
  24.         Challenge1 zgod = new Challenge1(1, 6, North, -1);
  25.  
  26.         zgod.OCD();
  27.     }
  28.     public void OCD(){
  29.         int hallwayLength = measureHallway();
  30.         while (frontIsClear()){
  31.             if (leftIsClear()) {
  32.                 turnLeft();
  33.                 int distance = leftEnd(); // goes to the end of the cubby
  34.                 turnLeft();
  35.                 turnLeft();
  36.                 if (nextToABeeper()) {
  37.                     int mirrorDistance = (distance * 2) + hallwayLength;
  38.                     for (int i = 0; i < mirrorDistance; i++) {
  39.                         move(); // goes to the opposite cubby if there is a beeper
  40.                     }
  41.                     turnLeft();
  42.                     turnLeft();
  43.                     if (!nextToABeeper()) {
  44.                         putBeeper(); // mirrors the beeper if there isn't one already
  45.                     }
  46.                     int returnDistance = distance + hallwayLength;
  47.                     for (int i = 0; i < returnDistance; i++) {
  48.                         move(); //goes back to the stating avenue
  49.                     }
  50.                     turnRight();
  51.                 } else{
  52.                     for (int i = 0; i < distance; i++) {
  53.                         move(); //goes out of the cubby
  54.                     }
  55.                     turnLeft();
  56.                 }
  57.                 distance = 0; // resets the distance
  58.             }
  59.             move();
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement