Java Reference
In-Depth Information
Code 10.3
continued
Part of the Simulator
class
* given number of steps.
* Stop before the given number of steps if it ceases to
* be viable.
* @param numSteps The number of steps to run for.
*/
public void simulate( int numSteps)
{
for ( int step = 1; step <= numSteps &&
view.isViable(field); step++) {
simulateOneStep();
}
}
/**
* Run the simulation from its current state for a single
* step.
* Iterate over the whole field, updating the state of
* each fox and rabbit.
*/
public void simulateOneStep()
{
// method body omitted
}
/**
* Reset the simulation to a starting position.
*/
public void reset()
{
step = 0;
rabbits.clear();
foxes.clear();
field.clear();
populate();
// Show the starting state in the view.
view.showStatus(step, field);
}
/**
* Populate the field with foxes and rabbits.
*/
private void populate()
{
Random rand = Randomizer.getRandom();
field.clear();
Search WWH ::




Custom Search