Langton's ant is now the star of a computer program used to show the difference between understanding a complete theory of the Universe and totally understanding its consequences.

The ant wanders around on an infinite square grid of black and white squares. When the ant walks onto a white square, it changes colour from white to black and the ant turns right and if it walks onto a black square the square changes to white and the ant turns left.

The ant first moves around the grid in very simple steps, making simple and symmetrical patterns. This happens for the first hundred or so moves.

After that, the movements of the ant appear to be chaos. Of course, it's still following the same rules as before, it just doesn't look so structured.

Finally, order emerges. The ant begins to build a highway. It goes through a series of 104 steps then after which it has moved out two squares diagonally and the shapes and colours along the edges are the same. The ant repeats this behaviour for ever.

It seems that the ant follows this pattern whatever configuration of black and white squares is used at the start. The ant shows that simple rules can have complex consequences.

Langton's Ant is a very simple system which demonstrates emergent behaviour.

An ant starts in the middle of a large square grid (100 by 100 is large enough), and initially all the squares are white. It is facing North.

When the ant is on a white square, it paints the square black, turns right 90 degrees, and steps into the next square. When the ant is on a black square, it paints the square white, turns left 90 degrees, and steps into the next square.

For about the first 400 steps, the ant creates symmetrical patterns. This is intuitively expected; the rules by which the ant operates are symmetrical, so the result of applying the rules should also be symmetrical. Suddenly, it appears to change 'mode' and wander about irregularly; its behaviour is very obviously different, but it is still following the same two rules. With a simple enough environment (all or mostly white squares), the simple rules have simple consequences; once the environment gets more complicated (with the pattern the ant itself creates), the simple rules have more complex consequences. After about 10000 steps the ant changes behaviour again; it builds a diagonal stripe across the grid (going South-West); and again, a very regular pattern emerges in the ant's path (theoretically, the ant would extend the stripe to infinity).

The shape and structure of the stripe is described nowhere in the ant's behaviour-rules. Yet it is a clear result of them; it's impossible to not notice it after seeing 11000 steps or more. This is an emergent property of the system.

Source: The Science of Discworld, by Terry Pratchett, Ian Stewart, and Jack Cohen, and my own OPL program I wrote so I could see the ant on my Psion 5mx:
``` PROC main:   LOCAL x%   LOCAL y%   LOCAL d%   LOCAL n%   LOCAL p%   LOCAL k\$(1)   LOCAL a%(10000)   x% = 50   REM x% increases in the East direction   y% = 50   REM y% increases in the South direction   d% = 0   REM d% = 0 for North, 1 for East, 2 for South, 3 for West   p% = 0   REM p% is nonzero for pausing the animation   n% = 10000   REM n% is first used to clear the 'map', then is used to count the number of steps the ant has taken   WHILE (n% > 0)     a%(n%) = 0     n% = (n% - 1)   ENDWH   CLS   k\$ = KEY\$   WHILE ((k\$ <> " ") AND (x% >= 0) AND (y% >= 0) AND (x% < 100) AND (y% < 100))     gAT x%, y%     IF (a%((y% * 100) + x% + 1) = 0)       REM set the point       gGMODE 0       gLINEBY 0, 0       a%((y% * 100) + x% + 1) = 1       REM turn right       IF (d% = 0)         d% = 1         x% = (x% + 1)       ELSEIF (d% = 1)         d% = 2         y% = (y% + 1)       ELSEIF (d% = 2)         d% = 3         x% = (x% - 1)       ELSEIF (d% = 3)         d% = 0         y% = (y% - 1)       ENDIF     ELSE       REM clear the point       gGMODE 1       gLINEBY 0, 0       a%((y% * 100) + x% + 1) = 0       REM turn left       IF (d% = 0)         d% = 3         x% = (x% - 1)       ELSEIF (d% = 1)         d% = 0         y% = (y% - 1)       ELSEIF (d% = 2)         d% = 1         x% = (x% + 1)       ELSEIF (d% = 3)         d% = 2         y% = (y% + 1)       ENDIF     ENDIF     n% = (n% + 1)     AT 30, 1     PRINT n%     k\$ = KEY\$     IF (k\$ = "p")       p% = (1 - p%)     ENDIF     WHILE ((p% <> 0) AND (k\$ <> "s") AND (k\$ <> " "))       k\$ = KEY\$       IF (k\$ = "p")         p% = 0       ENDIF     ENDWH   ENDWH   WHILE (k\$ <> " ")     k\$ = KEY\$   ENDWH ENDP ``` The 'p' key pauses the animation ('s' will run the animation one step) until 'p' is pressed again, the animation stops when the ant hits the edge of the grid, and the program stops when the 'space' key is pressed.

Log in or register to write something here or to contact authors.