demo
Class CarryDropSpace

java.lang.Object
  extended bydemo.CarryDropSpace

public class CarryDropSpace
extends java.lang.Object

Space object for the CarryDropModel Includes functions for placing agents into the space, determining the amount of money at a given cell or in the entire space, moving agents, removing agents, etc.

Author:
John T. Murphy
University of Arizona, Department of Anthropology
Arizona State University, Center for Environmental Studies

Constructor Summary
CarryDropSpace(int xSize, int ySize)
          Constructor that takes as arguments to x,y dimensions of the space to be created
 
Method Summary
 boolean addAgent(CarryDropAgent agent)
          Add an agent to this space.
 CarryDropAgent getAgentAt(int x, int y)
          Return a pointer to the agent at position x,y.
 uchicago.src.sim.space.Object2DGrid getCurrentAgentSpace()
          Get the 'agent space' object
 uchicago.src.sim.space.Object2DGrid getCurrentMoneySpace()
          Get the 'money space' object
 int getMoneyAt(int x, int y)
          Get the amount of money currently stored at the cell location specified
 int getTotalMoney()
          Return the total money found in the landscape
 boolean IsCellOccupied(int x, int y)
          Determine if a given cell is occupied
 boolean moveAgentAt(int x, int y, int newX, int newY)
          Moves an agent from one location to another.
 void removeAgentAt(int x, int y)
          Removes the agent from the specified location.
 void spreadMoney(int money)
          Randomly distributes an amount of money around the landscape
 int takeMoneyAt(int x, int y)
          Removes the money found at the specified location
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CarryDropSpace

public CarryDropSpace(int xSize,
                      int ySize)
Constructor that takes as arguments to x,y dimensions of the space to be created

Parameters:
xSize - size of X dimension
ySize - size of Y dimension
Method Detail

spreadMoney

public void spreadMoney(int money)
Randomly distributes an amount of money around the landscape

Parameters:
money - the (total) amount of money to be distributed

getMoneyAt

public int getMoneyAt(int x,
                      int y)
Get the amount of money currently stored at the cell location specified

Parameters:
x - X coordinate of the desired cell
y - Y coordinate of the desired cell
Returns:
amount of money stored at cell X,Y

getAgentAt

public CarryDropAgent getAgentAt(int x,
                                 int y)
Return a pointer to the agent at position x,y. If no agent is found, returns null.

Parameters:
x - X coordinate of the desired cell
y - Y coordinate of the desired cell
Returns:
a pointer to the agent at X,Y, if any.

getCurrentMoneySpace

public uchicago.src.sim.space.Object2DGrid getCurrentMoneySpace()
Get the 'money space' object

Returns:
the Object2DGrid object in which money is stored

getCurrentAgentSpace

public uchicago.src.sim.space.Object2DGrid getCurrentAgentSpace()
Get the 'agent space' object

Returns:
the Object2DGrid object in which agents are stored

IsCellOccupied

public boolean IsCellOccupied(int x,
                              int y)
Determine if a given cell is occupied

Parameters:
x - X coordinate of the desired cell
y - Y coordinate of the desired cell
Returns:
True if there is an agent at X,Y, false otherwise

addAgent

public boolean addAgent(CarryDropAgent agent)
Add an agent to this space. Will place the agent in an unoccupied space. Note that this will attempt to place the agent randomly, making 10*XSize*YYSize tries before giving up.

Parameters:
agent - The agent to be placed
Returns:
True if the agent was successfully placed, false if not

removeAgentAt

public void removeAgentAt(int x,
                          int y)
Removes the agent from the specified location.

Parameters:
x - the X coordinate of the cell from which the agent is to be removed
y - the Y coordinate of the cell from which the agent is to be removed

takeMoneyAt

public int takeMoneyAt(int x,
                       int y)
Removes the money found at the specified location

Parameters:
x - the X coordinate of the cell from which the money is to be removed
y - the Y coordinate of the cell from which the money is to be removed
Returns:
the amount of money collected from the cell

moveAgentAt

public boolean moveAgentAt(int x,
                           int y,
                           int newX,
                           int newY)
Moves an agent from one location to another. Note that this will not fail if there is no agent at the original location; it will only fail if there is already an agent at the new location. (If there is no agent at the original location, all that happens is that nulls get moved around).

Parameters:
x - the X coordinate of the original location
y - the Y coordinate of the original location
newX - the X coordinate of the destination location
newY - the Y coordinate of the destination location
Returns:
true if the move was successful, false otherwise

getTotalMoney

public int getTotalMoney()
Return the total money found in the landscape

Returns:
total money found in the landscape