FvdP HOME > Main index > Ants

Generalized Langton's ant, with programs

Quick introduction - what is an ant ?

An ant is here an automaton that moves on an infinite rectangular grid called the (ant's) world.

Each cell of the grid as a fixed number of states, numbered from 0 to N-1 (say); after an ant enters a cell, it turns left or right or back or continues straight ahead, according to the cell's state. After the ant leaves a cell, that cell's state is increased by one (wrapping from N-1 to 0).

This simple rule leads to surprisingly intricate ant trajectories.

An ant's rule is summarized by a sequence of characters:

Char. Meaning
+ turn left
- turn right
0 continue straight ahead
R U-turn ("reverse")

The i-th character (1 <= i <= N) tells the ant what to do in state i-1.

The original Langton's ant moves on a grid with two states 0="left" and 1="right" with the respective effect on the ant's trajectory. So its rule is "+-". Here is an image of Langton's ant's world after 11111 ant steps; yellow represents state 0=left, blue represents state 1=right, and the red square is the ant:

Langton's original ant after 11111 steps

At that time Langton's ant is actually building a highway.

The programs

I wrote two complementary programs to explore ant behaviour. Both programs allow for rules up to 65536 states at least, and the four +-0R instructions. To determine colours they can use palettes stored on disk under a simple text format (Fractint-compatible).

The first program, Ant-ology, features an unbounded world and the ability to zoom in into any fragment of this world, and to move inside the world by dragging with the mouse.

The second program, Ant-card, also offers an unbounded world but in a much less practical way (no zoom-in yet) and uses much more memory for each world cell; as a counterpart it is much faster and offers more flexible colouring schemes: you can colour cells according to diverse cell data.

Both programs require Windows 95 or NT4 or higher. (They may work with earlier versions but this has not been tested).

Ant-ology

Latest version:

Ant-Card

The second program was designed in order to study the cardioid generated by ant ++--, and hence is called AntCard (under the influence of a well-known DOS restriction, but on the other hand AntCard is no longer restricted to the cardioid-generating ant.) From the "scientifical" point of view it is much more complete, as it can display not only the world's current state, but several other measures about each world's cell C: (The cycle index is defined as the number of times the ant has passed through its original position.)

These measures can be displayed according to different scales (linear, logarithmic) with different palettes (it can read and write Fractint palette files).

From the aesthetic point of view it is richer too and produced images that I find appealing, some of them strangely reminiscent of astrophysical images.

Ant-card is also faster than Ant-ology, mainly because it does no try to be as clever about memory use and other nice but slow design tricks. (Most of Ant-card's memory use comes from the fact that it memorizes so much data about each world cell, though.)

Theory about ants

I'm going to expand this chapter in a new page, but I'm a bit lazy, so in short here are...

Some definitions to start with:

Some results:

and some open questions:

External links

Note that most other people consider ants with only + and - instructions, noted L and (ouch!) R.


(© Frédéric van der Plancke 2001; free of charge license is granted for private and non-profit educational purposes.)
FvdP HOME > Main index > Ants (top of page)