Advertisement
Guest User

Karel

a guest
Sep 16th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import stanford.karel.*;
  2.  
  3. public class HW2Second extends SuperKarel{
  4.  
  5.     public void run(){
  6.        
  7.         while(true){
  8.            
  9.                                                                            
  10.         while(frontIsClear()){
  11.            
  12.             move();
  13.         }
  14.        
  15.         if(facingEast() && frontIsBlocked()&&rightIsBlocked()&&leftIsBlocked()){
  16.             break;
  17.         }
  18.        
  19.         if(facingEast() && frontIsBlocked() && leftIsBlocked()){
  20.             break;
  21.         }
  22.        
  23.         if(facingEast() && frontIsBlocked()&&rightIsBlocked()){
  24.             turnLeft();
  25.         }
  26.        
  27.         if(facingNorth() && frontIsBlocked()&&rightIsBlocked()){
  28.             turnLeft();
  29.         }
  30.        
  31.         if(facingWest() && frontIsBlocked()){
  32.             turnRight();
  33.         }
  34.        
  35.         if(facingNorth()&&frontIsBlocked()&&rightIsClear()){
  36.             turnRight();
  37.         }
  38.                                
  39.  
  40.         }
  41.         }
  42.                        
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement