Wa-Tor Sharks and Fish from a magazine to Turbo Pascal

Sitting on the carpet in my father’s study, I used to browse through his copies of »Spektrum der Wissenschaft«1, which he had subscribed to at the time. Among the articles I came across was a description of a small world inhabited by sharks and fish, whose lives could be simulated with a few rules and a computer. That was something I wanted to try for myself, first in GFA BASIC on an Atari ST and later in Turbo Pascal on an MS-DOS computer. The latter program has survived as WATOR.PAS, with a file timestamp dating back to April 25, 19912.

A small ocean in my father’s study

The article was A. K. Dewdney’s Die kybernetische Saga vom Planeten Wa-Tor, published in »Spektrum der Wissenschaft« in 1985 on pages 6 to 133. The appealing part was that its inhabitants followed rules simple enough to turn into a program of my own. The magazine supplied the idea and explained how it worked, leaving the enjoyable business of making it run on my computer to me.

The world described in the article consisted of water, fish and sharks. Fish moved about and reproduced, while sharks moved about, ate fish and reproduced as well, provided they found enough food to stay alive. A fish needed somewhere to go, a shark needed something to eat, and neither had any knowledge of the population as a whole. Nevertheless, their individual activities could produce recognizable patterns across the ocean.

What interested me was the connection between those simple instructions and what would eventually appear on the screen. Reading the description was one thing, but translating it into a running program meant having to settle all the small questions hidden inside an apparently straightforward rule. What happens at the edge of the sea? Where does a newborn fish appear? And how do you stop a fish from moving twice just because its new position happens to be visited later in the same pass through the ocean?

A magazine could describe a small world, and a home computer could provide somewhere to try out its rules.

BASIC programming afternoons with a friend

A friend of mine was interested in these sorts of things as well. We liked meeting in our spare time, either at his place or at mine, to do something nerdy, which might mean tinkering with electronics or writing programs. If I remember correctly, it was my friend who came along with Game of Life, which we also programmed, and I subsequently discovered Wa-Tor. Both fitted rather well into the things we enjoyed doing together.

We had started programming in BASIC on 8-bit home computers. In my case, that included an Atari 600XL with a memory expansion and, before it, a Sinclair ZX81 handed down by my eldest brother. My mother had bought the ZX81 for him for Christmas, probably in 1982, although 1981 is another date I remember. By the time it became mine, it was already a computer on which somebody else in the family had taken his first steps.

The interesting part of having one of those machines was being able to make it do something of your own. An idea from a magazine could become an array, a few loops and something happening on the screen, with the inevitable corrections in between. Having a friend interested in the same experiments made them part of how we spent our afternoons, alongside our electronic tinkering.

The two simulations offered related reasons to experiment. In Conway’s Game of Life, cells survive, die or become occupied according to their neighbors. In Wa-Tor, individual animals move, breed and, in the case of sharks, hunt for food. Both invite the programmer to specify local rules and then watch the consequences spread over a larger area, although the particular rules and the way time advances differ.

From the Atari ST to MS-DOS

My first implementation of Wa-Tor was written in GFA BASIC on an Atari ST. Unfortunately, those sources are lost, so the version I can examine today is the program I later wrote in Turbo Pascal after getting an MS-DOS computer. It preserves another implementation of the idea, rather than a record from which I could reconstruct every detail of the earlier Atari version.

The surviving program is quite modest. Its ocean occupies 69 columns and 22 rows of the text screen, with black dots for fish and red 0 characters for sharks against a blue background. There are no little fins or animated tails, although a zero makes a serviceable shark once you know what it is supposed to represent.

The screenshots above were taken on November 4, 2026, in DOSBox, using an executable compiled from the unchanged source with Turbo Pascal 5.5. They show successive moments from one run, rather than images retained from 1991. The banner is an enlarged crop of the third screenshot, so its sharks and fish belong to the same small ocean.

The video below shows another uninterrupted run of the same program with the same settings.

A sea whose edges meet

The ocean has no shore. A fish leaving the right-hand edge reappears at the left-hand edge, and the top and bottom are connected in the same way. Mathematically, these connections give the rectangular grid the topology of a torus, the familiar doughnut shape. The program does not have to draw a doughnut or calculate a three-dimensional surface, because reconnecting the coordinates is sufficient for the animals’ movements.

In the Pascal source, this happens immediately after calculating a neighboring position:

1
2
3
4
5
6
xn:=x+zug[t*2-1];
yn:=y+zug[t*2];
if xn<1 then xn:=maxx;
if yn<1 then yn:=maxy;
if yn>maxy then yn:=1;
if xn>maxx then xn:=1;

There is a small difference from the model Dewdney described. His animals could move north, east, south or west, whereas my program considers all eight surrounding positions, including the diagonals. The direction table contains eight pairs of offsets, and a loop collects the suitable neighboring positions before choosing one at random. The screenshots therefore show the behavior of this particular implementation, with its own neighborhood and order of processing.

The drawing below comes from the English original article, which appeared in »Scientific American« in December 1984. Its circles and dots make the relationship to the text-screen display rather apparent, even though my ocean has a different size and different movement rules.

Keeping track of fish and sharks

Each position needs to record whether it is empty or occupied, along with enough information to decide when its inhabitant may reproduce. My program combines these in a single integer array named see, German for lake. A zero denotes water, a positive value denotes a fish and a negative value denotes a shark. The magnitude records a breeding counter, so adding to a positive value ages a fish and subtracting from a negative value ages a shark.

The initial population consists of 53 fish and five sharks, placed at randomly selected empty positions. Their breeding counters also receive random initial values, which means that they do not all begin at the same point in their breeding cycle. The settings are constants near the beginning of the source:

1
2
3
4
5
6
7
const fasten=4;
      hbrut=12;
      fbrut=6;
      maxf=53;
      maxh=5;
      maxx=69;
      maxy=22;

The names are abbreviated German. The breeding thresholds are fbrut for fish and hbrut for sharks, while fasten, meaning fasting, is the hunger threshold for sharks. The values describe the settings in this file, and changing them means editing and recompiling the source.

A fish looks for empty neighboring positions and moves to one selected at random. If its breeding counter has reached the threshold when it moves, a young fish remains at the old position and both counters are set to one. When a fish cannot move, its counter still increases, but reproduction waits until a move succeeds. This is one of the details that is easier to understand from the source than from simply saying that fish reproduce at a certain age.

A shark first looks for a neighboring fish. If there is one, it chooses among the available fish, moves to that position and resets its hunger counter, thereby replacing the fish with a fed shark. If there is no fish to eat, it tries to move to an empty position and becomes hungrier. A shark that cannot move becomes hungrier as well, and the program removes it when its hunger counter equals four at the beginning of its next turn. Sharks reproduce on a successful move once their breeding counter reaches the threshold, leaving a young shark behind.

The order of these operations matters. This program updates the ocean in place, visiting positions column by column and processing the animal found there. Later positions can therefore see changes made earlier in the same pass. The result is a sequential simulation with random movement choices, whose behavior depends on more than its population and breeding settings alone.

That leaves the question of the fish which might move twice. An animal moving to a position further along the scan would otherwise be encountered again, which would give it another turn. Two Boolean arrays, fischzug and haizug, record whether a fish or shark at a position has already taken its turn. The program marks destinations when animals move, also marks offspring, and clears the flags after finishing the pass through the ocean.

Moving an animal changes both its position and what the rest of the current pass through the ocean will encounter.

These are simple mechanisms, but they make the written rules concrete. The source also contains traces of things which do nothing in the surviving version, including a constant named chrono with the value 500. Despite that promising name, there is no delay or timing call using it, so the program runs as fast as its loops and screen output allow. I have left such details as they are in the downloadable source.

Running the surviving program

The original WATOR.PAS is available alongside a newly compiled WATOR.EXE. With Turbo Pascal 5.5, compilation required no changes to the source and produced a 6,336-byte executable. It uses the standard Crt and Dos units, including a BIOS call to hide the cursor, which is why an emulated DOS environment is useful for running it on a current computer.

To try the executable, place it in a directory of its own and mount that directory in DOSBox. For example, on a Linux system with the file in /tmp/wator:

mount c /tmp/wator
c:
cycles fixed 3000
wator.exe

The simulation starts immediately, and pressing a key ends it. There is no parameter dialog or population chart, so watching the colored characters is the whole interface. The screenshots were captured with DOSBox’s fixed cycle setting of 3,000, which slows the program enough to follow its changing arrangement4. Since the source initializes its random generator from the clock, a new run will generally begin with another distribution of animals.

Returning to Wa-Tor with the REFCODES SDK

On November 8, 2026, I returned to the experiment and created funcodes-wator with the REFCODES SDK, so that the little ocean can also run as a Java application on a current computer. The simulation retains the Pascal version’s eight neighbors, connected edges and column-by-column updates, while its dimensions, initial populations and breeding and starvation settings can now be changed without recompiling. The same Wa-Tor application provides a command-line display, a text user interface (TUI) and a graphical user interface (GUI) built with JavaFX, with the REFCODES components providing the forms and checkerboard views. Both forms allow a new run, a single generation or a reset, and an explicit random seed makes a Java run reproducible, although it does not reproduce Turbo Pascal’s random sequence.

The screenshots below show the new application as captured on November 8, 20265, with dots and arrowheads in the terminal and small fish and sharks swimming through blue water in the graphical view. The manpage describes the controls and options, and the application is available from the downloads page.

Back to the magazines

Looking at the program today brings back the circumstances in which the idea reached me, sitting on the carpet in my father’s study with his magazines, and the afternoons when my friend and I could occupy ourselves with electronics or programming. The Atari sources are lost, but the Pascal file still provides a working example of what could follow from reading an interesting article and wanting to try its idea. A small blue rectangle with dots and zeros is enough to remind me why that was an enjoyable way to spend my time.

See also

  1. The magazine »Spektrum der Wissenschaft« is the German edition of »Scientific American«. ↩

  2. This retrospective is dated to the original file’s retained modification timestamp, April 25, 1991, at 16:48:26. That timestamp identifies the surviving version, rather than proving the date on which work on either implementation began. The DOS executable, DOSBox screenshots and video accompanying this article were produced on November 4, 2026. ↩

  3. A. K. Dewdney, Die kybernetische Saga vom Planeten Wa-Tor, »Spektrum der Wissenschaft«, 1985, pp. 6-13. The English original is Sharks and fish wage an ecological war on the toroidal planet Wa-Tor, »Scientific American«, volume 251, number 6, December 1984, pp. 14-22, DOI 10.1038/scientificamerican1284-14. A scan of the English article is hosted by Gettysburg College. The figure above is an excerpt from page 19 of that English article. ↩

  4. These are DOSBox’s emulation settings, rather than a direct measurement of the original computer’s speed. The program contains no active frame limiter. Build details, recording settings and image provenance are recorded in the accompanying reproduction notes. ↩

  5. These are captures of funcodes-wator version 2026.11.0, built with the REFCODES 5.0.0-SNAPSHOT SDK. The capture settings and provenance are recorded in the Java application screenshot notes. ↩