Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import stanford.karel.*;
- public class HW2Second extends SuperKarel{
- public void run(){
- while(true){
- while(frontIsClear()){
- move();
- }
- if(facingEast() && frontIsBlocked()&&rightIsBlocked()&&leftIsBlocked()){
- break;
- }
- if(facingEast() && frontIsBlocked() && leftIsBlocked()){
- break;
- }
- if(facingEast() && frontIsBlocked()&&rightIsBlocked()){
- turnLeft();
- }
- if(facingNorth() && frontIsBlocked()&&rightIsBlocked()){
- turnLeft();
- }
- if(facingWest() && frontIsBlocked()){
- turnRight();
- }
- if(facingNorth()&&frontIsBlocked()&&rightIsClear()){
- turnRight();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement