For awhile now I have had more than a passing interest in a computer science phenomenon known as cellular automata. These are computations that follow a set of rules (aka algorithms) to produce “cells” of that morph overtime and can make elaborate and often complex structures from relatively simple rules. While these were discovered in the 1940’s, the classic example of cellular automata is Conway’s Game of Life (https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) .

Note see that running on a Tandy 100 at my post here:

There happens to be several good books on cellular automata if you want a deeper dive. Stephen Wolfram, of Wolfram Alpha, wrote an extensive treatise on the topic - https://www.wolframscience.com/nks/

In my exploration of the topic, I determined that the classic block building game Minecraft would be a great avenue to explore building a cellular automaton without too much code. Using some Python I was able to generate Langton’s Ant. Langton’s Ant follows these rules:

- at a white square, turn 90deg clockwise, flip color of square, move forward one step
- at a black square, turn 90deg counter-clockwise, flip color of square, move forward one step

```
import time
from mcpi.minecraft import Minecraft
mc = Minecraft.create()
while True:
# Starting position
x = 2790
y = 90
z = 32560
deg = 0
# Set blank canvas
mc.setBlocks(x - 500, y, z - 500, x + 500, y, z + 500, 0)
for a in range(1, 11000):
print(a)
block = mc.getBlock(x, y, z)
if block == 0: # air
mc.setBlock(x, y, z, 41)
if deg == 0:
deg = 90
x = x + 1
elif deg == 90:
deg = 180
z = z + 1
elif deg == 180:
deg = 270
x = x - 1
elif deg == 270:
deg = 0
z = z - 1
elif block == 41: # gold
mc.setBlock(x, y, z, 0)
if deg == 0:
deg = 270
x = x - 1
elif deg == 90:
deg = 0
z = z - 1
elif deg == 180:
deg = 90
x = x + 1
elif deg == 270:
deg = 180
z = z + 1
```

Then I figured, why not build Martin, Odlyzko and Wolfram’s rule 90? (doi:10.1007/BF01223745)

Rule 90 defined by this table:

111 | 110 | 101 | 100 | 011 | 010 | 001 | 000 |
---|---|---|---|---|---|---|---|

0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 |

```
import time
from mcpi.minecraft import Minecraft
mc = Minecraft.create()
# Starting blocks
x = 2719
y = 20
z = 32482
mc.setBlocks(x, y, z, x + 98, y, z + 98, 35) # whool
mc.setBlock(2769, y, z, 89) # set initial gold block
for b in range(1,99):
blockminus = 0
for a in range(1,99):
# Read blocks
blockminus = mc.getBlock(x - 1, y, z)
block = mc.getBlock(x, y, z)
blockplus = mc.getBlock(x + 1, y, z)
# Set blocks for the automaton machine
mc.setBlock(x, y + 1, z, block)
mc.setBlock(x - 3, y + 1, z, 0)
# Rule algorithm to set blocks
if block == 57: # diamond
break
elif blockplus == 89 or blockminus == 89: # gold block
if blockplus == 89 and blockminus == 89:
mc.setBlock(x, y, z + 1, 35) # whool
else:
mc.setBlock(x, y, z + 1, 89) # gold
x = x + 1
if a == 98:
mc.setBlocks(x - 4, y + 1, z, x, y + 1, z, 0)
x = 2719
z = z + 1
print(b)
# Slow down
time.sleep(3)
# Reset starting blocks
x = 2719
y = 20
z = 32482
```