Skip to content
cole14 edited this page Sep 19, 2012 · 13 revisions

Here is an overview of the implementation design of the fishtank simulation.

Check out the Class List for a less-organized, but possibly more up-to-date version of this information!

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(long ID) - This method will block until 'frontState.ID' > 'ID' at which point it will return 'frontState'. This is how the visualizer and AI's will interface with the simulation. The argument 'ID' should generally be the ID of the previously returned state, or 0 on initialization. This allows the State consumers to avoid the worry of 'running too fast'.
  • run() - Repeatedly calculate the next state by looking at each fish's rudder direction and speed, checking for collisions, and updating statistics.

Note that this part of the Engine interface may not represent the current design of the implementation...

  • 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