WATOR

Predator-Prey Simulation

A Java Applet


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

Contents


Description

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.


Implementation

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. Move a slide to the right to increase a parameter; move left to decrease. The simulation may be slowed by moving the delay slide to the right, increasing the delay.

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. This program runs reasonably well on Seamonkey 2.33 under Windows XP and Vista, and Mac OS 10.6. 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.

In 1995, when Java security was a "sandbox," this applet was compiled class files. Circa 2015, the old Java security was found inadequate. Java security became traceability to a trusted source, for a price. This applet is now an untraced, self-signed archive file. The user is welcome to take the source code for any needed security procedure.


Source Code

wator.java 20,706 bytes Java source code
wator.jar 22,866 bytes Java archive of compiled code

Reference

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