Skip to content
Transfinity edited this page Sep 15, 2012 · 13 revisions

Here is an overview of the design of the fish tank simulation.

Visualizer

The visualizer will be the graphical interface for the simulation. It will contain the main method, initialize and start the engine, and graphically display the changing state of the fish tank simulation. The visualizer itself will be a thread which spawns the engine and periodically polls it for the current state to display. The main method will spawn the visualization thread and then wait for user input to define how to alter or stop the simulation.

  • implements Runnable
  • main() - Parse any command-line arguments, start the visualization thread, poll for user input to interact with the simulation.
  • draw(State s) - Draw each fish and plant from state 's' to the window.
  • run() - Repeatedly call draw() on the most recent state from the engine.

Engine

The engine will run the fish tank simulation, keep track of statistics, and provide read-only access to the current state.

  • implements Runnable
  • private State backState - The engine calculates this state from the frontState.
  • private State frontState - The current state of the simulation
  • public State getState() - return the frontState
  • run() - Repeatedly calculate next state by looking at each fish's rudder direction and speed, check for collisions, and update statistics.
  • private FishAI createNewSpecies() - The engine calls this function to add a new fish species to the simulation.
  • private Queue newFishQueue - When a FishAI wants to reproduce, it will tell the engine which fish will split, and the engine will allocate the new fish and put it in this queue. On the next state update, the engine will take the Fish out of this queue and give it a position.
  • public Fish reproduce(Fish) - The FishAI calls this function to reproduce. It takes a Fish as an argument, then uses some of the Fish's gathered nutrients to create a new Fish to add to the newFishQueue. It returns the newly generated Fish.
  • public void grow(Fish) - The FishAI calls this function to grow a fish. It takes a Fish as an argument, then uses some of the Fish's gathered nutrients to increase the Fish's size.

State

The state will store all of the fish in the tank.

  • Map<Fish, Vector> fishLocations - store a map of Fish in the tank to their positions.
  • Map<PlantCell, Vector> plantLocations - store a map of Plants in the tank to their positions.
  • int length - The length of the tank.
  • int height - The height of the tank.
  • long ID - The identifier for the state (monotonically increasing integer)
  • public Vector location(Fish) - Looks up the location of the fish
  • public Vector location(PlantCell) - Looks up the location of the plant cell

Agents

Clone this wiki locally