Chapter 5. Basic Agent Behaviors: Motion, Appearance and Communication
<< previous |  | next >>

## Chapter 5. Basic Agent Behaviors: Motion, Appearance and Communication

To create a simple agent in breve, you'll need to subclass one of the basic agent classes, all subclasses of Real:

- Stationary, an immobile object in the simulated world.

- Mobile, an object that moves around the simulated world.

- Link, a physically simulated mobile object.

This chapter describes the basics of implementing agents in breve, with a focus on Mobile agents. Stationary objects are even easier to use than Mobile objects, and Physically simulated Link objects (and their companion class, MultiBody) are described in the chapter on physical simulation (Chapter 8).

The section A Simple Mobile agent (the section called “A Simple Mobile Agent”) shows a very basic mobile agent template that can be used to start any mobile agent. The appearance of the agent can be customized in a number of ways—some basic options are described in the section Changing the Appearance of Agents (the section called “Changing the Appearance of Agents”). Controlling the motion of agents is described in the section Moving Agents Around the 3D World (the section called “Moving Agents Around the 3D World”). The final section describes how events can be scheduled for specific times (the section called “Scheduling Events for a Specific Time”).

## A Simple Mobile Agent

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

Here's the code for a very simple mobile agent (in the steve language). 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.

<< previous |  | next >>
Writing breve Simulations With "steve" | Table of Contents | Changing the Appearance of Agents