|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JPanel Sugarscape.CellSpace
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
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 |
static long barterTime
private int birthCount
public final int BIRTHEVENT
java.util.List birthList
static int born
static java.io.BufferedOutputStream bos
Cell[][] cell
private int cellCols
private int cellRows
private boolean[][] cells
private int[][] cellsBuffer
private int cellSize
private boolean cellUnderMouse
private Citizen citizen
static int dead
private int deathByDerliction
private int deathByDotage
private int deathByStarvation
public final int DEATHEVENT
java.util.List deathList
static int destinationI
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
static long gatherTime
private Citizen mate
java.util.List mateList
static long mateTime
static java.lang.String msgStr
private java.awt.Graphics offScreenGraphics
static long otherTime
int population
static long startTime
public javax.swing.JTextArea textArea
private int totAge
private int totLifespan
private int totSpice
private int totSpMetab
private int totSugar
private int totSuMetab
private int totVision
private Citizen trader
java.util.List traderList
java.util.List zenList
Constructor Detail |
public CellSpace(int cellSize, int cellCols, int cellRows, javax.swing.JTextArea textArea)
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 |
public void bearChild(Citizen citizen, Citizen mate, int col, int row)
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.public boolean cellNMatesAvailable(Citizen citizen)
citizen
- citizen for whom mates are being sought.
public void clear()
public void createCells()
public int deleteOrphanCitizens(int newCellCols, int newCellRows)
newCellCols
- new value for number of columns on the grid.newCellRows
- new value for number of rows on the grid.
public void disburseInheritance(Citizen citizen)
citizen
- deceased citizen.public void dispersePollution()
public boolean drawRandomShape()
public boolean drawShape(int shapeWidth, int shapeHeight, int[] shape)
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.
public void drawSugarscape(int cols, int rows)
cols
- defines the number of columns on the Sugarscape.rows
- defines the number of rows on the Sugarscape.Sugarscape#drawSugarscape()
public static long getBarterTime()
public int getBirthCount()
public int getCellCols()
public int getCellRows()
public int getDeathByDerliction()
public int getDeathByDotage()
public int getDeathByStarvation()
public int getDistrAdults()
public int getDistrChildren()
public int getDistrEff()
public int getDistrFemale()
public int getDistrHyp()
public int getDistrHypSp()
public int getDistrHypSu()
public int getDistrIneff()
public int getDistrMale()
public int getDistrRiskAverse()
public int getDistrRiskTaker()
public int getDistrSeniors()
public int getDistrSlow()
public int getDistrSlowSp()
public int getDistrSlowSu()
public int getDistrSummer()
public int getDistrWinter()
public static long getGatherTime()
public static long getMateTime()
public static long getOtherTime()
public int getPopulation()
public int getTimePeriod()
GoLconst.timePeriod
public int getTotAge()
public int getTotLifespan()
public int getTotSpice()
public int getTotSpMetab()
public int getTotSugar()
public int getTotSuMetab()
public int getTotVision()
public void growGoods()
public void growGoodsBySeason()
public int incrementTime()
public boolean mouseDown(java.awt.Event evt, int x, int y)
evt
- x
- y
-
public boolean mouseDrag(java.awt.Event evt, int x, int y)
evt
- x
- y
- public boolean mouseUp(java.awt.Event evt, int x, int y)
evt
- event handle passed by system, not used.x
- x-axis parameter for pixel.y
- y-axis parameter for pixel.
private boolean moveNGather(int fromI, int fromJ, int toI, int toJ)
fromI
- column value of previous location.fromJ
- row value of previous location.toI
- column value of new location.toJ
- row value of new location.
public void next()
public void nextScape()
public void paint(java.awt.Graphics g)
g
- handle to the graphics object - used to draw the grid components
including cells and citizens.Cell.paintCell(java.awt.Graphics, int, int, int)
,
Citizen.paintZen(java.awt.Graphics, int)
public void pickMate()
public int populate()
GoLconst.DENSITY_FACTOR
public void resetScoreVars()
public void resetTimePeriod()
public void resizeCols(int cols)
cols
- the new value for columns in the grid.public void resizeRows(int rows)
rows
- the new value for rows in the grid.private boolean searchFarthestCell(Citizen citizen)
citizen
- the citizen for whom the method is being executed.
private boolean searchGridGoods(Citizen citizen)
citizen
- the citizen for whom the method is being executed.
private void searchNBarter(Citizen citizen)
citizen
- citizen currently exploring trade oppurtunities.private void setCellspaceStats(Citizen citizen, int event)
public void setDistrChildAdultSenior(Citizen citizen, int i)
i
- public void setDistrSeason(Citizen citizen, int i)
i
- public void setTotAge(Citizen citizen, int i)
i
- public void setTotSugarSpice(Citizen citizen, int i)
i
- public java.lang.String showCellStats(int col, int row)
col
- column location of the cell.row
- row location of the cell.
public java.lang.String showCitizenStats(java.lang.String message, int col, int row)
message
- col
- row
- public void showDebugSettings()
public void showPopulationStats(int infoType)
infoType
- represents amount of detail requested.public void showProcessStats()
public void showSpiceStats(int startCol, int startRow, int endCol, int endRow)
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.public void showSugarStats(int startCol, int startRow, int endCol, int endRow)
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.public void shuffleMates()
private void sortTraders(Citizen citizen)
citizen
- citizen currently exploring trade oppurtunities.public float sumPollutant()
public static long timeElapsed()
public boolean toggleCellUnderMouse(int x, int y)
x
- identifies the column where the cell is located.y
- identifies the row where the cell is located.
private int tradeGoods(Citizen citizen, Citizen trader)
citizen
- individual seeking to tradetrader
- individual whose offer has been accepted
public void update(java.awt.Graphics theG)
theG
- handle to the graphics object.public void writeText(java.lang.String text)
text
-
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |