Question
Objectives Assignment #8 Introduction to C Programming COP 3223 MUST USE FUNCTIONS 1. To learn how to design and implement functions for program development 2.
Objectives
Assignment #8 Introduction to C Programming COP 3223
MUST USE FUNCTIONS
1. To learn how to design and implement functions for program development 2. To reinforce how to use pass by value and pass by reference variables 3. To learn how to use structures to store information and solve problems
Introduction: Ninja Academy
Ninjas are awesome! Your friend has not stopped talking about how cool ninjas and how they would like to become a ninja. To amuse your friend, you have decided to create a series of programs about ninjas.
Problem: Ninja Quest (ninjaquest.c)
Congratulations! You have graduated from the Ninja Academy with the highest honors! You have been placed in charge of a team of six ninjas. Your task is to help your school expand into a new area. This area is contested by other ninjas from rival schools. You will need to defeat them in competitions and shows of ability to claim the area.
Program Details
You will have a team of six ninjas: each ninja has a performance score and an ability score. When their performance score drops to zero, they will no longer be able to compete and show off their ninja skills. Their ability score indicates how impressive their skills are to intimidate and outshine the competition.
Your program will simulate several days of competition for an area. An area is split into a 3x3 grid of competition spaces. Throughout the day, you will need to choose which section of the area to send each of your ninja subordinates. You can only send out one at a time, but you can send each ninja to any square.
As each ninja is deployed, resolve any competitions that occur. If your ninja is the only one in the section, you can claim the section! If there are other ninjas, you must compete for that section. Competitions are determine by the performance and ability scores of the ninjas. These scores are randomly generated values from 1 to 30, inclusive.
Consider the following example:
There are 3 opponent ninjas in the upper right corner. Suppose you send one of your ninjas to this section.
1 opponent ninja Not claimed | 2 opponent ninja Not claimed | 3 opponent ninja Not claimed |
0 opponent ninja Not claimed | 4 opponent ninja Not claimed | 1 opponent ninja Not claimed |
1 opponent ninja Not claimed | 1 opponent ninja Not claimed | 1 opponent ninja Not claimed |
Your ninja: Performance: 13 Ability: 25
Opponent ninjas:
Your ninja competes with the first opponent. Your ninja goes first and his performance impacts the opponents ability to respond:
Round 1: Your ninja: Performance: 13 Ability: 25 Opponent: Performance: 7 Ability: 2
Note how the opponents ability score was reduced from 15 to 2 by your ninjas performance score of 13. Correspondingly, the opponent will show off his ninja skills and impact your ability to follow up:
Round 2: Your ninja: Performance: 13 Ability: 18 Opponent: Performance: 7 Ability: 2
On your opponents turn, your ninjas ability score is reduced from 25 to 18 by your opponents performance score of 7. Next, its your turn again!
In the third round your ninja reduces the opponents ability below zero. A ninja with an ability score of less than or equal to zero can no longer compete. Only ninjas with positive ability scores can compete. Then, your ninja will go up against the second defender in the section:
Round 1: Your ninja: Performance: 13 Ability: 18 Opponent: Performance: 17 Ability: 7
You ninja goes first! The second opponent starts with an ability of 20, but since you go first, you reduce this to 7 with your performance score.
Round 2: Your ninja: Performance: 13 Ability: 1 Opponent: Performance: 17 Ability: 7
This opponent has a high performance score and reduces your ninjas ability to 1. But your ninja beats them in round three by reducing their ability from 7 to -6. There is one more ninja to defeat:
Round 1: Your ninja: Performance: 13 Ability: 1 Opponent: Performance: 12 Ability: 23
Performance: 7 Ability: 15 | Performance: 17 Ability: 20 | Performance: 12 Ability: 30 |
Your ninja is defeated in round 2!
Round 2: Your ninja: Performance: 13 Ability: -11 Opponent: Performance: 12 Ability: 23
You will have to retreat for now, but since you have defeated two ninjas the number of opponents will go down:
1 opponent ninja Not claimed | 2 opponent ninja Not claimed | 1 opponent ninja Not claimed |
0 opponent ninja Not claimed | 4 opponent ninja Not claimed | 1 opponent ninja Not claimed |
1 opponent ninja Not claimed | 1 opponent ninja Not claimed | 1 opponent ninja Not claimed |
You can then send a second ninja later in the day:
Your ninja: Performance: 27 Ability: 20
There is now only one opponent to defeat:
Opponent: Performance: 15 Ability: 25
Note that these numbers may be different later in the day, because they are randomly generated when you enter the section.
Round 1: Your ninja: Performance: 27 Ability: 20 Opponent: Performance: 15 Ability: -2
Since all of the opponent ninjas have been defeated you can claim this space:
1 opponent ninja Not claimed | 2 opponent ninja Not claimed | 0 opponent ninja CLAIMED |
0 opponent ninja Not claimed | 4 opponent ninja Not claimed | 1 opponent ninja Not claimed |
1 opponent ninja Not claimed | 1 opponent ninja Not claimed | 1 opponent ninja Not claimed |
Because you are a superior commander, when you claim a section it stays yours. If you send a ninja to a location with zero opponents, you can claim it automatically. Your program should run until either all the sections are yours or until all of your ninjas have run out of performance points.
At the end of each day, your ninjas with a positive ability score can restore their ability score to its original value.
Implementation Restrictions
You must use the following structures to store information:
struct ninja { int ID;
int performance;
int ability; };
struct map { int playerOwns;
int numOpponents; };
It is not sufficient to simply have the structures in your program, you must use them store information and process operations for the alliance. You may use type definition if you prefer.
Though function prototypes will not be provided, it is expected that you follow good programming design and create several functions with well-specified tasks related to the solution of this problem. Make sure to pay very careful attention to parameter passing.
Hints
Create a 3x3 array for the map. The value playerOwns represents a flag to indicate whether or not that section has been claimed for the player. These should be initialized to zero or false. The number of opponents for the map will come from an input file. See below for specifications.
Create a 1x6 array for your ninjas. Remember to randomly generate the values for each ninja as random integers between 1 and 30. Keep an original copy and a separate copy that can be updated throughout the day. Give the ninjas identification numbers like 1-6 to track their scores.
Input Specification
The input file will contain 9 integers representing the number of opponent ninjas in each square. Remember to prompt the user for the name of the input file and open the file that they specify.
The user will input directions in a 1-based, left to right fashion:
111213 212223 313233
Output Specification
Start each day with Good Morning!
Then, for each ninja with a positive ability score, show the user the currently claimed sections of the map. --- ---
--- (example initial map)
-CC --C --- (player has claimed sections 1 2, 1 3, and 2 3)
Then prompt the user with their ID number for where to send them: Where would you like to send ninja
Immediately resolve this by sending the ninja to the corresponding section on the map. Tell the user how many ninjas their ninja is facing:
There are X opponent ninjas in this section! Print out the values for both the player and the opponent so it can be tracked:
Your ninja: Performance: A Ability: C
Opponent: Performance: B Ability: D
And update these values as the two ninjas compete, until one ability is reduced to zero or below. When the players ninja defeats an opponent, print:
Your ninja defeated an opponent! When the players ninja is defeated, print:
Ninja
If the user defeats all opposing ninjas or if the user sends a ninja to an unoccupied space that has not been claimed, print:
You claim this section! If the user sends a ninja to an unoccupied space that has already been claimed, print:
You already own this section! If the player claims all of the sections, print:
You have claimed all of the sections. You Win!
If all of the players ninjas are defeated, print: Your ninjas are all exhausted. Try again next time.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started