Jadex 0.96

jadex.examples.hunterprey
Class Environment

java.lang.Object
  extended by jadex.examples.hunterprey.Environment
All Implemented Interfaces:
IEnvironment

public class Environment
extends Object
implements IEnvironment

The environment is the container all objects and creatures.


Field Summary
static int DEFAULT_LEASE_TICKS
          The default number of lease ticks.
 MultiCollection world
          All world objects accessible per location.
 
Constructor Summary
Environment()
          Create a new environment.
 
Method Summary
 Creature addCreature(Creature creature)
          Add a new creature to the world.
 TaskInfo addEatTask(Creature me, WorldObject obj)
          Add a move or eat action to the queue.
 void addFood(Food nfood)
          Add a new prey food to the world.
 TaskInfo addMoveTask(Creature me, String dir)
          Add a move or eat action to the queue.
 void addObstacle(Obstacle obstacle)
          Add a new obstacle to the world.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
 boolean eat(Creature me, WorldObject food)
          Eat some object.
 void executeStep()
          Execute a step.
 WorldObject[] getAllObjects()
          Get all objects in the world (obstacles, food, and creature).
 Creature[] getCreatures()
          Get the creatures.
 Food[] getFood()
          Get the obstacles.
 int getFoodrate()
          Get the foodrate.
 int getHeight()
          Get the height of the world.
 Creature[] getHighscore()
          Get the current highscore.
static Environment getInstance()
          Get the singleton.
 Obstacle[] getObstacles()
          Get the obstacles.
 long getSaveInterval()
          Get the highscore save interval (-1 for autosave off).
 int getTaskSize()
          Return the size of the task list.
 Vision getVision(Creature me)
          Get the current vision.
 int getWidth()
          Get the width of the world.
 int getWorldAge()
          Get the world age.
 Vision internalGetVision(Creature me)
          Get the current vision (without updating the creatures leaseticks).
 boolean move(Creature me, String dir)
          Perform a move.
 boolean moveDown(Creature me)
          Move one field downwards.
 boolean moveLeft(Creature me)
          Move one field to the left.
 boolean moveRight(Creature me)
          Move one field to the right.
 boolean moveUp(Creature me)
          Move one field upwards.
 boolean removeCreature(Creature creature)
          Remove a creature to the world.
 boolean removeFood(Food nfood)
          remove a prey food to the world.
 boolean removeObstacle(Obstacle obstacle)
          Remove a obstacle to the world.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
 void saveHighscore()
          Save the highscore to a file.
 void setFoodrate(int foodrate)
          Set the foodrate.
 void setSaveInterval(long saveinterval)
          Set the highscore save interval (-1 for autosave off).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LEASE_TICKS

public static int DEFAULT_LEASE_TICKS
The default number of lease ticks.


world

public MultiCollection world
All world objects accessible per location.

Constructor Detail

Environment

public Environment()
Create a new environment.

Method Detail

getInstance

public static Environment getInstance()
Get the singleton.

Returns:
The environment.

moveUp

public boolean moveUp(Creature me)
Move one field upwards. The method will block until the current simulation step has finished.

Specified by:
moveUp in interface IEnvironment
Returns:
True, when the operation succeeded.

moveDown

public boolean moveDown(Creature me)
Move one field downwards. The method will block until the current simulation step has finished.

Specified by:
moveDown in interface IEnvironment
Returns:
True, when the operation succeeded.

moveLeft

public boolean moveLeft(Creature me)
Move one field to the left. The method will block until the current simulation step has finished.

Specified by:
moveLeft in interface IEnvironment
Returns:
True, when the operation succeeded.

moveRight

public boolean moveRight(Creature me)
Move one field to the right. The method will block until the current simulation step has finished.

Specified by:
moveRight in interface IEnvironment
Returns:
True, when the operation succeeded.

eat

public boolean eat(Creature me,
                   WorldObject food)
Eat some object. The object has to be at the same location. This method does not block, and can be called multiple times during each simulation step.

Specified by:
eat in interface IEnvironment
Parameters:
food - The object.
Returns:
True, when the operation succeeded.

addEatTask

public TaskInfo addEatTask(Creature me,
                           WorldObject obj)
Add a move or eat action to the queue.


addMoveTask

public TaskInfo addMoveTask(Creature me,
                            String dir)
Add a move or eat action to the queue.


internalGetVision

public Vision internalGetVision(Creature me)
Get the current vision (without updating the creatures leaseticks).

Parameters:
me - The creature.

getVision

public Vision getVision(Creature me)
Get the current vision. This method does not block, and can be called multiple times during each simulation step.

Specified by:
getVision in interface IEnvironment
Parameters:
me - The creature.

getWidth

public int getWidth()
Get the width of the world.


getHeight

public int getHeight()
Get the height of the world.


addFood

public void addFood(Food nfood)
Add a new prey food to the world.

Parameters:
nfood - The new food.

removeFood

public boolean removeFood(Food nfood)
remove a prey food to the world.

Parameters:
nfood - Thefood.

addObstacle

public void addObstacle(Obstacle obstacle)
Add a new obstacle to the world.

Parameters:
obstacle - The new obstacle.

removeObstacle

public boolean removeObstacle(Obstacle obstacle)
Remove a obstacle to the world.

Parameters:
obstacle - The obstacle.

addCreature

public Creature addCreature(Creature creature)
Add a new creature to the world.

Parameters:
creature - The creature.

removeCreature

public boolean removeCreature(Creature creature)
Remove a creature to the world.

Parameters:
creature - The creature.

executeStep

public void executeStep()
Execute a step.


getWorldAge

public int getWorldAge()
Get the world age.

Returns:
The age of the world.

getFoodrate

public int getFoodrate()
Get the foodrate.

Returns:
The foodrate.

setFoodrate

public void setFoodrate(int foodrate)
Set the foodrate.

Parameters:
foodrate - The foodrate.

move

public boolean move(Creature me,
                    String dir)
Perform a move.

Parameters:
me - The creature.
dir - The direction.

getCreatures

public Creature[] getCreatures()
Get the creatures.

Returns:
The creatures.

getObstacles

public Obstacle[] getObstacles()
Get the obstacles.

Returns:
The obstacles.

getFood

public Food[] getFood()
Get the obstacles.

Returns:
The obstacles.

getAllObjects

public WorldObject[] getAllObjects()
Get all objects in the world (obstacles, food, and creature).


getTaskSize

public int getTaskSize()
Return the size of the task list.

Returns:
The task size.

getHighscore

public Creature[] getHighscore()
Get the current highscore.

Returns:
The 10 best creatures.

saveHighscore

public void saveHighscore()
Save the highscore to a file.


setSaveInterval

public void setSaveInterval(long saveinterval)
Set the highscore save interval (-1 for autosave off).


getSaveInterval

public long getSaveInterval()
Get the highscore save interval (-1 for autosave off).


addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties.

Parameters:
listener - The PropertyChangeListener to be added.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Parameters:
listener - The PropertyChangeListener to be removed.

Jadex 0.96

Submit a bug or feature
For further API reference and developer documentation, see the Jadex User Guide and the Jadex Tutorial. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, and working code examples.

Copyright (C) 2002-2007 Lars Braubach, Alexander Pokahr - University of Hamburg. Use is subject to license terms.