A Simple Mobile Agent

The majority of agents created in breve are simple mobile agents.

Here's a simple mobile agent. It inherits most of its behaviors from the class Mobile, but we'll customize it with our own init and iterate methods.

Mobile : Bird {
        + variables:
                myShape (object).

        + to init:
                # make a new shape -- this step is optional.  The 
                # default shape for a new Mobile is a sphere of 
                # radius 1.

                myShape = (new Cube init-with size (1, 1, 1)).

                # set the Mobile to the new shape and we're done!

                self set-shape to myShape.

        + to iterate:
                # here we would specify our default behavior--the action
                # we take at each iteration.  typically this involves a
                # change in velocity or acceleration based on some sort
                # of computation
}

The shape used need not be a cube—you can choose from a number of shapes using the class Shape. You can also construct your own shapes with the class CustomShape.

This is only a simple example—a template for a real agent. In the rest of the chapter we'll see how to customize the appearance, motion and behavior of an agent.