# or this project, you will implement a game in which Anthony the Ant and his army of ants try to conquer other ant colonies. T

CSCE 1030 – Project 4 Due: 11:59 PM on Tuesday, November 24, 2020

1 of 10

PROGRAM DESCRIPTION: For this project, you will implement a game in which Anthony the Ant and his army of ants try to conquer other ant colonies. The colonies will be placed on a dynamically allocated 3-by-10 matrix (i.e., two-dimensional array) where each column will represent an ant colony ruled by a queen ant and her army. Anthony and his army of ants will then attempt to capture each queen in the neighboring colonies. If they can get to and capture the queen for the ant colony at location ‘J’ with at least 1 ant remaining, then Anthony and his army will be victorious! REQUIREMENTS: 1. In the main() function:

b. Declare a two-dimensional dynamic array of integers to represent the 3-by-10 matrix of ant colonies. Since the 2-D matrix array is not global, you will pass the 2-D matrix array to the needed functions as a pointer (actually, as a pointer to a pointer). You will also need to make sure to return the memory for the two- dimensional array back to the freestore when your program is done using it at the end. You may define a global constant for the number of columns of the 2-D array, but not the number of rows.

c. Initialize the 2-D matrix array using a function, passing at least the 2-D array as an argument that will be updated in the function. For each column, you will place a Queen Ant (designated by the ‘Q’ character) on a randomly generated row. Then, on the two remaining rows in that column, you will place a randomly generated number from 1 to 10, inclusively, that represents the number of ants guarding that colony outpost. Think of each column as an ant colony with one Queen and two outposts of ants supporting that colony. Be sure that you seed all randomly generated numbers in this program.

d. Randomly generate Anthony the Ant’s army of ants to be between 15 and 25, inclusively. This number will be increased and decreased when an individual attack on an ant colony is successful or not, respectively.

e. You will then display the initial 2-D matrix array with row and column labels 0 – 2 and A – J, respectively. The values of each ant colony (i.e., the columns) will initially be hidden using the “––” string for each entry. Ant colonies, except those outposts in that colony that have already been attacked, will remain hidden until Anthony the Ant has captured the Queen Ant for that column. This function will be called after processing each row selection (based on input from the player). Outposts that have been encountered will be identified by an ‘X’. This function will also be called with all values revealed at the end of the game should the player lose. See SAMPLE OUTPUT for detailed examples of what is expected.

CSCE 1030 – Project 4 Due: 11:59 PM on Tuesday, November 24, 2020

2 of 10

f. Now, it’s time to play the game. Using a loop of your choice, prompt for and read in the row position in the column that is being attacked by Anthony’s the Ant and his army of ants. If the row value is out of range (Note that the row value should be between 0 and 2, inclusively, as shown in the SAMPLE OUTPUT), you will display an error message and continue to re-prompt the user until a valid row value is entered. If a valid row is input, you will take the following action:

i. If the Queen Ant is found (i.e., row-column entry with the ‘Q’ character), you will add the value of any undiscovered outposts in that column to Anthony’s number of ants in his army and mark those outposts with the ‘*’ character, mark that row-column entry to ‘A’, signifying that Anthony the Ant has captured that colony, and advance Anthony the Ant and his army of ants on to the next ant colony (i.e., next column). You will also display a status message that the Queen Ant was captured and update the number of ants added to Anthony’s army of ants.

ii. If an outpost is newly discovered (i.e., the row-column entry will contain an integer from 1 to 10, inclusively), you will mark that row-column entry to ‘X’, signifying that a battle took place, and subtract the number of ants in the row-column entry from Anthony’s number of ants in his army of ants and then display a status message with the number of ants lost.

iii. If the outpost has already been encountered (i.e., there is already an ‘X’ in the row-column entry), you will display an error message and go back to the top of the loop to allow the player to read in the row position again with no ants won or lost.

Whether or not Anthony’s army found the ant colony, you will display the current state of the 2-D matrix array, revealing only the ant colonies (i.e., columns) that have been taken over by Anthony the Ant and his army of ants plus any discovered outposts in the current column. See SAMPLE OUTPUT for more details. The loop will terminate when either Anthony the Ant and his army of ants have taken over all of the ant colonies from ‘A’ through ‘J’ or the number of ants remaining in his army is 0 or less.

g. If Anthony the Ant and his army of ants has found all of the Queen Ants from colonies ‘A’ through ‘J’ with at least 1 ant remaining, display a congratulatory message along with the number of ants remaining in Anthony’s army; otherwise, display an appropriate message indicating that Anthony was not successful in his endeavor and call the function to display the 2D matrix array, revealing all of the columns.

2. You shall organize your program into three files: • euidHW4.h will hold the include directives for the necessary libraries, any

global constants, any enumerated data types, any type definitions, any

CSCE 1030 – Project 4 Due: 11:59 PM on Tuesday, November 24, 2020

3 of 10

structure definitions, and the list of function prototypes (i.e., function declarations).

• euidHW4main.cpp will hold the local include directive for the header file as well as the main() function for the program.

• euidHW4func.cpp will hold the local include directive for the header file as well as all function definitions (not including main(), of course) used in the program.

3. You may assume that all input by the player is of the correct data type, though perhaps out of range. Please pay attention to the SAMPLE OUTPUT for specific details about the flow and input/output of the program. You should contact your instructor if there is any question about what is being asked for.

4. Your code should be well documented in terms of comments. For example, good comments in general consist of a header (with your name, course section, date, and brief description), comments for each variable, and commented blocks of code.

5. Your program will be graded based largely on whether it works correctly on the CSE machines (e.g., cse01, cse02, …, cse06), so you should make sure that your program compiles and runs on a CSE machine.

6. You shall use techniques and concepts discussed in class – you are not to use global variables, goto statements, or other items specifically not recommended in this class.

DESIGN (ALGORITHM): On a piece of paper (or word processor), write down the algorithm, or sequence of steps, that you will use to solve the problem. You may think of this as a “recipe” for someone else to follow. Continue to refine your “recipe” until it is clear and deterministically solves the problem. Be sure to include the steps for prompting for input, performing calculations, and displaying output. You should attempt to solve the problem by hand first (using a calculator or perhaps a drawing of the scenario as needed) to work out what the answer should be for a few sets of inputs. This will also help in designing any loops that will process the two- dimensional array. Type these steps and calculations into a document (i.e., Word, text, or PDF) that will be submitted along with your source code. Note that if you do any work by hand, images (such as pictures) may be used, but they must be clear and easily readable. This document shall contain both the algorithm and any supporting hand-calculations you used in verifying your results. SAMPLE OUTPUT (input shown in bold): \$ ./a.out +———————————————-+ | Computer Science and Engineering | | CSCE 1030 – Computer Science I |

CSCE 1030 – Project 4 Due: 11:59 PM on Tuesday, November 24, 2020

4 of 10

| Student Name EUID euid@my.unt.edu | +———————————————-+ Let’s begin! Anthony’s army is 25 strong! A B C D E F G H I J +——————————-+ 0 | — — — — — — — — — — | 1 | — — — — — — — — — — | 2 | — — — — — — — — — — | +——————————-+ Enter row position in column A to strike: 4 Invalid row (4) entered. Try again… Enter row position in column A to strike: 0 Anthony’s army lost 5 and now has 20 ants remaining! A B C D E F G H I J +——————————-+ 0 | X — — — — — — — — — | 1 | — — — — — — — — — — | 2 | — — — — — — — — — — | +——————————-+ Enter row position in column A to strike: 1 Queen found! Anthony’s army captured 5 and is now 25 ants strong! A B C D E F G H I J +——————————-+ 0 | X — — — — — — — — — | 1 | A — — — — — — — — — | 2 | * — — — — — — — — — | +——————————-+ Enter row position in column B to strike: 2 Anthony’s army lost 6 and now has 19 ants remaining! A B C D E F G H I J +——————————-+ 0 | X — — — — — — — — — | 1 | A — — — — — — — — — | 2 | * X — — — — — — — — | +——————————-+ Enter row position in column B to strike: 1 Queen found! Anthony’s army captured 7 and is now 26 ants strong! A B C D E F G H I J +——————————-+ 0 | X * — — — — — — — — | 1 | A A — — — — — — — — | 2 | * X — — — — — — — — | +——————————-+ Enter row position in column C to strike: 0 Queen found! Anthony’s army captured 5 and is now 31 ants strong! A B C D E F G H I J +——————————-+ 0 | X * A — — — — — — — |

CSCE 1030 – Project 4 Due: 11:59 PM on Tuesday, November 24, 2020

5 of 10

1 | A A * — — — — — — — | 2 | * X * — — — — — — — | +——————————-+ Enter row position in column D to strike: 2 Queen found! Anthony’s army captured 6 and is now 37 ants strong! A B C D E F G H I J +——————————-+ 0 | X * A * — — — — — — | 1 | A A * * — — — — — — | 2 | * X * A — — — — — — | +——————————-+ Enter row position in column E to strike: 1 Anthony’s army lost 8 and now has 29 ants remaining! A B C D E F G H I J +——————————-+ 0 | X * A * — — — — — — | 1 | A A * * X — — — — — | 2 | * X * A — — — — — — | +——————————-+ Enter row position in column E to strike: 0 Anthony’s army lost 10 and now has 19 ants remaining! A B C D E F G H I J +——————————-+ 0 | X * A * X — — — — — | 1 | A A * * X — — — — — | 2 | * X * A — — — — — — | +——————————-+ Enter row position in column E to strike: 1 Ant colony already explored. Try again! Enter row position in column E to strike: 2 Queen found! Anthony’s army captured 0 and is now 19 ants strong! A B C D E F G H I J +——————————-+ 0 | X * A * X — — — — — | 1 | A A * * X — — — — — | 2 | * X * A A — — — — — | +——————————-+ Enter row position in column F to strike: 0 Queen found! Anthony’s army captured 9 and is now 28 ants strong! A B C D E F G H I J +——————————-+ 0 | X * A * X A — — — — | 1 | A A * * X * — — — — | 2 | * X * A A * — — — — | +——————————-+ Enter row position in column G to strike: 2 Anthony’s army lost 8 and now has 20 ants remaining! A B C D E F G H I J +——————————-+

CSCE 1030 – Project 4 Due: 11:59 PM on Tuesday, November 24, 2020

6 of 10

0 | X * A * X A — — — — | 1 | A A * * X * — — — — | 2 | * X * A A * X — — — | +——————————-+ Enter row position in column G to strike: 1 Queen found! Anthony’s army captured 4 and is now 24 ants strong! A B C D E F G H I J +——————————-+ 0 | X * A * X A * — — — | 1 | A A * * X * A — — — | 2 | * X * A A * X — — — | +——————————-+ Enter row position in column H to strike: 0 Anthony’s army lost 1 and now has 23 ants remaining! A B C D E F G H I J +——————————-+ 0 | X * A * X A * X — — | 1 | A A * * X * A — — — | 2 | * X * A A * X — — — | +——————————-+ Enter row position in column H to strike: 1 Queen found! Anthony’s army captured 5 and is now 28 ants strong! A B C D E F G H I J +——————————-+ 0 | X * A * X A * X — — | 1 | A A * * X * A A — — | 2 | * X * A A * X * — — | +——————————-+ Enter row position in column I to strike: 2 Anthony’s army lost 1 and now has 27 ants remaining! A B C D E F G H I J +——————————-+ 0 | X * A * X A * X — — | 1 | A A * * X * A A — — | 2 | * X * A A * X * X — | +——————————-+ Enter row position in column I to strike: 0 Anthony’s army lost 4 and now has 23 ants remaining! A B C D E F G H I J +——————————-+ 0 | X * A * X A * X X — | 1 | A A * * X * A A — — | 2 | * X * A A * X * X — | +——————————-+ Enter row position in column I to strike: 1 Queen found! Anthony’s army captured 0 and is now 23 ants strong! A B C D E F G H I J +——————————-+ 0 | X * A * X A * X X — |

CSCE 1030 – Project 4 Due: 11:59 PM on Tuesday, November 24, 2020

7 of 10

1 | A A * * X * A A A — | 2 | * X * A A * X * X — | +——————————-+ Enter row position in column J to strike: 0 Queen found! Anthony’s army captured 9 and is now 32 ants strong! A B C D E F G H I J +——————————-+ 0 | X * A * X A * X X A | 1 | A A * * X * A A A * | 2 | * X * A A * X * X * | +——————————-+ Congratulations! Anthony the Ant is victorious with an army of 32 remaining! Here is more sample input and output, this time for an unsuccessful attempt: \$ ./a.out +———————————————-+ | Computer Science and Engineering | | CSCE 1030 – Computer Science I | | Student Name EUID euid@my.unt.edu | +———————————————-+ Let’s begin! Anthony’s army is 17 strong! A B C D E F G H I J +——————————-+ 0 | — — — — — — — — — — | 1 | — — — — — — — — — — | 2 | — — — — — — — — — — | +——————————-+ Enter row position in column A to strike: 1 Anthony’s army lost 9 and now has 8 ants remaining! A B C D E F G H I J +——————————-+ 0 | — — — — — — — — — — | 1 | X — — — — — — — — — | 2 | — — — — — — — — — — | +——————————-+ Enter row position in column A to strike: 0 Queen found! Anthony’s army captured 2 and is now 10 ants strong! A B C D E F G H I J +——————————-+ 0 | A — — — — — — — — — | 1 | X — — — — — — — — — | 2 | * — — — — — — — — — | +——————————-+ Enter row position in column B to strike: 2 Queen found! Anthony’s army captured 15 and is now 25 ants strong! A B C D E F G H I J +——————————-+ 0 | A * — — — — — — — — |

CSCE 1030 – Project 4 Due: 11:59 PM on Tuesday, November 24, 2020

8 of 10

1 | X * — — — — — — — — | 2 | * A — — — — — — — — | +——————————-+ Enter row position in column C to strike: 1 Anthony’s army lost 6 and now has 19 ants remaining! A B C D E F G H I J +——————————-+ 0 | A * — — — — — — — — | 1 | X * X — — — — — — — | 2 | * A — — — — — — — — | +——————————-+ Enter row position in column C to strike: 0 Anthony’s army lost 8 and now has 11 ants remaining! A B C D E F G H I J +——————————-+ 0 | A * X — — — — — — — | 1 | X * X — — — — — — — | 2 | * A — — — — — — — — | +——————————-+ Enter row position in column C to strike: 2 Queen found! Anthony’s army captured 0 and is now 11 ants strong! A B C D E F G H I J +——————————-+ 0 | A * X — — — — — — — | 1 | X * X — — — — — — — | 2 | * A A — — — — — — — | +——————————-+ Enter row position in column D to strike: 0 Anthony’s army lost 2 and now has 9 ants remaining! A B C D E F G H I J +——————————-+ 0 | A * X X — — — — — — | 1 | X * X — — — — — — — | 2 | * A A — — — — — — — | +——————————-+ Enter row position in column D to strike: 2 Anthony’s army lost 8 and now has 1 ants remaining! A B C D E F G H I J +——————————-+ 0 | A * X X — — — — — — | 1 | X * X — — — — — — — | 2 | * A A X — — — — — — | +——————————-+ Enter row position in column D to strike: 1 Queen found! Anthony’s army captured 0 and is now 1 ants strong! A B C D E F G H I J +——————————-+ 0 | A * X X — — — — — — | 1 | X * X A — — — — — — |

CSCE 1030 – Project 4 Due: 11:59 PM on Tuesday, November 24, 2020

9 of 10

2 | * A A X — — — — — — | +——————————-+ Enter row position in column E to strike: 0 Anthony’s army lost 6 and now has -5 ants remaining! A B C D E F G H I J +——————————-+ 0 | A * X X X — — — — — | 1 | X * X A — — — — — — | 2 | * A A X — — — — — — | +——————————-+ Sorry, but Anthony’s army has been defeated! A B C D E F G H I J +——————————-+ 0 | A * X X X Q 7 Q 3 10 | 1 | X * X A 10 4 2 4 5 2 | 2 | * A A X Q 3 Q 6 Q Q | +——————————-+

TESTING: Test your program to check that it operates as desired with a variety of inputs. Then, compare the answers your code gives with the ones you get from hand calculations. Once you’re done writing your code and testing it, enjoy your game!!

SUBMISSION: Your program will be graded based largely upon whether it works correctly on the CSE machines, so you should make sure your program compiles and runs on the CSE machines. Your program will also be graded based upon your program style. This means that you should use comments (as directed), meaningful variable names, and a consistent indentation style as recommended in the textbook and in class. We will be using an electronic homework submission on Canvas to make sure that all students hand their programming projects on time. You will submit both (1) the program source code files and (2) the algorithm design document to the Project 4 dropbox on Canvas by the due date and time.