Question: Objectives To learn how to design and implement functions for program development To reinforce how to use pass by value and pass by reference variables

Objectives

To learn how to design and implement functions for program development

To reinforce how to use pass by value and pass by reference variables

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: Artifact Retrieval (ninjafinal.c)

To prove you are ready to graduate from the Ninja Academy, there is one more task for you to perform. All of your lessons, exercises, exams, and errands have led up to this final task: leading a team of your classmates on a mission that will utilize their unparalleled stealth and observation skills.

Your instructors have set up a nearby temple with a number of traps and relics. Your job is to retrieve each of these relics in under two hours. Traps will delay you and if you are detected by one of your instructors, you will be forced to wait until the next hour begins to resume your search.

Program Details

You have a team of four ninjas. Each ninja has an individual stealth score that helps them avoid attention from the instructors and an observation score that helps them find a relic at their location. To find a relic, a ninja will need to be sent to its location, find it, and return it without being caught.

Your program will simulate the six hours available for this exercise. The temple has been split into a 3x3 grid of locations. The team leader will track information about what level of observation is needed to locate the relic in each space on their grid. For each hour, the team leader will need to choose which section of the area to send each of their team members. As each ninja is deployed, your program should update the grid for the team leader. Once a relic is retrieved from a section, there is no need to revisit it.

List of Relics:

The founders KATANA

An ornate SCROLL

A JADE statue

An ancient MASK

Traps will be marked with a 0.

If nothing is stored in that location, it will be marked with a 5.

Consider the following example:

4 Search

4 MASK

1 Search

1 KATANA

3 Search

3 JADE

1 Search

2 SCROLL

2 Search

0 TRAP

3 Search

5 NOTHING

1 Search

5 NOTHING

5 Search

0 TRAP

1 Search

5 NOTHING

There is a MASK in the upper left corner that requires a ninja with at least a skill of 4 in searching to locate.

The team of ninjas might look like this:

0

1

2

3

Search: 3

Stealth: 1

Search:2

Stealth: 5

Search: 5

Stealth: 1

Search: 1

Stealth: 3

Ninja 2 has a high search skill and will be able to find anything hidden in the temple. However, they have a low stealth skill, which means they have a high chance of getting caught.

Your program should prompt the user for instructions for each team member. Ask which section of the temple they are being sent to. Before they start searching, check to see if they will be caught by an instructor. Create a pseudorandom integer between 0 and the ninjas stealth skill, inclusive. If they get a 0, they have been caught and must sit out this hour.

If they are not detected, they may search the space. If their search skill meets or exceeds the search value of the space they will be successful. If there is an item there, they will bring it back to the team leader. If nothing is there, nothing will happen. If a trap is there, the ninja falls for the trap and PERMANENTLY loses one point of their stealth skill.

Your program should run until either all the relics have been retrieved, for a total of four relics, or until 2 hours have elapsed. At that point in time, the test is over and the ninja students must leave the temple. Before closing the program, tell the user if they were successful in retrieving all the relics or not.

Implementation Restrictions

You must leave comments explaining each major portion of your code.

You must use the following structures to store information:

struct ninja {

int search;

int stealth;

};

struct map {

int searchval;

int item;

int found;

};

It is not sufficient to simply have the structures in your program, you must use them store information and process operations for the program. 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.

You may not use global variables.

Hints

Create a 3x3 array for the map. The value searchval indicates the required search value a ninja needs to search the space. When a ninja has a search skill that is the same or higher than this searchval they can obtain the item. The item is identified by an integer: 0 is a trap, 1 is the katana, 2 is the scroll, 3 is a jade statue, 4 is a mask, and 5 is a trap. Remember that traps will modify the ninjas stealth score by reducing it by 1. Both of these values will be provided by an input file. See below for specifications. The third integer is a flag to indicate whether or not the item in the space has been found. Initialize these to 0.

Create a 1x4 array for your ninjas. These values will also be provided by an input file. Consider making an initialization function to process this file and initialize your data structures for the program.

Input Specification

The input file will contain 9 pairs of integers representing the search and item values (in that order) for each square. This will be followed by 4 pairs of integers representing the search and stealth values (in that order) for the ninjas. Here is the sample file that matches the above example:

4 4 1 1 3 3

1 2 2 0 3 5

1 5 5 0 1 5

3 1

2 5

5 1

1 3

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:

1 1 1 2 1 3

2 1 2 2 2 3

3 1 3 2 3 3

Output Specification

At the start of each hour, let the team leader know how many hours are remaining - You have X hours left to collect the relics. and show them the status of their ninjas:

Ninja Search Stealth

1 X1 Y1

2 X2 Y2

3 X3 Y3

4 X4 Y4

Then, for each ninja, show the captain the current state of the map:

4s 1s 3s

1s 2s 3s

1s 5s 1s

(example initial map; use s to indicate it has not been searched yet)

RELIC 1s 3s

1s TRAP 3s

1s 5s NOTHING

(ninjas have searched sections 1 1, 2 2, and 3 3; these spaces do not need to be revisited)

Then prompt the user with their ninja team member number for where to send them:

Where would you like to send ninja X?

Immediately resolve this by sending the ninja to the corresponding section on the map. FIRST, check to see if they will be caught. If they are caught output the following statements. This ninja will not be able to search this hour.

Your ninja has been caught!

If they are able to search, compare their search skill to the search value required for this space. If their skill is not high enough, output the following statement.

Your ninja was not able to search this room.

If they complete a search, update the map with what they found and print one of the following messages:

You have found a . Hint: Replace with the appropriate relic name.

Your ninja fell into a trap!

There is nothing in this room!

If the player claims all of the relics in all of the sections, print:

You have retrieved all of the relics!

If the player must retreat due to time, print:

You are forced to leave the temple. You retrieved X relics for the Ninja Academy!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!