Question

In: Computer Science

Langton Ant Program: This assignment will apply Langton's ant a two-dimensional universal turning machine on a...

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:

  1. If the ant is on a white tile turn 90° clockwise, then change the color of the tile & move forward one unit
  2. If the ant is on a black tile turn 90° counterclockwise, change the color of the tile and then move forward one unit.

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.

  1. Must be named `get_color_string`, must return type `std::string`, and must accept no input. `get_color_string` must return "1" if `color` is `black` and must return "0" if `color` is `white`.

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)

Solutions

Expert Solution

. 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 –


Related Solutions

Langton Ant Program: This assignment will apply Langton's ant a two-dimensional universal turning machine on a...
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...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
Write a program that creates a two-dimensional array initialized with test data. The program should have...
Write a program that creates a two-dimensional array initialized with test data. The program should have the following functions: Hi There I really appreciate your help with this project. ▪ getTotal . This function should accept a two-dimensional array as its argument and return the total of all the values in the array. ▪ getAverage . This function should accept a two-dimensional array as its argument and return the average of all the values in the array. ▪ getRowTotal ....
For this assignment, you will apply what you learned in analyzing a simple Java™ program by...
For this assignment, you will apply what you learned in analyzing a simple Java™ program by writing your own Java™ program. The Java™ program you write should do the following: Display a prompt on the console asking the user to type in his or her first name Construct the greeting string "Hello, nameEntered!" Display the constructed greeting on the console Complete this assignment by doing the following: Download and unzip the linked zip file. Add comments to the code by...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
Write a program in Java to: Read a file containing ones and zeros into a two-dimensional...
Write a program in Java to: Read a file containing ones and zeros into a two-dimensional int array. Your program must (1) read the name of the file from the command-line arguments, (2) open the file, (3) check that each line has the same number of characters and (4) check that the only characters in a line are ones and zeros. If there is no such command-line argument or no such file, or if any of the checks fail, your...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT