Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Carlos Garcia
- * Challenge 1
- * OCD Karel
- * */
- package Challenges;
- import kareltherobot.World;
- public class Challenge1 extends EsperBot1 {
- public Challenge1(int street, int avenue, Direction direction, int beeperCount) {
- super(street, avenue, direction, beeperCount);
- }
- public static void main(String[] args) {
- World.setDelay(5);
- World.setVisible();
- World.setSize(10, 10);
- World.showSpeedControl(true);
- World.readWorld("KarelChallenges1.kwld");
- Challenge1 zgod = new Challenge1(1, 6, North, -1);
- zgod.OCD();
- }
- public void OCD(){
- int hallwayLength = measureHallway();
- while (frontIsClear()){
- if (leftIsClear()) {
- turnLeft();
- int distance = leftEnd(); // goes to the end of the cubby
- turnLeft();
- turnLeft();
- if (nextToABeeper()) {
- int mirrorDistance = (distance * 2) + hallwayLength;
- for (int i = 0; i < mirrorDistance; i++) {
- move(); // goes to the opposite cubby if there is a beeper
- }
- turnLeft();
- turnLeft();
- if (!nextToABeeper()) {
- putBeeper(); // mirrors the beeper if there isn't one already
- }
- int returnDistance = distance + hallwayLength;
- for (int i = 0; i < returnDistance; i++) {
- move(); //goes back to the stating avenue
- }
- turnRight();
- } else{
- for (int i = 0; i < distance; i++) {
- move(); //goes out of the cubby
- }
- turnLeft();
- }
- distance = 0; // resets the distance
- }
- move();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement