RoBOTL

Sample Program 2


define
{
   /* classic C-style comment */
   WorldEntity pile_of_beepers
   {
      beeper at  0,0 =  2;  // ANSI C/C++ style single-line comment
      beeper at  1,0 =  1;
      beeper at  2,0 =  5;
      beeper at  3,0 =  3;
      beeper at  4,0 =  9;
      beeper at  5,0 =  2;
      beeper at  6,0 = 15;
      beeper at  7,0 =  4;
      beeper at  8,0 =  6;
      beeper at  9,0 =  8;
      beeper at 10,0 = 12;
   }
   NewRobotType smart_bot
   {
      IsLikeA basic_bot;
      DefineInitialBeepers 1;
      DefineNewInstruction face_north as 
            while (not FacingNorth) TurnLeft;
      DefineNewInstruction face_south as 
            while (not FacingSouth) TurnLeft;
      DefineNewInstruction face_east as 
            while (not FacingEast) TurnLeft;
      DefineNewInstruction face_west as 
            while (not FacingWest) TurnLeft;
      DefineInteger startx;
      DefineNewInstruction move_to_origin as
      {
         /* this assumes no blocks or walls exist except 
         the outer boundaries */
         face_west ;
         Move XPosition;
         face_south;
         Move YPosition;
      }
      DefineNewInstruction harvest_westward as
      {
         face_west;
         while (FrontIsClear)
         {
            Move;
            if (BeepersOnFloor > 0) PickBeeper;
         }
      }
      DefineNewInstruction distribute_eastward as
      {
         face_east;
         while (BeepersInBag > 0)
         {
            PutBeeper;
            Move;
         }
         while (XPosition < startx) Move;
      }
      DefineNewInstruction harvest_next_row as
      {
         face_north;
         Move;
         harvest_westward;
      }
      DefineNewInstruction sort_columns as
      {
         move_to_origin;
         face_east;
         while (BeepersOnFloor > 0) Move;
         startx = XPosition;
         harvest_next_row;
         while (BeepersInBag > 0)
         {
            distribute_eastward;
            harvest_next_row;
         }
         move_to_origin;
      }
      DefineNewInstruction make_columns as
      {
         move_to_origin;
         while (BeepersOnFloor > 0)
         {
            iterate BeepersOnFloor times PickBeeper;
            PutBeeper;
            face_north;
            while (BeepersInBag > 0)
            {
               Move;
               PutBeeper;
            }
            face_south;
            Move YPosition;
            face_east;
            Move;
         }
      }
   }
}
execute
{
   place pile_of_beepers at 0,0;
   new smart_bot karel at 5,8;
   tell karel:
   {
      make_columns;
      sort_columns;
      TurnOff;
   }
}

See also:
Go to Next Section of the RoBOTL Reference Guide:
You can also go:

Created on 20 June 1995
Last revised 27 January 1997
Copyright ©1995,1996.1997 Walter S. Ching, n1hbr@ma.ultranet.com