yaes.application.eel6938.game.objects
Class Agent

java.lang.Object
  extended byyaes.application.eel6938.game.objects.GameObject
      extended byyaes.application.eel6938.game.objects.Agent
Direct Known Subclasses:
FeedAgent, FleeAgent, KillerAgent, RandomMoveAgent, UserInputAgent

public abstract class Agent
extends yaes.application.eel6938.game.objects.GameObject

Author:
Linus Luotsinen, lluotsin@mail.ucf.edu Feb 9, 2005 This class provides the basic functionalities of an agent in the Flee-Feed-Mate game. Simply inherit this class when a new agent is to be created for the game.

Constructor Summary
Agent()
          Initializes agent sensors and path-planner.
 
Method Summary
 void attack()
          Attacks an agent if an agent is available to attack.
 void attack(int direction)
          Attacks an agent in a direction given by the parameter.
 boolean canAttack()
          This function is used to determine if the agent can attack any other agent or not.
 boolean canEat()
          This function is used to determine if the agent can feast from food/energy resources or not.
 boolean canFlee()
          This function is used to determine if the agent can flee or not.
 boolean canMate()
          This function is used to determine if the agent can mate or not.
 void eat()
          Feeds from a food/energy resource if food/energy resource is available to the agent.
 void eat(int direction)
          Feeds from a food/energy resource in the direction given by the parameter.
 void flee(int direction)
          Flees in a direction given by the parameter.
 java.awt.Point getClosestOpenNeighbouringPoint(java.awt.Point p)
          This function returns the closest neighbouring open spot/point to a point in the agents sensor range.
abstract  int[] getColor()
          Returns the color of the agent.
 int[] getDirections(java.awt.Point p)
          Use this function to get directions to a point in the sensor range.
 int getEnergyLevel()
          This function returns current energy level of the agent.
abstract  java.lang.String getName()
          Returns the name of the agent.
 java.awt.Point[] getSensorAgentList()
          The points in the array returned by this function describes other game agents present in an agent's sensor range.
 int[][] getSensorDataMap()
          This function is used to retreive all agent sensors in a two-dimensional array (map).
 java.awt.Point[] getSensorFoodList()
          The points in the array returned by this function describes food/energy resources present in an agent's sensor range.
 java.awt.Point[] getSensorObstacleList()
          The points in the array returned by this function describes obstacles present in an agent's sensor range.
abstract  void intelligence()
          Specifies the user defined agent intelligence, must be implemented by all agents.
 void mate()
          Spawns a child agent.
 void move(int direction, int speed)
          Moves the agent around in the world as specified by the parameters provided.
 boolean wasLastCommandSuccessful()
          This function is used to give feedback weather or not an action was successful or not.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Agent

public Agent()
Initializes agent sensors and path-planner.

Method Detail

intelligence

public abstract void intelligence()
Specifies the user defined agent intelligence, must be implemented by all agents. This function is called in a round-robin manner in the game. Available actions are shown in the list below:

eat
eat(int)
attack()
attack(int)
flee(int)
mate()
move(int, int)


getName

public abstract java.lang.String getName()
Returns the name of the agent. Must be implemented by all agents in the game.

Returns:
A string describing the name of the agent.

getColor

public abstract int[] getColor()
Returns the color of the agent. Must be implemented by all agents in the game.

Returns:
An array of three integers descibing the color of the agent. For instance the color red is specified by the array {255,0,0}. The default color is black.

canMate

public final boolean canMate()
This function is used to determine if the agent can mate or not. An agent can mate if it has enough food/energy.

Returns:
True if the agent can invoke the mate command, false otherwise.

canEat

public final boolean canEat()
This function is used to determine if the agent can feast from food/energy resources or not. An agent can eat food/energy resources if they are located in neighbouring cells.

Returns:
True if the agent can invoke the eat command, false otherwise.

canAttack

public final boolean canAttack()
This function is used to determine if the agent can attack any other agent or not. An agent can attack other agents if they are located in neighbouring cells.

Returns:
True if the agent can invoke the attack command, false otherwise.

canFlee

public final boolean canFlee()
This function is used to determine if the agent can flee or not. An agent can flee if it has been attacked.

Returns:
True if the agent can invoke flee command otherwise false.

wasLastCommandSuccessful

public final boolean wasLastCommandSuccessful()
This function is used to give feedback weather or not an action was successful or not.

Returns:
True if last command (any command) was successful or not.

getDirections

public int[] getDirections(java.awt.Point p)
Use this function to get directions to a point in the sensor range. This function will return a list/array of directions to this point if possible. The first entry in the array is the first move to make in order to get to the target. The function acts as a path-planner and will return the optimum path.

Parameters:
p - The point to get directions to.
Returns:
An array of direction constants if path was found. Otherwise null is returned.

getClosestOpenNeighbouringPoint

public final java.awt.Point getClosestOpenNeighbouringPoint(java.awt.Point p)
This function returns the closest neighbouring open spot/point to a point in the agents sensor range. Use this function to get an appropriate point from which your agent can feed or attack from.

Parameters:
p - The point used to find neighbouring points from. Usually a food resource location or an agent location.
Returns:
The closest open point to the given reference point provided as a input parameter.

eat

public final void eat(int direction)
Feeds from a food/energy resource in the direction given by the parameter.

Parameters:
direction -

eat

public final void eat()
Feeds from a food/energy resource if food/energy resource is available to the agent.


move

public final void move(int direction,
                       int speed)
Moves the agent around in the world as specified by the parameters provided.

Parameters:
direction - The direction to move.
speed - Speed to move at.

attack

public final void attack(int direction)
Attacks an agent in a direction given by the parameter.

Parameters:
direction - The direction to attack.

attack

public final void attack()
Attacks an agent if an agent is available to attack.


flee

public final void flee(int direction)
Flees in a direction given by the parameter.

Parameters:
direction - The direction to flee.

mate

public final void mate()
Spawns a child agent.


getEnergyLevel

public final int getEnergyLevel()
This function returns current energy level of the agent.

Returns:
Current energy level.

getSensorObstacleList

public final java.awt.Point[] getSensorObstacleList()
The points in the array returned by this function describes obstacles present in an agent's sensor range. All obstacles are represented, from the agent reference point of (x,y) = (0,0), using the standard coordinate system as descibed below.

(y)^
     |
     |
     ----->
        (x)

For example: An obstacle north-east of the agent can be represented by (10,10). An obstacle north of the agent can be represented by (0,10). An obstacle south-west of the agent can be represented by (-10,-10). An obstacle south of the agent can be represented by (0,-10).

Returns:
An array of points of (x,y) coordinates descibing obstacles present in the calling agent's sensor range.

getSensorAgentList

public final java.awt.Point[] getSensorAgentList()
The points in the array returned by this function describes other game agents present in an agent's sensor range. The array is ordered so that closest agents are located in the beginning of the list. All agents are represented, from the agent reference point of (x,y) = (0,0), using the standard coordinate system as descibed below.

(y)^
     |
     |
     ----->
        (x)

For example: An agent north-east of the agent can be represented by (10,10). An agent north of the agent can be represented by (0,10). An agent south-west of the agent can be represented by (-10,-10). An agent south of the agent can be represented by (0,-10).

Returns:
An array of points of (x,y) coordinates descibing agents present in the calling agent's sensor range.

getSensorFoodList

public final java.awt.Point[] getSensorFoodList()
The points in the array returned by this function describes food/energy resources present in an agent's sensor range. The array is ordered so that closest food/energy resources are located in the beginning of the list. All food/energy resources are represented, from the agent reference point of (x,y) = (0,0), using the standard coordinate system as descibed below.

(y)^
     |
     |
     ----->
        (x)

For example: An food/energy resource north-east of the agent can be represented by (10,10). An food/energy resource north of the agent can be represented by (0,10). An food/energy resource south-west of the agent can be represented by (-10,-10). An food/energy resource south of the agent can be represented by (0,-10).

Returns:
An array of points of (x,y) coordinates descibing food/energy resource present in the calling agent's sensor range.

getSensorDataMap

public final int[][] getSensorDataMap()
This function is used to retreive all agent sensors in a two-dimensional array (map). It can be used instead of or as a complement to getSensorObstacleList(), getSensorFoodList() and getSensorAgentList().

Returns:
A two-dimensional array (map) descibing all objects (other agents, food/energy resources and obstacles) available in an agent's sensor range.