Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Winstone Yang October 26
- import edu.fcps.karel2.Robot;
- import edu.fcps.karel2.Display;
- public class Sideback extends Athlete implements Runnable
- {
- public Sideback()
- {
- super(1, 1, Display.NORTH, 0);
- }
- public Sideback(int x, int y)
- {
- super(x, y, Display.NORTH, 0);
- }
- public void run()
- {
- if(Math.random() < 0.5)
- {
- turnRight();
- while(!nextToABeeper())
- {
- while(frontIsClear() && !rightIsClear())
- {
- if(frontIsClear() && !rightIsClear() && !nextToABeeper())
- move();
- }
- if(!frontIsClear())
- turnLeft();
- while(frontIsClear() && !rightIsClear())
- move();
- if(!frontIsClear())
- turnLeft();
- while(frontIsClear() && !rightIsClear())
- move();
- if(rightIsClear())
- {
- turnRight();
- move();
- if(!nextToABeeper())
- turnRight();
- }
- while(frontIsClear() && !nextToABeeper())
- move();
- if(!frontIsClear())
- turnLeft();
- }
- }
- else
- {
- turnLeft();
- while(!nextToABeeper())
- {
- while(frontIsClear() && !leftIsClear())
- {
- if(frontIsClear() && !leftIsClear() && !nextToABeeper())
- move();
- }
- if(!frontIsClear())
- turnRight();
- while(frontIsClear() && !leftIsClear())
- move();
- if(leftIsClear())
- {
- turnLeft();
- move();
- if(!nextToABeeper())
- turnLeft();
- }
- while(frontIsClear() && !nextToABeeper())
- move();
- if(!frontIsClear())
- turnRight();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement