RoBOTL

Defining New Robot Types


You cannot redefine the characteristics of a basic_bot, so if you want to change the characteristics of the robot to something you prefer. you must define your own robot type. First, however, you must decide what type of robot on which you wish to base your new type of robot. For now, the only defined robot type is basic_bot, so you must base your new robot on it. By basing one robot type on another, it inherits all the existing characteristics and new characteristics can be defined without affecting any other robot types.

To define a new robot, you must use the NewRobotType and IsLikeA statements. The IsLikeA must be the first statement in the NewRobotType definition. One is never used without the other.

The definition must come before any executable statements, so it must appear within a define block. For example, if we wanted to define another type of robot called another_bot and then wanted to create one named twin to try it out, we could do the following:

define
{
   NewRobotType another_bot 
   {
      IsLikeA basic_bot;
   }
}
execute
{
   new basic_bot karel at 1,1; 
   tell karel: 
   {
      if (FrontIsClear) Move 1; 
      TurnOff; 
   }
   new another_bot twin at 3,3;
   tell twin:
   {
      if (FrontIsClear) Move 1;
      TurnOff;
   }
}
This is not all that useful at the moment because another_bot is exactly like a basic_bot. We can't tell twin to do anything that we couldn't tell karel. What would make it useful is to add enhancements to the definition of another_bot. This can include defining new instructions and/or specifiying a starting number of beepers in the robot's bag (a basic_bot starts without any beepers in its bag). You can also declare integer values that you want the robot to remember.

Allowable enhancements are:

Now we can do something useful with a new robot type, as shown below:
define
{
   NewRobotType smarter_bot 
   {
      IsLikeA basic_bot; 
      DefineInitialBeepers 5; 
      DefineNewInstruction turnright as iterate 3 times TurnLeft;       
      DefineNewInstruction moveright as
      {
         if (RightIsClear)
         {
            turnright;
            Move 1; 
         }
      }
   }
}
execute
{
   new basic_bot karel at 1,1; 
   tell karel: 
   {
      iterate 4 times 
      {
         if (RightIsClear) 
         {
            iterate 3 times TurnLeft;
            Move 1; 
         }
      }
      TurnOff; 
   }
   new smarter_bot egghead at 3,3;
   tell egghead: iterate 4 times moveright;
   tell egghead: TurnOff;
}

Further Details - Defining New Robot Types
Go to Next Section of the RoBOTL Reference Guide:
You can also go:

Created on 19 June 1995
Last revised 22 January 1997
Copyright ©1995,1996,1997 Walter S. Ching, n1hbr@ma.ultranet.com