public class Environment extends java.lang.Object implements IEnvironment
Modifier and Type | Field and Description |
---|---|
protected int |
age
The world age.
|
protected java.util.Map |
creatures
The creatures.
|
static int |
DEFAULT_LEASE_TICKS
The default number of lease ticks.
|
protected java.util.Set |
food
The prey food.
|
protected int |
foodrate
The foodrate determines how often new food pops up.
|
protected java.util.List |
highscore
The highscore location.
|
protected static Environment |
instance
The singleton instance.
|
protected java.lang.Object |
monitor
The monitor.
|
protected java.util.Set |
obstacles
The obstacles.
|
protected jadex.commons.SimplePropertyChangeSupport |
pcs
The helper object for bean events.
|
protected java.util.Random |
rand
The radnom number generator.
|
protected long |
saveinterval
The interval between saves of highscore (-1 for autosave off).
|
protected long |
savetime
The last time the highscore was saved.
|
protected int |
sizex
The horizontal size.
|
protected int |
sizey
The vertictal size.
|
protected java.util.List |
tasklist
The list for move and eat requests.
|
jadex.commons.collection.MultiCollection |
world
All world objects accessible per location.
|
Constructor and Description |
---|
Environment()
Create a new environment.
|
Modifier and Type | Method and Description |
---|---|
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,
java.lang.String dir)
Add a move or eat action to the queue.
|
void |
addObstacle(Obstacle obstacle)
Add a new obstacle to the world.
|
void |
addPropertyChangeListener(jadex.commons.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list.
|
protected void |
clearTaskList()
Clear the TaskList
HACK! Should be done in executeStep method, but that leads to problems with
other Agents.
|
protected Location |
createLocation(Location loc,
java.lang.String dir)
Create a location.
|
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).
|
protected Creature |
getCreature(Creature creature)
Get the internal representation of a creature.
|
Creature[] |
getCreatures()
Get the creatures.
|
protected Location |
getEmptyLocation()
Get an empty location.
|
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.
|
protected WorldObject[] |
getNearObjects(Location loc,
int range)
Get objects near a position.
|
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,
java.lang.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(jadex.commons.beans.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).
|
public static final int DEFAULT_LEASE_TICKS
protected static Environment instance
protected java.util.Map creatures
protected java.util.Set obstacles
protected java.util.Set food
public jadex.commons.collection.MultiCollection world
protected int sizex
protected int sizey
protected java.lang.Object monitor
protected java.util.List tasklist
protected jadex.commons.SimplePropertyChangeSupport pcs
protected java.util.Random rand
protected java.util.List highscore
protected long savetime
protected long saveinterval
protected int foodrate
protected int age
public static Environment getInstance()
public boolean moveUp(Creature me)
moveUp
in interface IEnvironment
public boolean moveDown(Creature me)
moveDown
in interface IEnvironment
public boolean moveLeft(Creature me)
moveLeft
in interface IEnvironment
public boolean moveRight(Creature me)
moveRight
in interface IEnvironment
public boolean eat(Creature me, WorldObject food)
eat
in interface IEnvironment
food
- The object.public TaskInfo addEatTask(Creature me, WorldObject obj)
public TaskInfo addMoveTask(Creature me, java.lang.String dir)
protected void clearTaskList()
public Vision internalGetVision(Creature me)
me
- The creature.public Vision getVision(Creature me)
getVision
in interface IEnvironment
me
- The creature.public int getWidth()
public int getHeight()
public void addFood(Food nfood)
nfood
- The new food.public boolean removeFood(Food nfood)
nfood
- Thefood.public void addObstacle(Obstacle obstacle)
obstacle
- The new obstacle.public boolean removeObstacle(Obstacle obstacle)
obstacle
- The obstacle.public Creature addCreature(Creature creature)
creature
- The creature.public boolean removeCreature(Creature creature)
creature
- The creature.public void executeStep()
public int getWorldAge()
public int getFoodrate()
public void setFoodrate(int foodrate)
foodrate
- The foodrate.public boolean move(Creature me, java.lang.String dir)
me
- The creature.dir
- The direction.public Creature[] getCreatures()
public Obstacle[] getObstacles()
public Food[] getFood()
public WorldObject[] getAllObjects()
protected Location createLocation(Location loc, java.lang.String dir)
loc
- The location.dir
- The direction.protected Location getEmptyLocation()
public int getTaskSize()
protected Creature getCreature(Creature creature)
creature
- The creature.protected WorldObject[] getNearObjects(Location loc, int range)
loc
- The location.range
- The range.public Creature[] getHighscore()
public void saveHighscore()
public void setSaveInterval(long saveinterval)
public long getSaveInterval()
public void addPropertyChangeListener(jadex.commons.beans.PropertyChangeListener listener)
listener
- The PropertyChangeListener to be added.public void removePropertyChangeListener(jadex.commons.beans.PropertyChangeListener listener)
listener
- The PropertyChangeListener to be removed.