|
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--uwcse.sim.WorldModel
A WorldModel is a relatively efficient representation of the world. The world is chopped up into a number of cells so that interactions can be efficiently computed. Things will typically ask the model about their "neighbors" (those Things that live in the same simulation cell) and questions such as these can be efficiently answered. Things can also ask questions like: give me the list of things that are in the neighboring cell... The smaller the cellsize, the more "fine-grained" the simulation will be; a very large cellsize can be used for simple, flat, simulations where regional associations are not important.
The WorldModel is also responsible for "stepping" the simulation. Each step fo the simulation consists of several phases:
Field Summary | |
static int |
DEFAULT_CELL_SIZE
The default cell size. |
static Offset |
EAST
Often used offset representing the neighboring cell to the east. |
static Offset |
NORTH
Often used offset representing the neighboring cell to the north. |
static Offset |
NORTHEAST
Often used offset representing the neighboring cell to the northeast. |
static Offset |
NORTHWEST
Often used offset representing the neighboring cell to the northwest. |
static Offset |
SOUTH
Often used offset representing the neighboring cell to the south. |
static Offset |
SOUTHEAST
Often used offset representing the neighboring cell to the southeast. |
static Offset |
SOUTHWEST
Often used offset representing the neighboring cell to the southwest. |
static Offset |
WEST
Often used offset representing the neighboring cell to the west. |
Constructor Summary | |
WorldModel()
Create a new, empty world model of default cell size. |
|
WorldModel(int cellSize)
Create a new, empty world model of the given cell size. |
Method Summary | |
void |
add(Thing t)
Add the given thing to the world. |
void |
addView(WorldView v)
Add the given view. |
void |
birth()
Add all items in the nursery to the world. |
void |
doTurn()
The basic turn of the simulation consists of calling birth(), action(), reap(), and notifyViews(). |
java.util.Iterator |
getThings()
Get all the things in the world. |
java.util.List |
getThings(Thing t)
Get the neighbors of this thing, that is, those Things that inhabit the same cell. |
java.util.List |
getThings(Thing t,
java.util.List offSets)
Get the things that inhabit the cells that are in the given list of directions from the cell inhabited by the given thing. |
java.util.List |
getThings(Thing t,
Offset dir)
Get the things that inhabit the cell that is in the given direction from the cell inhabited by the given thing. |
void |
go()
Call init(), and then loop forever, calling doTurn() and sleeping for the sleepTime. |
void |
go(int cycles)
Call init(), and then loop for the given number of cycles. |
void |
init()
Initialize the world. |
void |
map(uwcse.sim.WorldModel.CallBack cb)
Map this call back over the world. |
void |
notifyViews()
Notify the views to let them do their thing. |
void |
remove(Thing t)
Remove a thing from the world map. |
void |
setSleepTime(int newTime)
|
int |
size()
Answer the number of things in the world. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int DEFAULT_CELL_SIZE
public static final Offset EAST
public static final Offset NORTH
public static final Offset NORTHEAST
public static final Offset NORTHWEST
public static final Offset SOUTH
public static final Offset SOUTHEAST
public static final Offset SOUTHWEST
public static final Offset WEST
Constructor Detail |
public WorldModel()
public WorldModel(int cellSize)
Method Detail |
public void add(Thing t)
public void addView(WorldView v)
public void birth()
public void doTurn()
public java.util.Iterator getThings()
public java.util.List getThings(Thing t)
public java.util.List getThings(Thing t, java.util.List offSets)
public java.util.List getThings(Thing t, Offset dir)
public void go()
public void go(int cycles)
public void init()
public void map(uwcse.sim.WorldModel.CallBack cb)
public void notifyViews()
public void remove(Thing t)
public void setSleepTime(int newTime)
public int size()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |