RoBOTL

Sample Program 1


/************************************************************************/
/* DEMO1.ROB                                                            */
/* Based on a program developed by Richard E. Pattis,                   */
/* Chapter 5.5, A Large Program Written by Stepwise Refinement,         */
/* as published in Karel the Robot, Copyright (c)1981 John Wiley & Sons */
/* Translated to RoBOTL by Walter S. Ching, June 1995                   */
/* Translation Copyright (c)1995,1996 Walter S. Ching                   */
/************************************************************************/

define
{
   WorldEntity world_of_karel
   {
      wall from 2,2 north for 10;
      wall from 2,11 east for 10;
      wall from 11,11 south for 5;
      wall from 11,5 south for 4;
      wall from 11,2 west for 10;
   }
   NewRobotType beeper_bot
   {
      IsLikeA basic_bot;
      DefineInitialBeepers 5;
      DefineNewInstruction turnright as
      {
         iterate 3 times TurnLeft;
      }
      DefineNewInstruction sidestep_right as
      {
         turnright;
         Move 1;
         TurnLeft;
      }
      DefineNewInstruction sidestep_back_left as
      {
         TurnLeft;
         Move 1;
         turnright;
      }
      DefineNewInstruction shuffle as
      {
         sidestep_right;
         if (FrontIsClear)
         {
            sidestep_back_left;
            Move 1;
         }
      }
      DefineNewInstruction go_to_wall as
      {
         while (FrontIsClear)
         {
            if (not RightIsClear) turnright;
            else shuffle;
         }
      }
      DefineNewInstruction follow_perimeter as
      {
         if (FrontIsClear) Move 1;
         else
         {
             TurnLeft;
             if (BeepersInBag > 0) PutBeeper;
         }
      }
      DefineNewInstruction follow_until_door_is_on_right as
      {
         while (not RightIsClear) follow_perimeter;
      }
      DefineNewInstruction exit_door as
      {
         turnright;
         iterate 3 times if (FrontIsClear) Move 1;
      }
      DefineNewInstruction escape as
      {
         go_to_wall;
         TurnLeft;
         follow_until_door_is_on_right;
         exit_door;
         TurnOff;
      }
   }
}
execute
{
   place world_of_karel at 0,0;
   new beeper_bot karel at 5,8;
   new beeper_bot kathy at 5,4;
   tell karel: escape;
   remove karel;
   tell kathy: escape;
}

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