An implementation of Langton's Ant using the C 2018 standard. Note that the initial placement of the Ant in this program is at random.
- The Ant is denoted by a '*' char that is analogous to a read/write head.
- Memory cells are represented by a two-dimensional char array. Each cell is like a square on a chessboard. Each cell can either contain a '#', or a ' '. We call these two states "black" and "white."
- The Ant can move forward, change orientation by 90 degrees (clockwise or counterclockwise), and be seated on either a black or a white square.
- The Ant's next move is entirely dependent upon its current state. A history of the ant's previous states is not necessary to predict its next move.
Because our program is composed of a read/write head (1) that can execute a discrete number of operations (3) upon a geographic arrangement of discrete memory cells (2), Langton's Ant is a Turing Machine.
Furthermore, because the Ant has no notion of history (4), and there are a discrete number of head-states (by combining 2, and 3), Langton's Ant can be modeled with automata theory. This can be implemented with the help of a doubly-linked list.
- Clone or download.
- Open a terminal windows, navigate to this project's directory.
-
Enter this command at the prompt:
make
Now you have an executable sitting in your working directory called langtons_ant.out
It can be invoked with three integers as arguments:
./langtons_ant.out <rows> <columns> <turns>
Here's the last printout of the state of the ant at the last turn:
./langtons_ant.out 15 12 25000
