Main Page | Class Hierarchy | Class List | Class Members | Related Pages

blockworld.Env Class Reference

environment. More...

Inheritance diagram for blockworld.Env:

blockworld.lib.ObsVectListener List of all members.

Public Member Functions

Agent addAgent (String name)
 Add agent to the world.

void removeAgent (Agent agent)
 Called by the interpreter when the agent this instance refers to is about to be removed from the platform.

Agent removeAgent (String name)
boolean enter (Agent agent, final Point position, long timeout)
 enter the environment via some entrance.

boolean addStone (Point position) throws IndexOutOfBoundsException
 set stone at position

boolean removeStone (Point position)
 remove stone at position

boolean setAgentPosition (Agent agent, Point position, long timeout)
boolean doAgentNorth (Agent a, long timeout)
 Move up.

boolean doAgentEast (Agent a, long timeout)
 Move up.

boolean doAgentSouth (Agent a, long timeout)
 Move down.

boolean doAgentWest (Agent a, long timeout)
 Move left.

boolean doAgentPickup (Agent agent)
 Attempt to take bomb from agent's current location.

boolean doAgentDrop (Agent agent)
 Attempt to drop bomb at agent's current location.

Agent senseAgent (Point p)
 Check for agent at coordinate.

void onAdd (int index, Object o)
void onRemove (int index, Object o)
void clear ()
void save (OutputStream destination) throws IOException
void load (InputStream source) throws IOException, ClassNotFoundException
void addAgentListener (ObsVectListener o)
 This listener is notified upon changes regarding the Agent list.

void addStonesListener (ObsVectListener o)
 This listener is notified upon changes regarding the Stones list.

void addBombsListener (ObsVectListener o)
 This listener is notified upon changes regarding the Bombs list.

Collection agents ()
void setTrap (Point trap)
 Set bomb trap location.

Point getTrap ()
void setSize (Dimension size)
 resize world

void setSize (int width, int height)
 helper function, calls setSize(Dimension)

int getWidth ()
int getHeight ()
void setSenseRange (int senserange)
int getSenseRange ()

Public Attributes

transient Signal signalSenseRangeChanged = new Signal("env sense range changed")
 emitted if sense range changed

transient Signal signalSizeChanged = new Signal("env size changed")
 emitted if environment is resized

transient Signal signalTrapChanged = new Signal("env trap position changed")
 emitted if bomb trap location changed

transient Signal signalEntranceChanged = new Signal("env entrance changed")
 emitted if entrance position changed

transient Signal signalBombTrapped = new Signal("env bomb trapped")
 emitted on collection of a bomb in the bomb trap


Protected Member Functions

boolean outOfBounds (Point p)
 check if point is within environment boundaries


Protected Attributes

ObsVect _agents = new ObsVect(this)
 list of agents (Agent)

ObsVect _stones = new ObsVect()
 list of coordinates (Point) containing stones

ObsVect _bombs = new ObsVect()
 list of coordinates (Point) containing bombs

Dimension _size = new Dimension(16,16)
 size of environment

Point _trap = new Point(2,2)
 location of bomb trap

Point _entrance = new Point(0,0)
 location of entrance

int _senserange = 10
 number of cells visible to each agent


Package Functions

boolean addBomb (Point position) throws IndexOutOfBoundsException
 drop bomb at specified position

boolean removeBomb (Point position)
 attempt to remove bomb at specified position

Collection senseBombs (Point position)
 Sense visible area for bombs.

Collection senseStones (Point position)
 Sense visible area for stones.

Collection senseAgents (Point position)
 Sense visible area for agents. This does not include self.

boolean senseBomb (Point p)
 see if there is a stone at the specified coordinate

boolean senseStone (Point p)
 see if there is a stone at the specified coordinate


Detailed Description

environment.

main storage for agents and bombs, stones etc.

Todo:
use _entrance IMPORTANT


Member Function Documentation

Agent blockworld.Env.addAgent String  name  ) 
 

Add agent to the world.

It will be put in a queue of agents waiting to enter the environment.

Todo:
check name to be uniq

void blockworld.Env.addAgentListener ObsVectListener  o  ) 
 

This listener is notified upon changes regarding the Agent list.

Please note that this only involves registering new agents or removing existing agents. To track agent position changes, add a listener to that specific agent.

See also:
Agent

boolean blockworld.Env.addBomb Point  position  )  throws IndexOutOfBoundsException [package]
 

drop bomb at specified position

Todo:
this can be done more efficient, using different datastruct

do not allow bomb dropping on repository

boolean blockworld.Env.doAgentDrop Agent  agent  ) 
 

Attempt to drop bomb at agent's current location.

Returns:
False on failure (eg. not carrying bomb), true on success

boolean blockworld.Env.doAgentEast Agent  a,
long  timeout
 

Move up.

The X component represents the horizontal position of the agent, with (0,0) being the top left position. Moving right thus means x = x + 1.

Returns:
false on failure (eg. stone in place)

boolean blockworld.Env.doAgentNorth Agent  a,
long  timeout
 

Move up.

The Y component represents the vertical position of the agent, with (0,0) being the top left position. So moving up means y = y - 1.

Parameters:
timeout Block if north is not possible, until timeout milliseconds elapsed. A value of 0 (obviously) means no timeout at all. A value of -1 means infinity timeout - be carefull with this, it may cause agent deadlocking (eg. both agents waiting for each other to move out of the way).
a To which agent this operation should be applied
Returns:
false on failure (eg. stone in place)

boolean blockworld.Env.doAgentPickup Agent  agent  ) 
 

Attempt to take bomb from agent's current location.

Returns:
False on failure (eg. already carrying bomb), true on success
Todo:
cleanup Agent._bomb

boolean blockworld.Env.doAgentSouth Agent  a,
long  timeout
 

Move down.

Returns:
false on failure (eg. stone in place)

boolean blockworld.Env.doAgentWest Agent  a,
long  timeout
 

Move left.

Returns:
false on failure (eg. stone in place)

boolean blockworld.Env.enter Agent  agent,
final Point  position,
long  timeout
 

enter the environment via some entrance.

This method will wait (block) infinitely until the entrance is free if the timeout argument is ommitted or has value -1.

Todo:
block with timeout until entrance is free

maybe implement signalEnter signal instead of signalMove

boolean blockworld.Env.outOfBounds Point  p  )  [protected]
 

check if point is within environment boundaries

Returns:
false is p is within bounds

Agent blockworld.Env.removeAgent String  name  ) 
 

Todo:
stuff agents in hashmap for efficiency

void blockworld.Env.removeAgent Agent  agent  ) 
 

Called by the interpreter when the agent this instance refers to is about to be removed from the platform.

This will remove the agent from the environment, it also removes all listeners.

Todo:
move this call from agent to Plugin factory and actually remove agent

boolean blockworld.Env.removeBomb Point  position  )  [package]
 

attempt to remove bomb at specified position

Returns:
true on succes
Todo:
this can be done more efficient, using different datastruct

Agent blockworld.Env.senseAgent Point  p  ) 
 

Check for agent at coordinate.

Returns:
Null if there is no agent at the specified coordinate. Otherwise return a reference to the agent there.

boolean blockworld.Env.setAgentPosition Agent  agent,
Point  position,
long  timeout
 

Todo:
implement blocking + timeout

void blockworld.Env.setSize Dimension  size  ) 
 

resize world

Todo:
remove bombs IMPORTANT

void blockworld.Env.setTrap Point  trap  ) 
 

Set bomb trap location.

Agents must dispose bombs here.

Todo:
check bounds etc


The documentation for this class was generated from the following file:
Generated on Wed Jun 16 17:22:45 2004 for blockworld by doxygen 1.3.7