appletbots.gatherers
Class Gatherer

java.lang.Object
  extended by appletbots.WorldObject
      extended by appletbots.Agent
          extended by appletbots.CarrierAgent
              extended by appletbots.gatherers.Gatherer

public class Gatherer
extends CarrierAgent

A gatherer agent chooses the closest visible piece of food that is currently not being carried by anyone (and is not already in the agent's home base) and accelerates towards it. If no "uncarried" food can be found, the agent tries to find food carried by a member of the opposing team to accelerate towards. If no food is visible the agent sets his acceleration to a random vector to search for food. When it gets close enough to pick up a piece of food, it picks it up and carries it towards its home base corner for 20 time cycles, and drops it again. The gatherer must then rest for 10 time cycles before picking up another piece of food. During these 10 time cycles, the "exhausted" agent does not accelerate.

Author:
Erik Rasmussen

Field Summary
protected  boolean bottomRightTeam
          Whether or not the agent is on the team with the home base in the bottom right-hand corner of the world
protected  int timeCarried
          The amount of time the gatherer has been carrying a piece of food
protected  int timeToRest
          The the amount of time needed to rest
protected  Vector towardsHome
          The vector pointing in the direction of the agent's home base
 
Fields inherited from class appletbots.Agent
accelerationVectorColor, maxAcceleration, sight, velocityVectorColor, world
 
Fields inherited from class appletbots.WorldObject
color, mass, maxSpeed, size
 
Constructor Summary
Gatherer(int pickupDistance, boolean bottomRightTeam, int size, int sight, double maxSpeed, double maxAcceleration)
          Constructs a new Gatherer with the given parameters
 
Method Summary
protected  Food chooseFood(boolean carried)
          Selects closest visible food not already in home base
protected  void dropFood()
          Attempts to drop any carried food
protected  Gatherer getNearestGatherer(boolean opponent)
          Returns the nearest visible gatherer
 boolean isBottomRightTeam()
          Returns whether or not the agent is on the team with the home base in the bottom right-hand corner of the world
 void observeWorld()
          Observes the world, and follows the Gatherer Algorithm.
protected  void pickUp(CarriableObject item)
          Picks up an object
 
Methods inherited from class appletbots.CarrierAgent
drop, getInventory, getPickUpDistance, hasItem, hasItems
 
Methods inherited from class appletbots.Agent
getAcceleration, getMaxAcceleration, getRandomAcceleration, getShowAcceleration, getShowVelocity, getSight, getVectorsToDraw, setAcceleration, setShowAcceleration, setShowVelocity, setWorld
 
Methods inherited from class appletbots.WorldObject
collidedWith, getColor, getMass, getMaxSpeed, getSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bottomRightTeam

protected boolean bottomRightTeam
Whether or not the agent is on the team with the home base in the bottom right-hand corner of the world


timeCarried

protected int timeCarried
The amount of time the gatherer has been carrying a piece of food


timeToRest

protected int timeToRest
The the amount of time needed to rest


towardsHome

protected Vector towardsHome
The vector pointing in the direction of the agent's home base

Constructor Detail

Gatherer

public Gatherer(int pickupDistance,
                boolean bottomRightTeam,
                int size,
                int sight,
                double maxSpeed,
                double maxAcceleration)
Constructs a new Gatherer with the given parameters

Parameters:
pickupDistance - The distance from an object the agent must be to pick up the object
bottomRightTeam - Whether or not this agent is on the team moving food to the bottom right corner of the world
size - The agent's radius
sight - The distance the agent can see
maxSpeed - The maximum speed the agent can travel
maxAcceleration - The maximum acceleration for this agent
Method Detail

observeWorld

public void observeWorld()
Observes the world, and follows the Gatherer Algorithm.

Specified by:
observeWorld in class Agent

chooseFood

protected Food chooseFood(boolean carried)
Selects closest visible food not already in home base

Parameters:
carried - Whether or not the food we are looking for is being carried
Returns:
The closest visible food not already in home base

getNearestGatherer

protected Gatherer getNearestGatherer(boolean opponent)
Returns the nearest visible gatherer

Parameters:
opponent - If true will return nearest visible opponent, otherwise nearest teammate
Returns:
The nearest visible gatherer

isBottomRightTeam

public boolean isBottomRightTeam()
Returns whether or not the agent is on the team with the home base in the bottom right-hand corner of the world

Returns:
Whether or not the agent is on the team with the home base in the bottom right-hand corner of the world

dropFood

protected void dropFood()
Attempts to drop any carried food


pickUp

protected void pickUp(CarriableObject item)
Picks up an object

Overrides:
pickUp in class CarrierAgent
Parameters:
item - The object to pick up