Final Project Using Arrays and Structs/Classes

Final Project
Using Arrays and Structs/Classes
Grading: Unlike the assignment you will not demonstrate the final project to a TA. You must submit your program and all supporting files. The TAs will only grade the last items submitted so please do not submit them one at a time. Your reflections are very important as that is the only way the TA can find answers to their questions.
Implementing Langton’s Ant
You will design, implement, and test a program that implements a simulation of Langton’s Ant. For a brief explanation consider Wikipedia: https://en.wikipedia.org/wiki/Langton%27s_ant. Note that is can be considered a cellular automaton. This means that you have an array or matrix of cells. Each turn or step the value of each cell may change based upon a simple rule. For the Ant there are two simple rules.
You must give the user an opportunity to change the variables in your program: number of rows, number of columns, the ant’s starting position, the number of iterations or rounds, starting direction, the number of rows and columns in the grid, and the configuration of the starting grid or board.
You will create a program to rad this information from the command line: # of iterations, starting X, starting Y, direction, and a filename. For example:
ant –n 10000 –x 500 –y 500 –d up -f testfile4
You must use the indicators wo the user can enter the information in any order:
ant –d up –n 10000 –y 500 -f testfile4 –x 500
The file will contain the grid configuration information. The first row will have 2 integers separated by at least one space character. The first number is the number of rows and the second is the number of columns. After that you will provide the starting configuration, i.e. which cells will be “white” and which will be “dark. You must have the number of rows and columns specified on the first line. You will use a 0 to indicate white, and a 1 to indicated dark.
You will need to convert each character as you read it in; 0 becomes a blank space character, and 1 becomes an asterisk, “8”. As you fill in the array remember to also add a “#” for the position of the ant.
Incremental development! You should do all of this AFTER your create the ant! For testing create a driver program that gets the information by reading it from the keyboard. After it is all debugged, save a copy! Then work on reading the file, or the CLA. When it’s working and debugged, save it. Then implement the other.
WARNING – Use the Internet to ONLY research how the ‘game’ is structured and designed. Design and write your own program. Do NOT use any code that you did not write for yourself. That would be cheating. Much of what is available is more complicated or advanced than what is required here. It is harder to use it than to write your own.

The rules are:
1. In a white square, turn right 90o and change the square to black.
2. In a black square, turn left 90o and change the square to white.
NOTE – Think this through carefully before you start coding.
You can use a blank character for a white space. You can use the number sign (“*”) for black. And for the Ant? “#”. Left ? Right? Those are relative directions! How are you going to keep track of the direction the Ant is facing? How will you “remember” what color the current cell occupied by the Ant is or was? You will be displaying the ant symbol so you need to save the color of the cell. You will create an Ant struct or class to help organize, hold, and manipulate this information.
You will create your design document BEFORE you start coding. The TA will grade, in part, on how well your implementation matched your design. Remember, in your reflections document you can explain how you had to change the design because your first idea, just didn’t work. Just explain what you learned. Simply stated, program design is identifying the problem to be solved, identify the inputs, specify the desired output, and then develop the algorithm(s) to convert the input into the output.
For testing:
Your program will prompt the user to enter the number of rows and columns for the 2D array. The array will not change size while the simulation is running. You only need to create a 2D array of the specified size.
You should also prompt the user for the number of steps. Notice in the Wikipedia article they mention several hundred and 10000. Use functional decomposition to develop functions to validate the input. What parameters and criteria do these functions need? You should start by asking the user for the starting location of the Ant. You should add the option for the user to have a random starting location.
After you have this implemented and debugged add the CLA and file input as specified above.
Note: You should start saving utility functions for future programs you write.
Note: For testing purposes always start the Ant at the same location. Then try different locations.
Your program should display each step.
By the due date at midnight, you will submit your program, and the reflections document, which will discuss how well your design worked, and the results of the testing.
WARNING – Submitting any code you did not write is a violation of the university’s academic dishonesty policy. Keep in mind, if you can find it using Google, the TA’s can too.
GRADING –
Programming style and documentation (10%) The ant follows the rules correctly (10%) Input validation function(s) (5%)
Create the Ant struct or class (5%)
Displays each step correctly, including running for the correct number of steps (5%) The display allows the user to see the change(s) in the starting confiugration(s) (5%) Implement the command line argument to read data into your program (25%)
o –n reads in number of iterations or rounds
o –y reads in the ant’s starting x coordinate (should be less than or equal to limit in the first line) o –y reads in the ant’s starting y coordinate (should be less than or equal to limit in the first line) o –d reads in the initial facing of the ant
o –f reads in the file name that holds the configuration
Implement creating the array from the information in the file (10%) o Size of array created from the data in the file
o The grid filled correctly from the data in the file
Perform all file operations correctly (5%) o File opened and closed
• • • • • • •

• •
IMPORTANT POINT – Keep in mind this is a programming assignment. You are not writing a program to share with others for their enjoyment. Too often students forget this and the attempt to make it entertaining which also makes it more difficult. And has little to do with the grading. You are graded on developing the design, writing the code, and testing your program. You will use text-based output. It may not be pretty, but it will demonstrate your design and implementation works. If you have other programming experience and want to use something else check with your grader before doing it.
HINTS:
1. Use the grading breakdown to plan your program. Use incremental development. Get one part working. Test it. Save a copy and continue working on the next step in your plan. This ensures you will have something to submit!
2. Be very careful about borrowing any code, or ideas you see in someone else’s code. This is a problem used for researching mathematical topics; proofs?, “a two dimensional Turing machine”, “Cohen–Kong theorem”, proofs! Much more complicated than required for this project. As always, any code submitted must be yours and yours alone.
Reflections document to include the design description, test plan, test results, and comments about how you resolved problems during the assignment (20%)