Sugarscape
Class Cell

java.lang.Object
  extended bySugarscape.Cell

class Cell
extends java.lang.Object

This is a component of the Sugarscape object. The Sugarscape is a 2D grid of cell objects. The number of instances is simply the product of the number of rows and columns in the grid. The object is created when the Sugarscape is first instantiated. Cells may be added or removed as the grid is resized dynamically by the user.

Author:
abraham kannankeril

Field Summary
 Citizen citizen
          Citizen object container within the cell.
(package private)  float pollution
           
(package private)  float spice
           
(package private)  float sugar
           
 
Constructor Summary
Cell()
          Constructor object, initializes quantities of sugar and spice within the cell.
 
Method Summary
 float getPollution()
          Returns the current level of pollution in the cell.
 float getSpice()
          Returns the current stock of spice in the cell.
 float getSugar()
          Returns the current stock of sugar in the cell.
 boolean notOccupied()
          Returns false when cell is occupied by a citizen.
 void paintCell(java.awt.Graphics g, int x, int y, int cellSize)
          Updates the Cell background of an empty cell.
 void setPollution(int actionFlag)
          Recalculates pollution for the cell.
 void setSpice(float quantity)
          Initializes the quantity of spice in a cell to a pre-specified or random amount.
 void setSugar(float quantity)
          Initializes the quantity of sugar in a cell to a pre-specified or random amount.
 java.lang.String showStats(int col, int row)
          Returns a string describing the sugar, spice and pollution levels within the cell.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

citizen

public Citizen citizen
Citizen object container within the cell. Initialized to null, when no citizen is present.

See Also:
Citizen

pollution

float pollution

spice

float spice

sugar

float sugar
Constructor Detail

Cell

public Cell()
Constructor object, initializes quantities of sugar and spice within the cell.

Method Detail

getPollution

public float getPollution()
Returns the current level of pollution in the cell.


getSpice

public float getSpice()
Returns the current stock of spice in the cell.


getSugar

public float getSugar()
Returns the current stock of sugar in the cell.


notOccupied

public boolean notOccupied()
Returns false when cell is occupied by a citizen.


paintCell

public void paintCell(java.awt.Graphics g,
                      int x,
                      int y,
                      int cellSize)
Updates the Cell background of an empty cell. Also indicates the quantity of both goods graphically in the form of horizontal bars. The display can be configured as two or three-dimensional.

Parameters:
g - handle to the graphics object - used to draw the grid components including cells and citizens.
x - axis coordinate identifying the top left corner of the cell to be redrawn.
y - axis coordinate identifying the top left corner of the cell to be redrawn.
cellSize - Each cell is a square, this defines the length of one side in pixels.
See Also:
GoLconst.CELL_3D

setPollution

public void setPollution(int actionFlag)
Recalculates pollution for the cell. If the parameter equals 1, then determines the pollution caused by the harvesting of sugar in the cell. Each unit harvested contributes GoLconst.POLLUTION_PRODUCTION_SUGAR amount of pollution; If the parameter equals 2, then determines the pollution caused by the harvesting of spice in the cell. Each unit harvested contributes GoLconst.POLLUTION_PRODUCTION_SPICE amount of pollution; If the parameter equals 0, then pollution dispersal process is executed. Pollution is reduced by amount specified in GoLconst.POLLUTION_DISPERSION_UNIT. Pollution dispersal occurs once per cycle / time period.

Parameters:
actionFlag -

setSpice

public void setSpice(float quantity)
Initializes the quantity of spice in a cell to a pre-specified or random amount. If the parameter is greater than zero, stores that value as the new quantity of spice in the cell; if the parameter equals zero, signifies that the spice is being harvested. Calls the setPollution method to calculate pollution caused by harvesting, then resets spice quantity to zero; if the parameter is less than zero, then randomly determines whether cell is to contain spice or be barren. The probability for this is determined by the constant GoLconst.GRID_FERTILITY_SPICE. If it determined that the cell will grow spice, then the actual quantity is randomly determined within a range of 0 - GoLconst.SPICE_MAX_CELL.

Parameters:
quantity - value that can be positive, 0 or -1.

setSugar

public void setSugar(float quantity)
Initializes the quantity of sugar in a cell to a pre-specified or random amount. If the parameter is greater than zero, stores that value as the new quantity of sugar in the cell; if the parameter equals zero, signifies that the sugar is being harvested. Calls the setPollution method to calculate pollution caused by harvesting, then resets sugar quantity to zero; if the parameter is less than zero, then randomly determines whether cell is to contain sugar or be barren of sugar. The probability for this is determined by the constant GoLconst.GRID_FERTILITY_SUGAR. If it determined that the cell will grow sugar, then the actual quantity is randomly determined within a range of 0 - GoLconst.SUGAR_MAX_CELL.

Parameters:
quantity - value that can be positive, 0 or -1.

showStats

public java.lang.String showStats(int col,
                                  int row)
Returns a string describing the sugar, spice and pollution levels within the cell.

Parameters:
col - displays stats for cell at column identified by this value
row - displays stats for cell at row identified by this value