In: Computer Science
Langton Ant Program:
This assignment will apply Langton's ant a two-dimensional universal turning machine on a 2 dimensional X by X grid where each grid cell is of the color white or black and the ant can be described as one of eight states ie. cell color and orientation.
Create a X by X square grid of “Cell”s that are either black or white. Begin with the “ant” in the center of the grid ( X must be a odd number/integer). Start the ant in a “up” orientation in the center of the board. Perform N steps where each step has to follow some simple rules:
You are to program the `Cell` class according to the following:
Cell color:
The `Cell` class will store the cell's color as a private member variable named `color` of type `CellColor` where `CellColor` is an enumeration data type defined as:
“enum CellColor {white, black};”
Constructor :
The `Cell` class will be constructed using the default constructor i.e. will not accept any arguments. The constructor will set `color` to `white` upon construction.
Cell Color Mutator
The `Cell` class will contain a public member function called `change_color` to change the `color` member. I.e. if `color` is set to `white`, calling `change_color( )` will change the `color` to `black`. The member function `change_color` will return type `void` and will accept no input parameters.
Cell Color Accessors
The `Cell` class will contain two "getter" functions to access `color`.
1.) Must be named `get_color`, will return type `CellColor`, must return the value of `color`, and must accept no input parameters. `get_color must return the value of `Cell`'s `color` member.
The template we will be using to declare the “Cell” class
Cell.hpp:
#include
// Declare an enumeration data type to store the Cell's color
enum CellColor {white, black};
// Declare the Cell Class
class Cell {
public:
// Declare default constructor to initialize color to white
// Declare member function getter for the color (get_color). Returns CellColor
// Declare a member to flip the color (change_color)
// Declare a member to print the string for this color.
// white = "0", black = "1"
private:
// Declare the color of this cell (color) as type CellColor
};
#endif
Cell.cpp:
#include "Cell.hpp"
(This is only part 1. of this homework assignment so I only need the code for this part I described and not the grid and ant movement yet)
. Langton’s ant
Langton's ant is a two-dimensional Turing machine with a very
simple set of rules
but complicated emergent behavior. It was invented by Chris Langton
in 1986 and
runs on a square lattice of black and white cells. The universality
of Langton's ant
was proven in 2000. The idea has been generalized in several
different ways, such as
turmites which add more colors and more states.
Squares on a plane are colored variously either black or white. We
arbitrarily
identify one square as the "ant". The ant can travel in any of the
four cardinal
directions at each step it takes. The ant moves according to the
rules below:
• At a white square, turn 90° right, flip the color of the square,
move forward
one unit
• At a black square, turn 90° left, flip the color of the square,
move forward one
unit
Langton's ant can also be described as a cellular automaton, where
the grid is
colored black or white, the "ant" square has one of eight different
colors assigned to
encode the combination of black/white state and the current
direction of motion of
the ant.
These simple rules lead to complex behavior.
• Simplicity: During the first few hundred moves it creates very
simple patterns
which are often symmetric.
• Chaos: After a few hundred moves, a big, irregular pattern of
black and white
squares appears. The ant traces a pseudo-random path until around
10,000
steps.
• Emergent order: Finally the ant starts building a recurrent
"highway" pattern
of 104 steps that repeat indefinitely. All finite initial
configurations tested
eventually converge to the same repetitive pattern, suggesting that
the
"highway" is an attractor of Langton's ant, but no one has been
able to prove
that this is true for all such initial configurations. It is only
known that the
ant's trajectory is always unbounded regardless of the initial
configuration –