Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. import stanford.karel.*;
  2.  
  3. public class CheckerboardKarel extends SuperKarel {
  4.     public void run() {
  5.         while (frontIsClear()) {
  6.             putBeeper();
  7.             advancedMove();
  8.             advancedMove();
  9.         }
  10.     }
  11.     private void advancedMove() {
  12.         if (frontIsClear()) {
  13.             move();
  14.         } else {
  15.             if (facingNorth()) {
  16.                
  17.             } else {
  18.                 if (facingEast()) {
  19.                     turnLeft();
  20.                     if (frontIsClear()) {
  21.                         move();
  22.                         turnLeft();
  23.                     }
  24.                 } else {
  25.                     if (facingWest()) {
  26.                         turnRight();
  27.                         if (frontIsClear()) {
  28.                             move();
  29.                             turnRight();
  30.                         }
  31.                     }
  32.                 }
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement