Sugarscape
Class CellSpace

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended bySugarscape.CellSpace
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class CellSpace
extends javax.swing.JPanel

Implements the CellSpace object that defines the Sugarscape grid. Implements grid-level methods of the project. Implements data collection and display methods for results of the executing simulation. CellSpace encompasses the Cell object. Also contains the Graphics objects that is used to draw the Sugarspace display

Author:
abraham kannankeril
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
(package private) static long barterTime
           
private  int birthCount
           
 int BIRTHEVENT
           
(package private)  java.util.List birthList
           
(package private) static int born
           
(package private) static java.io.BufferedOutputStream bos
           
(package private)  Cell[][] cell
           
private  int cellCols
           
private  int cellRows
           
private  boolean[][] cells
           
private  int[][] cellsBuffer
           
private  int cellSize
           
private  boolean cellUnderMouse
           
private  Citizen citizen
           
(package private) static int dead
           
private  int deathByDerliction
           
private  int deathByDotage
           
private  int deathByStarvation
           
 int DEATHEVENT
           
(package private)  java.util.List deathList
           
(package private) static int destinationI
           
(package private) static int destinationJ
           
private  int distrAdults
           
private  int distrChildren
           
private  int distrEff
           
private  int distrFemale
           
private  int distrHyp
           
private  int distrHypSp
           
private  int distrHypSu
           
private  int distrIneff
           
private  int distrMale
           
private  int distrRiskAverse
           
private  int distrRiskTaker
           
private  int distrSeniors
           
private  int distrSlow
           
private  int distrSlowSp
           
private  int distrSlowSu
           
private  int distrSummer
           
private  int distrWinter
           
(package private) static long gatherTime
           
private  Citizen mate
           
(package private)  java.util.List mateList
           
(package private) static long mateTime
           
(package private) static java.lang.String msgStr
           
private  java.awt.Graphics offScreenGraphics
           
(package private) static long otherTime
           
(package private)  int population
           
(package private) static long startTime
           
 javax.swing.JTextArea textArea
          Used to display simulation data and command feedback to the user.
private  int totAge
           
private  int totLifespan
           
private  int totSpice
           
private  int totSpMetab
           
private  int totSugar
           
private  int totSuMetab
           
private  int totVision
           
private  Citizen trader
           
(package private)  java.util.List traderList
           
(package private)  java.util.List zenList
           
 
Fields inherited from class javax.swing.JPanel
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CellSpace(int cellSize, int cellCols, int cellRows, javax.swing.JTextArea textArea)
          CellSpace constructor - resizes physical dimensions for the Sugarscape Defines Linked list objects that contain the citizen population.
 
Method Summary
 void bearChild(Citizen citizen, Citizen mate, int col, int row)
          Bears child inheriting characteristics of citizen and mate.
 boolean cellNMatesAvailable(Citizen citizen)
          Examines adjacent cells to determine if any prospective mates are available and for an empty cell in which to bear a child.
 void clear()
          Clears Grid, empties the Citizen List and (re)initializes grid vars.
 void createCells()
          Creates instances of the Cell object.
 int deleteOrphanCitizens(int newCellCols, int newCellRows)
          Eliminates citizens marooned by dynamic reduction in grid dimension.
 void disburseInheritance(Citizen citizen)
          Disburses wealth of a dead citizen equally among its offspring.
 void dispersePollution()
          Periodic dispersal of accumulated pollution caused by gathering activity.
 boolean drawRandomShape()
          Draws random pattern for the first time in Game of Life template.
 boolean drawShape(int shapeWidth, int shapeHeight, int[] shape)
          Draws selected pattern for the first time in Game of Life template.
 void drawSugarscape(int cols, int rows)
          Executes simulation processes for the first time when the Sugarscape template is selected.
static long getBarterTime()
           
 int getBirthCount()
           
 int getCellCols()
           
 int getCellRows()
           
 int getDeathByDerliction()
           
 int getDeathByDotage()
           
 int getDeathByStarvation()
           
 int getDistrAdults()
           
 int getDistrChildren()
           
 int getDistrEff()
           
 int getDistrFemale()
           
 int getDistrHyp()
           
 int getDistrHypSp()
           
 int getDistrHypSu()
           
 int getDistrIneff()
           
 int getDistrMale()
           
 int getDistrRiskAverse()
           
 int getDistrRiskTaker()
           
 int getDistrSeniors()
           
 int getDistrSlow()
           
 int getDistrSlowSp()
           
 int getDistrSlowSu()
           
 int getDistrSummer()
           
 int getDistrWinter()
           
static long getGatherTime()
           
static long getMateTime()
           
static long getOtherTime()
           
 int getPopulation()
          Reports the current population size.
 int getTimePeriod()
          Returns the current cycle or time period of the simulation under execution.
 int getTotAge()
           
 int getTotLifespan()
           
 int getTotSpice()
           
 int getTotSpMetab()
           
 int getTotSugar()
           
 int getTotSuMetab()
           
 int getTotVision()
           
 void growGoods()
          Generate initial/periodic distribution of sugar in Cellspace when seasonal processes inactive.
 void growGoodsBySeason()
          Generate initial/periodic distribution of sugar in Cellspace when seasonal processes have been activated.
 int incrementTime()
          Increments time period by one
 boolean mouseDown(java.awt.Event evt, int x, int y)
          Cell selection operation
Copies status of cell selected by the user.
 boolean mouseDrag(java.awt.Event evt, int x, int y)
          Calls routine to toggle status of a range of cells selected by dragging the mouse.
 boolean mouseUp(java.awt.Event evt, int x, int y)
          Calls routine to toggle current cell status.
private  boolean moveNGather(int fromI, int fromJ, int toI, int toJ)
          Moves citizen to a new location previously identified by the search methods.
 void next()
          Determines the next generation in the Game of Life templates
 void nextScape()
          Executes simulation processes for subsequent cycles or time periods.
 void paint(java.awt.Graphics g)
          The main paint method for (re)drawing the Sugarscape.
 void pickMate()
          Attaches weights to each mate based on their ranking.
 int populate()
          Populates cells in the Sugarscape based on a frequency determined by the global constant DENSITY_FACTOR in GoLconst.java.
 void resetScoreVars()
           
 void resetTimePeriod()
          Resets the time period for a new round of the simulation
 void resizeCols(int cols)
          Initiates change in the number of columns on the grid.
 void resizeRows(int rows)
          Initiates change in the number of rows on the grid.
private  boolean searchFarthestCell(Citizen citizen)
          Search process for farthest cell within range specified by citizen's vision.
private  boolean searchGridGoods(Citizen citizen)
          Search process for citizens seeking sugar and spice on the Sugarscape.
private  void searchNBarter(Citizen citizen)
          Barter process defining needs evaluation, prospects search, negotiation and mutually beneficial exchange of goods by denizens of the Sugarscape.
private  void setCellspaceStats(Citizen citizen, int event)
          Tabulates statistics to reflect changes to the Sugarscape population.
 void setDistrChildAdultSenior(Citizen citizen, int i)
           
 void setDistrSeason(Citizen citizen, int i)
           
 void setTotAge(Citizen citizen, int i)
           
 void setTotSugarSpice(Citizen citizen, int i)
           
 java.lang.String showCellStats(int col, int row)
          Calls the relevant Cell method to display stats for a given cell.
 java.lang.String showCitizenStats(java.lang.String message, int col, int row)
           
 void showDebugSettings()
          Display settings for all DEBUG switches.
 void showPopulationStats(int infoType)
          Calculate and display detailed stats on Cellspace population.
 void showProcessStats()
          Displays time slices used by various broadly defined processes.
 void showSpiceStats(int startCol, int startRow, int endCol, int endRow)
          Display the spice distribution on the Sugarscape.
 void showSugarStats(int startCol, int startRow, int endCol, int endRow)
          Display the sugar distribution on the Sugarscape.
 void shuffleMates()
          Shuffles list of mates before selection of final partner.
private  void sortTraders(Citizen citizen)
          Method called when multiple prospects available for trade with a citizen.
 float sumPollutant()
          Calculates pollutant accumulated in cells on the grid.
static long timeElapsed()
          Process timekeeper - Tracks time elapsed since the last call to this method.
 boolean toggleCellUnderMouse(int x, int y)
          Called by the mouseUp & mouseDrag methods.
private  int tradeGoods(Citizen citizen, Citizen trader)
          Determines the trade price, flow of goods and units to be exchanged.
 void update(java.awt.Graphics theG)
           
 void writeText(java.lang.String text)
          Attempt to write simulation data to diskfile - have to find another way of doing this as Java security does not permit this operation.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseEnter, mouseExit, mouseMove, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

barterTime

static long barterTime

birthCount

private int birthCount

BIRTHEVENT

public final int BIRTHEVENT
See Also:
Constant Field Values

birthList

java.util.List birthList

born

static int born

bos

static java.io.BufferedOutputStream bos

cell

Cell[][] cell

cellCols

private int cellCols

cellRows

private int cellRows

cells

private boolean[][] cells

cellsBuffer

private int[][] cellsBuffer

cellSize

private int cellSize

cellUnderMouse

private boolean cellUnderMouse

citizen

private Citizen citizen

dead

static int dead

deathByDerliction

private int deathByDerliction

deathByDotage

private int deathByDotage

deathByStarvation

private int deathByStarvation

DEATHEVENT

public final int DEATHEVENT
See Also:
Constant Field Values

deathList

java.util.List deathList

destinationI

static int destinationI

destinationJ

static int destinationJ

distrAdults

private int distrAdults

distrChildren

private int distrChildren

distrEff

private int distrEff

distrFemale

private int distrFemale

distrHyp

private int distrHyp

distrHypSp

private int distrHypSp

distrHypSu

private int distrHypSu

distrIneff

private int distrIneff

distrMale

private int distrMale

distrRiskAverse

private int distrRiskAverse

distrRiskTaker

private int distrRiskTaker

distrSeniors

private int distrSeniors

distrSlow

private int distrSlow

distrSlowSp

private int distrSlowSp

distrSlowSu

private int distrSlowSu

distrSummer

private int distrSummer

distrWinter

private int distrWinter

gatherTime

static long gatherTime

mate

private Citizen mate

mateList

java.util.List mateList

mateTime

static long mateTime

msgStr

static java.lang.String msgStr

offScreenGraphics

private java.awt.Graphics offScreenGraphics

otherTime

static long otherTime

population

int population

startTime

static long startTime

textArea

public javax.swing.JTextArea textArea
Used to display simulation data and command feedback to the user.


totAge

private int totAge

totLifespan

private int totLifespan

totSpice

private int totSpice

totSpMetab

private int totSpMetab

totSugar

private int totSugar

totSuMetab

private int totSuMetab

totVision

private int totVision

trader

private Citizen trader

traderList

java.util.List traderList

zenList

java.util.List zenList
Constructor Detail

CellSpace

public CellSpace(int cellSize,
                 int cellCols,
                 int cellRows,
                 javax.swing.JTextArea textArea)
CellSpace constructor - resizes physical dimensions for the Sugarscape Defines Linked list objects that contain the citizen population. Defines the Cell objects that make the grid.

Parameters:
cellSize - Defines the size of each individual cell.
cellCols - Defines the number of columns on the grid.
cellRows - Defines the number of rows on the grid.
textArea - Handle to the text area for display of program feedback.
Method Detail

bearChild

public void bearChild(Citizen citizen,
                      Citizen mate,
                      int col,
                      int row)
Bears child inheriting characteristics of citizen and mate. Transfers wealth from parents to child as its inheritance. Updates mating details for parents.

Parameters:
citizen - active parent, can be male or female.
mate - selected partner, opposite sex of citizen.
col - column location of newborn citizen.
row - row location of newborn citizen.

cellNMatesAvailable

public boolean cellNMatesAvailable(Citizen citizen)
Examines adjacent cells to determine if any prospective mates are available and for an empty cell in which to bear a child. Prospective mates are checked for compatibility and child-supporting capability. If all Ok, they are added to a prospective mates list.

Parameters:
citizen - citizen for whom mates are being sought.
Returns:
boolean, signalling availability of atleast one mate and empty cell for newborn child.

clear

public void clear()
Clears Grid, empties the Citizen List and (re)initializes grid vars.


createCells

public void createCells()
Creates instances of the Cell object. The number of instances are determined by the product of the number of columns and rows.


deleteOrphanCitizens

public int deleteOrphanCitizens(int newCellCols,
                                int newCellRows)
Eliminates citizens marooned by dynamic reduction in grid dimension.

Parameters:
newCellCols - new value for number of columns on the grid.
newCellRows - new value for number of rows on the grid.
Returns:
number of citizens eliminated by resizing the grid.

disburseInheritance

public void disburseInheritance(Citizen citizen)
Disburses wealth of a dead citizen equally among its offspring. Executed only when inheritance process is activated.

Parameters:
citizen - deceased citizen.

dispersePollution

public void dispersePollution()
Periodic dispersal of accumulated pollution caused by gathering activity.


drawRandomShape

public boolean drawRandomShape()
Draws random pattern for the first time in Game of Life template.

Returns:
True,after completion of random pattern.

drawShape

public boolean drawShape(int shapeWidth,
                         int shapeHeight,
                         int[] shape)
Draws selected pattern for the first time in Game of Life template.

Parameters:
shapeWidth - Max width of the pattern to be drawn on the grid.
shapeHeight - Max height of the pattern to be drawn on the grid.
shape - Boolean array defining the pattern to be displayed on the grid.
Returns:
returns false if shape doesn't fit within current grid dimensions.

drawSugarscape

public void drawSugarscape(int cols,
                           int rows)
Executes simulation processes for the first time when the Sugarscape template is selected. Populates the Sugarscape with a random distribution of citizens based on the frequency configured in the global constant DENSITY_FACTOR.

Parameters:
cols - defines the number of columns on the Sugarscape.
rows - defines the number of rows on the Sugarscape.
See Also:
Sugarscape#drawSugarscape()

getBarterTime

public static long getBarterTime()
Returns:
time slice claimed by bartering processes.

getBirthCount

public int getBirthCount()
Returns:

getCellCols

public int getCellCols()
Returns:

getCellRows

public int getCellRows()
Returns:

getDeathByDerliction

public int getDeathByDerliction()
Returns:

getDeathByDotage

public int getDeathByDotage()
Returns:

getDeathByStarvation

public int getDeathByStarvation()
Returns:

getDistrAdults

public int getDistrAdults()
Returns:

getDistrChildren

public int getDistrChildren()
Returns:

getDistrEff

public int getDistrEff()
Returns:

getDistrFemale

public int getDistrFemale()
Returns:

getDistrHyp

public int getDistrHyp()
Returns:

getDistrHypSp

public int getDistrHypSp()
Returns:

getDistrHypSu

public int getDistrHypSu()
Returns:

getDistrIneff

public int getDistrIneff()
Returns:

getDistrMale

public int getDistrMale()
Returns:

getDistrRiskAverse

public int getDistrRiskAverse()
Returns:

getDistrRiskTaker

public int getDistrRiskTaker()
Returns:

getDistrSeniors

public int getDistrSeniors()
Returns:

getDistrSlow

public int getDistrSlow()
Returns:

getDistrSlowSp

public int getDistrSlowSp()
Returns:

getDistrSlowSu

public int getDistrSlowSu()
Returns:

getDistrSummer

public int getDistrSummer()
Returns:

getDistrWinter

public int getDistrWinter()
Returns:

getGatherTime

public static long getGatherTime()
Returns:
time slice claimed by food gathering processes.

getMateTime

public static long getMateTime()
Returns:
time slice claimed by mate search & child-birth processes.

getOtherTime

public static long getOtherTime()
Returns:
time slice claimed by processes other than gather, mate & barter.

getPopulation

public int getPopulation()
Reports the current population size.

Returns:
number of citizens

getTimePeriod

public int getTimePeriod()
Returns the current cycle or time period of the simulation under execution. The variable is accessed from the global constants file, GoLconst.java

Returns:
GoLconst.timePeriod
See Also:
GoLconst.timePeriod

getTotAge

public int getTotAge()
Returns:

getTotLifespan

public int getTotLifespan()
Returns:

getTotSpice

public int getTotSpice()
Returns:

getTotSpMetab

public int getTotSpMetab()
Returns:

getTotSugar

public int getTotSugar()
Returns:

getTotSuMetab

public int getTotSuMetab()
Returns:

getTotVision

public int getTotVision()
Returns:

growGoods

public void growGoods()
Generate initial/periodic distribution of sugar in Cellspace when seasonal processes inactive.


growGoodsBySeason

public void growGoodsBySeason()
Generate initial/periodic distribution of sugar in Cellspace when seasonal processes have been activated.


incrementTime

public int incrementTime()
Increments time period by one

Returns:
new timeperiod

mouseDown

public boolean mouseDown(java.awt.Event evt,
                         int x,
                         int y)
Cell selection operation
Copies status of cell selected by the user. If occupied, eliminates citizen or creates new citizen otherwise.

Parameters:
evt -
x -
y -
Returns:
always returns true

mouseDrag

public boolean mouseDrag(java.awt.Event evt,
                         int x,
                         int y)
Calls routine to toggle status of a range of cells selected by dragging the mouse. If occupied, eliminates citizen, creates new citizen otherwise.

Parameters:
evt -
x -
y -

mouseUp

public boolean mouseUp(java.awt.Event evt,
                       int x,
                       int y)
Calls routine to toggle current cell status. If occupied, eliminates citizen or creates new citizen otherwise.

Parameters:
evt - event handle passed by system, not used.
x - x-axis parameter for pixel.
y - y-axis parameter for pixel.
Returns:
always returns true

moveNGather

private boolean moveNGather(int fromI,
                            int fromJ,
                            int toI,
                            int toJ)
Moves citizen to a new location previously identified by the search methods. If sugar and/or spice available at new location, it is gathered by citizen.

Parameters:
fromI - column value of previous location.
fromJ - row value of previous location.
toI - column value of new location.
toJ - row value of new location.
Returns:
boolean, signalling successful relocation.

next

public void next()
Determines the next generation in the Game of Life templates


nextScape

public void nextScape()
Executes simulation processes for subsequent cycles or time periods. Tracks time spent on various broadly defined processes, list of dying and newborn citizens. Perhaps the main execution loop for the simulation.


paint

public void paint(java.awt.Graphics g)
The main paint method for (re)drawing the Sugarscape. Based on the template group selected (Game of Life / Sugarscape), the appropriate grid is displayed. The method then determines the status of the cell and calls either Cell paint, if the cell is empty or the Citizen paint method. Column and row coordinates are also displayed based on options configured in the global constants file.

Parameters:
g - handle to the graphics object - used to draw the grid components including cells and citizens.
See Also:
Cell.paintCell(java.awt.Graphics, int, int, int), Citizen.paintZen(java.awt.Graphics, int)

pickMate

public void pickMate()
Attaches weights to each mate based on their ranking. Higher ranking increases selection chances.
Randomly selects mate.


populate

public int populate()
Populates cells in the Sugarscape based on a frequency determined by the global constant DENSITY_FACTOR in GoLconst.java.

Returns:
the new population size.
See Also:
GoLconst.DENSITY_FACTOR

resetScoreVars

public void resetScoreVars()

resetTimePeriod

public void resetTimePeriod()
Resets the time period for a new round of the simulation


resizeCols

public void resizeCols(int cols)
Initiates change in the number of columns on the grid.

Parameters:
cols - the new value for columns in the grid.

resizeRows

public void resizeRows(int rows)
Initiates change in the number of rows on the grid.

Parameters:
rows - the new value for rows in the grid.

searchFarthestCell

private boolean searchFarthestCell(Citizen citizen)
Search process for farthest cell within range specified by citizen's vision. The most distant or a random selection from equally distant locations is made.

Parameters:
citizen - the citizen for whom the method is being executed.
Returns:
boolean, signalling the success/failure of the search.

searchGridGoods

private boolean searchGridGoods(Citizen citizen)
Search process for citizens seeking sugar and spice on the Sugarscape. Search area is defined by the vision of each citizen. The most fertile or a random selection among equally fertile locations is made.

Parameters:
citizen - the citizen for whom the method is being executed.
Returns:
boolean, signalling the success/failure of the search.

searchNBarter

private void searchNBarter(Citizen citizen)
Barter process defining needs evaluation, prospects search, negotiation and mutually beneficial exchange of goods by denizens of the Sugarscape. This method calculates the Marginal Rate of Substitution for a citizen and builds a list of compatible trade partners. It then ranks those offers in order of desirability to the citizen. Finally, it completes the exchange of goods with one or more traders based on how much the citizen wishes to trade.

Parameters:
citizen - citizen currently exploring trade oppurtunities.

setCellspaceStats

private void setCellspaceStats(Citizen citizen,
                               int event)
Tabulates statistics to reflect changes to the Sugarscape population. This method is called when a birth or death event occurs, triggering a reevaluation of census data on the Sugarscape.


setDistrChildAdultSenior

public void setDistrChildAdultSenior(Citizen citizen,
                                     int i)
Parameters:
i -

setDistrSeason

public void setDistrSeason(Citizen citizen,
                           int i)
Parameters:
i -

setTotAge

public void setTotAge(Citizen citizen,
                      int i)
Parameters:
i -

setTotSugarSpice

public void setTotSugarSpice(Citizen citizen,
                             int i)
Parameters:
i -

showCellStats

public java.lang.String showCellStats(int col,
                                      int row)
Calls the relevant Cell method to display stats for a given cell.

Parameters:
col - column location of the cell.
row - row location of the cell.
Returns:
string, containing cell stats.

showCitizenStats

public java.lang.String showCitizenStats(java.lang.String message,
                                         int col,
                                         int row)
Parameters:
message -
col -
row -

showDebugSettings

public void showDebugSettings()
Display settings for all DEBUG switches.


showPopulationStats

public void showPopulationStats(int infoType)
Calculate and display detailed stats on Cellspace population. Includes:
Population distribution by needs/abilities is an arbitrary attempt to group citizens based on their characteristics and preferences. The classification comprises eight categories as follows:

Parameters:
infoType - represents amount of detail requested.

showProcessStats

public void showProcessStats()
Displays time slices used by various broadly defined processes.


showSpiceStats

public void showSpiceStats(int startCol,
                           int startRow,
                           int endCol,
                           int endRow)
Display the spice distribution on the Sugarscape.

Parameters:
startCol - column value for top-left cell of grid.
startRow - row value for top-left cell of grid.
endCol - column value for bottom-right cell of grid.
endRow - row value for bottom-right cell of grid.

showSugarStats

public void showSugarStats(int startCol,
                           int startRow,
                           int endCol,
                           int endRow)
Display the sugar distribution on the Sugarscape.

Parameters:
startCol - column value for top-left cell of grid.
startRow - row value for top-left cell of grid.
endCol - column value for bottom-right cell of grid.
endRow - row value for bottom-right cell of grid.

shuffleMates

public void shuffleMates()
Shuffles list of mates before selection of final partner.


sortTraders

private void sortTraders(Citizen citizen)
Method called when multiple prospects available for trade with a citizen. Offers are sorted by price variance.

Parameters:
citizen - citizen currently exploring trade oppurtunities.

sumPollutant

public float sumPollutant()
Calculates pollutant accumulated in cells on the grid.

Returns:
total accumulated pollutant on the grid.

timeElapsed

public static long timeElapsed()
Process timekeeper - Tracks time elapsed since the last call to this method.

Returns:
time elapsed since last call.

toggleCellUnderMouse

public boolean toggleCellUnderMouse(int x,
                                    int y)
Called by the mouseUp & mouseDrag methods. Does the actual work marking a citizen for elimination if the cell is occupied or creating a new citizen in the cell when it is empty.

Parameters:
x - identifies the column where the cell is located.
y - identifies the row where the cell is located.
Returns:
True, upon completion of operation.

tradeGoods

private int tradeGoods(Citizen citizen,
                       Citizen trader)
Determines the trade price, flow of goods and units to be exchanged. It then executes the exchange and recalculates preferences of the citizen and his/her trading partner.

Parameters:
citizen - individual seeking to trade
trader - individual whose offer has been accepted
Returns:
amount of surplus still available for trade by citizen.

update

public void update(java.awt.Graphics theG)
Parameters:
theG - handle to the graphics object.

writeText

public void writeText(java.lang.String text)
Attempt to write simulation data to diskfile - have to find another way of doing this as Java security does not permit this operation.

Parameters:
text -