jadex.micro.examples.hunterprey
Class MoveAction

java.lang.Object
  extended by jadex.commons.SimplePropertyObject
      extended by jadex.micro.examples.hunterprey.MoveAction
All Implemented Interfaces:
ISpaceAction, IPropertyObject

public class MoveAction
extends SimplePropertyObject
implements ISpaceAction

Action allowing a creature to move.


Nested Class Summary
static interface MoveAction.IMoveEvaluator
          Interface for evaluating moves.
 
Field Summary
static String DIRECTION_DOWN
          The move direction down.
static String DIRECTION_LEFT
          The move direction left.
static String DIRECTION_NONE
          Placeholder for "no move" action.
static String DIRECTION_RIGHT
          The move direction right.
static String DIRECTION_UP
          The move direction up.
static String PARAMETER_DIRECTION
          The move direction parameter.
static String PROPERTY_LASTPOS
          The last position property (only for hunters).
 
Fields inherited from class jadex.commons.SimplePropertyObject
pcs, properties
 
Fields inherited from interface jadex.application.space.envsupport.environment.ISpaceAction
ACTOR_ID, OBJECT_ID
 
Constructor Summary
MoveAction()
           
 
Method Summary
static String evaluateMoves(Grid2D space, IVector2 sourcepos, MoveAction.IMoveEvaluator eval)
          Get the best move.
static String getAvoidanceDirection(Grid2D space, IVector2 sourcepos, ISpaceObject[] objects)
          Move to stay away from the given objects.
static String getDirection(Grid2D space, IVector2 sourcepos, IVector2 targetpos)
          Get the best way to go towards a direction.
static String[] getPossibleDirections(Grid2D space, IVector2 sourcepos)
          Get the possible moves.
 Object perform(Map parameters, IEnvironmentSpace space)
          Performs the action.
 
Methods inherited from class jadex.commons.SimplePropertyObject
addPropertyChangeListener, getProperties, getProperty, getPropertyNames, hasProperty, removePropertyChangeListener, setProperties, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jadex.commons.IPropertyObject
getProperty, getPropertyNames, hasProperty, setProperty
 

Field Detail

PARAMETER_DIRECTION

public static final String PARAMETER_DIRECTION
The move direction parameter.

See Also:
Constant Field Values

PROPERTY_LASTPOS

public static final String PROPERTY_LASTPOS
The last position property (only for hunters).

See Also:
Constant Field Values

DIRECTION_LEFT

public static final String DIRECTION_LEFT
The move direction left.

See Also:
Constant Field Values

DIRECTION_RIGHT

public static final String DIRECTION_RIGHT
The move direction right.

See Also:
Constant Field Values

DIRECTION_UP

public static final String DIRECTION_UP
The move direction up.

See Also:
Constant Field Values

DIRECTION_DOWN

public static final String DIRECTION_DOWN
The move direction down.

See Also:
Constant Field Values

DIRECTION_NONE

public static final String DIRECTION_NONE
Placeholder for "no move" action.

See Also:
Constant Field Values
Constructor Detail

MoveAction

public MoveAction()
Method Detail

perform

public Object perform(Map parameters,
                      IEnvironmentSpace space)
Performs the action.

Specified by:
perform in interface ISpaceAction
Parameters:
parameters - parameters for the action
space - the environment space
Returns:
action return value

getDirection

public static String getDirection(Grid2D space,
                                  IVector2 sourcepos,
                                  IVector2 targetpos)
Get the best way to go towards a direction.

Parameters:
space - The 2D space to move in.
sourcepos - The source position.
targetpos - The target position.
Returns:
The way to go (if any).

getAvoidanceDirection

public static String getAvoidanceDirection(Grid2D space,
                                           IVector2 sourcepos,
                                           ISpaceObject[] objects)
Move to stay away from the given objects.

Parameters:
space - The 2D space to move in.
sourcepos - The source position.
objects - The objects to avoid.
Returns:
The direction to go ('none', if no move at all is better than moving in any direction).

evaluateMoves

public static String evaluateMoves(Grid2D space,
                                   IVector2 sourcepos,
                                   MoveAction.IMoveEvaluator eval)
Get the best move.

Parameters:
space - The 2D space to move in.
sourcepos - The source position.
eval - The move evaluator.
Returns:
The direction to go ('none', if no move at all is better than moving in any direction).

getPossibleDirections

public static String[] getPossibleDirections(Grid2D space,
                                             IVector2 sourcepos)
Get the possible moves.

Parameters:
space - The 2D space to move in.
sourcepos - The source position.
Returns:
The directions to go (i.e. all possible directions excluding 'none' or an array with only 'none').


Copyright © 2010. All Rights Reserved.