RoBOTL Robot Instructions

Robot Instructions are those functions which you can call within a Tell or DefineNewInstruction, "execute" or "define" statement. Instructions are used to make a specific robot perform a specific function or set of functions.

Instructions can be used singularly, or in groups. The current list of Robot Instructions are:


Assignment

Usage: Variable "=" Expression ";"

Assignment instructions set a given variable equal to some expression. Using this instruction, you can change both the globally defined variables as well as the robot's local variables.


Do-While

Usage: Do Instructions While "(" Expression ")" ";"

The Do-While instruction is much like the While instruction, except the loop is executed first, and then the expression is checked.


If-Else

Usage: If "(" Expression ")" Instructions [ "Else" Instructions ]

The If-Else conditional instruction is much like the If-Else "execute" statement, except you specify instructions instead of statements. See the if-else statement information for an example.


Iterate

Usage: Iterate Expression "times" Instructions

The iterate instruction allows you to have some set of instructions repeated a specific number of times, specified by Expression. For instance:

iterate 4 times move 1;

This instruction will make the specified robot move 4 squares in the direction it's facing. (Note: This is a random example, and the overall effect can be achieved using a more efficient statement such as 'move 4;'.)


Move

Usage: Move Expression ";"

The move instruction causes the specified robot to move a specified number of squares (defined using the above Expression) in the direction the robot is currently facing.

Note: If the robot moves such that it hits an object (another robot or block), the robot will be damaged and it will shut itself off. You can not revive the robot once it is damaged. Unless you know that the squares in front of your robot are not blocked, you should use a If-Else Robot Instruction coupled with a FrontIsClear Boolean Function, and some form of loop to move the robot forward safely. For instance, to move 4 squares forward, you can use:

iterate 4 times {
    if ( frontisclear )
       move 1;
}
This will cause the robot to move forward only if the square in front of the robot is clear of obstruction.


PickBeeper

Usage: PickBeeper ";"

This instruction will instruct the specified robot to take a beeper from the ground and place it in the robot's beeper bag. If there are no beepers on the ground, a warning is generated.


PutBeeper

Usage: PutBeeper ";"

The PutBeeper Instruction will cause the specified robot to remove a beeper from its beeperbag and place it on the ground. If there are no beepers available, a warning is generated.


TurnLeft

Usage: TurnLeft ";"

Each robot in RoBOTL is only allowed to change direction in 90° increments, in a counter-clockwise manner. The instruction to cause a robot to turn 90° is the turnleft instruction.

Note: Often, RoBOTL programs define 'turnright' as 'iterate 3 times turnleft;'.


TurnOff

Usage: TurnOff ";"

Turns off the currently specified robot.


TurnOn

Usage: TurnOn ";"

Turns on the currently specified robot.

Note: Robots which are damaged (by hitting an object) and are deactivated can NOT be re-activated by the turnon instruction.


User Defined Instructions

Usage: Instruction Name ";"

One of the more powerful things you can do with RoBOTL is define your own instructions which you can use to instruct a robot to do something. The most typical user defined instruction is 'turnright'.

Example:


define {
  NewRobotType smart_bot {
    IsLikeA basic_bot;
    DefineNewInstruction turnright as iterate 3 times turnleft;
  }
}
execute {
  new smart_bot pete_bot;
  tell pete_bot : {
       move 1;
       turnleft;
       move 4;
       turnright;
       while ( frontisclear )
	     move 1;
  }
}


While

Usage: While Expression Instructions

This instruction will execute the given instructions as long as the expression is true. Note that the expression is checked before the first time through the while loop, so if the expression is initially false, the loop is ignored.


This guide is not great to look at under text-only browsers. Sorry. Since you need a graphical browser for the applet, we figured you'd be using it for the reference guide.

Document Last Revised: Tuesday December 16th, 1997 at 1:57am
Copyright ©1997 Worcester Polytechnic Institute
Page Written by: Theo Van Dinter (felicity@kluge.net)