Predator-Prey Simulation

A Java Applet

The "wator" java applet intended to occupy this space can not run under this browser.



WATOR is a simulation of the interaction over time of predator and prey in a small rectangular area. It is a simple program originally described by A.K. Dewdney in Scientific American magazine. The game is to arrange the parameters so the populations are stable when the area is made small.

The program is dependent upon five parameters, plus the size of the rectangular grid. The first parameter is the number of fish, the prey. A fish swims at random to one of the four horizontally or vertically adjacent spaces on the grid, if it is unoccupied. The grid wraps around so a fish can swim off one edge and appear at the opposite edge. The second parameter is the fish breed time. If a fish survives this number of cycles and an open space is available, a new fish is bred. The third parameter is the number of sharks, the predators. A shark eats a fish in an adjacent space on the grid. A shark swims to an open space if there is no adjacent fish. The fourth parameter is the shark starve time. If a shark finds no fish for this number of cycles, it dies. The final parameter is the shark breed time. A shark breeds in the same way as a fish.

If the number of sharks is very small, the fish population will increase quickly and the shark population will soon follow because they find plenty of food. Eventually the fish will become overcrowded and overwhelmed by the large shark population and the fish population will crash. Depending upon the quantity and distribution of sharks at the beginning of the crash, the fish may disappear entirely, the sharks may become isolated and disappear or catastrophe may be narrowly averted.

Studies of small, isolated biological systems that lack diversity have shown similar patterns, though never as simply. The ebb and flow of populations is interesting in itself and there is probably slim evidence to support any particular social or political philosophy.


This program shows the simulated Wa-tor world at the top and a graph of the populations at the bottom. The slides to adjust the parameters are shown at the right of the Wa-tor world, with control buttons below the slides.

Fish are green, sharks, red and the background is light blue. The graph shows the numbers of fish and sharks with zero at the bottom and the total number of spaces on the grid at the top. A vertical black line sweeps from left to right moving one pixel each cycle and when it reaches the right edge, wraps around to the left edge. When any of the parameters is altered or the Remix button is pushed, the discontinuity is noted with a vertical white line.

When a breed or starve parameter is altered, each fish and shark receives the new value after it next breeds or eats. When a fish or shark is created, its breed and starve values are randomized somewhat. The numbers of fish and sharks are updated continuously by the program, but may be altered by the user. Whenever the numbers of fish or sharks or the size of the grid is altered, the simulation is remixed.

The geometry of fish and sharks on the grid affects the simulation, and is well mixed initially. This can be done explicitly with the Remix button. The simulation can be paused and restarted with the Stop and Go buttons. Your browser may suspend the program independently when it is scrolled off the screen.

Usage Notes

This is a Java Applet. If your browser does not support Java, imagine a program running in a window within this web page, near the top. The language appears to be relatively new and thus unstable. This program runs reasonably well on Netscape 3.0 under Windows 95, but there is reason to believe it will not work as well elsewhere. There is no reason to believe this programmer understands the documentation.

If most of the toolbars and such are cleared away, the entire program can be viewed at once with a high screen resolution, or in two halves in a low resolution.

There is no persistent information associated with this program. There is no record of it after your browser quits.

Source Code

wator.java 13,846 bytes Java source (4 classes)
wator.class 6,508 bytes Top level compiled class
panelmap.class 3,641 bytes Simulation compiled class
panelgrf.class 2,187 bytes Graph compiled class
fish.class 1,337 bytes Fish/shark object compiled class


A.K. Dewdney
Sharks and fish wage an ecological war on the toroidal planet Wa-Tor
(Scientific American, December 1984)
Larry Leinweber, Proprietor

Return to Larry's Cerebral Snack Bar