A predator is a version of the follower agent that chases other boids and eats them. The point of this assignment is to understand the place of models of the world in making decisions. Decisions based on a model can be much better than decisions tied directly to features of the world… as long as the information specified by the model is true!
The assignment is designed to be done with relatively simple models. That means that some of the complexities that we considered with the follower in class are out of the picture here. You do not need to worry about limits on effectors: your agent can move as fast as it wants in each time step, up to its maximum speed, and it can also turn in each time step to whatever heading it wants. These parameters are automatically set in the skeleton code files for you.
First, create a reactive predator. The reactive predator orients itself towards the closest boid and charges towards it full speed ahead, until it closes in and eats it.
The skeleton code highlights the methods isTarget(Percept), targetCost(Percept), deliberate(List<Percept>) and draw(Graphics).
Note. The skeleton code already takes care of the fact that the predator will eat any boid that it closes in on. That happens through the collision detection code in the World class, plus the fact that the predator expects to have an InteractiveBehavior of ATTACK when it collides with a BOID.
Second, create a model-based predator. The model-based predator makes a prediction about where each boid is going to go. In particular, it assumes that each boid is going to continue indefinitely at its current speed and heading. The model-based predator uses this prediction to think through which boid it can catch most easily, and what direction to go to get to it. It then proceeds at full speed in that direction, pursuing a boid until it, too, closes in and eats it.
The reasoning carried out by the model-based predator can be described in terms of the following picture.
In this picture the blue agent represents the predator and the green agent represents a potential target. The target is represented as in the predator's percept. The target is located a specified distance away at a specified angle. The target is moving at a specified speed in a specified orientation.
The shortest distance between any two points is a straight line. That means if the predator wants to get to the target as quickly as possible, the predator should steer now in the direction of the point where the predator will ultimately intercept the target. That point is labeled X in the figure. The diagram shows how to calculate this point trigonometrically. Start from the segment AB between the predator and the target and extend it to a further point C such that ACX and BCX are both right triangles. The angle at A, \alpha, is an intercept angle chosen by the predator. The angle at B, \beta, is the divergence angle at which the target is heading off to the side. Say v_t is the speed of the target and v_p is the speed of the predator. The figure shows that
To figure out where the interception actually takes place, you can consider how long it takes for the predator to make up the distance d to the target, thinking about the horizontal motion that brings both to point C at time t. The predator and the target both travel this distance, so
The skeleton code highlights the methods isTarget(Percept), targetCost(Percept), deliberate(List<Percept>) and draw(Graphics).
You should supplement your changes here with helper methods: for example, you might want to find whether, when, and where the agent will intercept the target specified by a given Percept.
There are two basic properties that distinguish a ReactiveFollower from a ModelFollower. The first difference is the direction they move to pursue a target. ReactiveFollower goes to where the target is, ModelFollower goes to where the target will be. These two files illustrate the contrast.
The second diference is which target they choose to go after. ReactiveFollower goes for the closest one. ModelFollower goes to the one it will catch first. These two files illustrate the contrast.
Create four demonstration files showing the strengths and weaknesses of using a model to make decisions.
The demonstration files describe a single predator and a single prey acting in a common environment. They may also include other entities. The files come in pairs. The only difference between each pair is that where one declares a reactive-predator (with certain parameters) the other declares a model-predator (with certain parameters).
First give a pair of examples where the model clearly wins. In particular, the model-predator should catch the target. The reactive-predator should not. Call these files mwm.xml (model wins model) and mwr.xml (model wins reactive).
Second give a pair of examples where the model clearly loses. In particular, the model-predator should take substantially longer to catch the target than the reactive-predator because the target does something that the model-predator doesn't expect. Call these files rwm.xml (reactive wins model) and rwr.xml (reactive wins reactive).
It might help to set up the two predators in the same file to start, and let them "race" each other.
Geeky aside. The point of this assignment is to implement and analyze a model. There are lots of ways this model is incomplete, some of which we explore below. However, an important but irrelevant way that this model is incomplete is that it doesn't account for the fact that the world is a torus. In a torus, you actually see an infinite number of copies of each object - like looking at yourself between two mirrors - because light can reach you directly from the object or "around the world" any number of times. Sometimes, you will reach your target quicker if you run not towards the closest image of it, but towards one of the other ones. It's almost as if you sneak up on it by going backwards around the world. Do not spend too much time thinking about this - unless you enjoy doing so. Just focus on the cases where one agent chases another within the bounds of the screen.
Improve the decisions of the model-based agent: make its models better match what is actually happening in the world around it. Create more sophisticated prey. Iterate. Possible projects:
In each case, you should include your code in an existing file. By default, your program should have the behavior it is specified to have in the basic version of the assignment. Your agents should only exhibit specialized or sophisticated behavior if the XML attribute with-extensions (which corresponds to the FixedAgentAttributes instance field withExtensions) is true. This behavior is essential for grading purposes.
To show off your new implementation, create sample world files that show what your extended agent does that the basic model-based agent cannot do.