uk.ac.nott.cs.g54dia.library
Class Environment

java.lang.Object
  extended by uk.ac.nott.cs.g54dia.library.Environment

public class Environment
extends java.lang.Object

An infinite grid of cells representing the current state of the environment at a given timestep.

Each cell in the Environment implements the Cell interface.


Field Summary
private  CellFactory cfactory
          CellFactory which is called to generate new environment.
private  java.util.Map<Point,Cell> map
          Mapping from an (x,y) point to a Cell.
 java.util.ArrayList<Station> stations
          List of stations
private  long timestep
          Current timestep of the simulation.
 
Constructor Summary
Environment(int size)
           
Environment(int size, CellFactory factory)
          Initialises the Tanker environment.
 
Method Summary
private  void generateTasks()
           
 Cell getCell(Point pos)
          Get the cell at a specified location
 long getTimestep()
          Get the current timestep.
 Cell[][] getView(Point pos, int size)
          Return the cells a Tanker can see.
 void putCell(Cell c)
          Add a cell to the environment.
 void tick()
          Increase timestep.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private java.util.Map<Point,Cell> map
Mapping from an (x,y) point to a Cell.


cfactory

private CellFactory cfactory
CellFactory which is called to generate new environment.


timestep

private long timestep
Current timestep of the simulation.


stations

public java.util.ArrayList<Station> stations
List of stations

Constructor Detail

Environment

public Environment(int size,
                   CellFactory factory)
Initialises the Tanker environment. Creates an initial environment of wells.

Parameters:
size - size of the initial environment
factory - factory used to create new cells

Environment

public Environment(int size)
Method Detail

getView

public Cell[][] getView(Point pos,
                        int size)
Return the cells a Tanker can see.

Parameters:
pos - position of the Tanker
size - distance the Tanker can see
Returns:
an array containing the cells visible from pos.

getCell

public Cell getCell(Point pos)
Get the cell at a specified location

Parameters:
pos - coordinates of the cell

getTimestep

public long getTimestep()
Get the current timestep.

Returns:
the current timestep

tick

public void tick()
Increase timestep.


putCell

public void putCell(Cell c)
Add a cell to the environment.

Parameters:
c - cell to be added

generateTasks

private void generateTasks()