ImgBin

Artificial Life. Langton’s ant in C++

A two-dimensional universal Turing machine called Langton’s ant has very few rules but exhibits remarkable emergent behavior. Chris Langton came up with the idea in 1986, and it functions on a square lattice of black and white cells.

Ant simulation (by author)

Following is a quick explanation of Langton’s ant problem based on Studying Artificial Life with Cellular Automata.
Black or white is used to color squares on a plane. We can identify one square to represent the ant.
Each step the ant takes allows it to move in one of the four directions. The ant moves in accordance with these rules:

  • At a black square, turn 90° counter-clockwise, flip the color of the square, and move forward one unit.

The ant behavior depending on the cell color can be depicted in the following figure,

Langton’s ant (by author)

I implemented the following rules in C++ and the source you can find on my GitHub.

In order to use Eigen C++ library, visit the website. Download the Eigen repository to your favorite location on your machine and (for Linux users) create the soft link.

git clone https://gitlab.com/libeigen/eigen.git
sudo ln -s /usr/include/eigen3/Eigen /usr/local/include/
/usr/include/eigen3/Eigen <-- location of your cloned library

Thank you for reading.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store