Skip to content

blaskode/langtons_ant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

langtons_ant.c

  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.

Some properties of Langton's Ant

  1. The Ant is denoted by a '*' char that is analogous to a read/write head.
  2. 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."
  3. The Ant can move forward, change orientation by 90 degrees (clockwise or counterclockwise), and be seated on either a black or a white square.
  4. 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.

Build/Run Instructions

  1. Clone or download.
  2. Open a terminal windows, navigate to this project's directory.
  3. 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>

Example

Here's the last printout of the state of the ant at the last turn:
./langtons_ant.out 15 12 25000

About

An implementation of Langton's Ant in C99

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published