CSE 111, Fall 2004

findbeeper.kp


beginning-of-program

   define-new-instruction about-face as
   begin
      turnleft;
      turnleft;
   end;

   define-new-instruction face-north as
   begin
      while not-facing-north do
         turnleft;
   end;

   define-new-instruction face-south as
   begin
      while not-facing-south do
         turnleft;
   end;

   define-new-instruction face-east as
   begin
      while not-facing-east do
         turnleft;
   end;

   define-new-instruction face-west as
   begin
      while not-facing-west do
         turnleft;
   end;

   define-new-instruction go-to-wall as
   begin
      while front-is-clear do
         move;
   end;

   define-new-instruction move-1-block-north as
   begin
      move;
   end;

   define-new-instruction move-1-block-south as
   begin
      move;
   end;

   define-new-instruction move-1-block-east as
   begin
      move;
   end;

   define-new-instruction move-1-block-west as
   begin
      move;
   end;

   define-new-instruction go-to-next-diagonal as
   begin
      if facing-west then
         
face-north
      else face-east;
      move;
      about-face;
   end;

   define-new-instruction zag-down-right as
   begin
      
move-1-block-south;
      face-east;
      move-1-block-east;
      face-south;
   end;

   define-new-instruction zig-left-up as
   begin
      
move-1-block-west;
      face-north;
      move-1-block-north;
      face-west;
   end;

   define-new-instruction zag-move as
   begin
      if front-is-clear then
         
zag-down-right
      else go-to-next-diagonal;
   end;

   define-new-instruction zig-move as
   begin
      if front-is-clear then
         
zig-left-up
      else go-to-next-diagonal;
   end;

   define-new-instruction go-to-origin as
   begin
      
face-west;
      go-to-wall;
      face-south;
      go-to-wall;
   end;

   define-new-instruction find-beeper as
   begin
      
go-to-origin;
      face-west;
      while not-next-to-a-beeper do
      begin
         if facing-west then
            zig-move
         else zag-move;
      end;
   end;

   beginning-of-execution
      find-beeper;
      pickbeeper;
      go-to-origin;
      putbeeper;
      turnoff;
   end-of-execution

end-of-program



Copyright © 2004 by William J. Rapaport (rapaport@cse.buffalo.edu)
file: 111F04/findbeeper-2004-11-23.html