V22.0002 - ASSIGNMENT 6

No late Homework 6 submissions will be accepted!

 

Write a program that simulates a contest to the finish among 4 robots.

 

Each robot is a structure composed of the following:name, operational status, head, torso, arms, legs.†† Name is a three-letter string; operation status is one of two values- functional or not functional; each of the remaining physical components (head, torso, etc.) is an integer with three possible values: UNSCATHED, DAMAGED, GONE.The initial value for operational status is FUNCTIONAL and the initial values for the physical components are UNSCATHED.

 

The 4 robots spar with each other until only one robot is left in a functional state.†† As long as a robot is functioning, it can attempt hits on another.In order to simulate this sparring, use a random number to pick which robot is hit and then use another random number to select which physical component is hit.Each time a robotís part is hit that part is downgraded one leveluntil it is gone (i.e. if UNSCATHED then it becomes DAMAGED; if DAMAGED it becomes GONE).If a component is GONE and the random number indicates it is the target, it canít be hit and therefore cannot take more damage; in that case, you must select another part to hit (if thatís GONE you must try another and so on).If all of a particular robotís physical components are GONE then the robotís operational status is NOT FUNCTIONAL and it is out of the bout.As with parts, if a chosen robot is not functional, you must try to target another robot that is functional.

 

You are to print to the screen the starting status of each robot, a play-by-play account of the sparring which includes a message indicating which robot and part is being targeted and the status of that robot after the potential hit.When only one is left functional, print a victory message with that robotís name and then print the status of its components.

 

Hints:

 

1.     You must use an array of structures to represent the four robots.

2.     Within the robot structure, you must use an array to represent its components.

3.     The robot structure should resemble the following:

 

typedef struct

{

char sName[ NAME_SIZE ] ;

†† int iOperationalStatus ;

/* zeroth element is the sum of the status*/††

/* for parts in rest of array (see hint 4)*/

int iRobotParts[ PARTS_COUNT + 1 ];

} TRobot ;

 

It would be helpful to define constants which map a part to a particular index or subscript in the RobotParts array:

 

#define PARTS_COUNT_INDEX 0

#define PART_HEAD_INDEX 1

#define PART_TORSO_INDEX 2

#define PART_ARMS_INDEX 3

#define PART_LEGS_INDEX 4

 

4.     You should write a function to allow the user to input the names of the 4 robots.

5.     One way to keep track of operational status is to maintain a count of values for each component.For example, UNSCATHED is worth 2, GONE is worth 0... when your count is 0 ALL components are GONE and the operational status should be set to NOT FUNCTIONAL.Note that you canít just decrement right away for a possible hit on a target component, because if the component is already GONE you canít hit it.

6.     You have to use srand and rand (see notes and craps example on web site).

 

 

 

Sample run

Please enter the name for robot 1: Ake
Please enter the name for robot 2: Bek
Please enter the name for robot 3: Cel
Please enter the name for robot 4: Dak

 

 

 

Name: Ake†††††† Status: Functional

Head: [Unscathed] Torso: [Unscathed] Arms: [Unscathed] Legs: [Unscathed]

 

Name: Bek†††††† Status: Functional

Head: [Unscathed] Torso: [Unscathed] Arms: [Unscathed] Legs: [Unscathed]

 

Name: Cel†††††† Status: Functional

Head: [Unscathed] Torso: [Unscathed] Arms: [Unscathed] Legs: [Unscathed]

 

Name: Dak†††††† Status: Functional

Head: [Unscathed] Torso: [Unscathed] Arms: [Unscathed] Legs: [Unscathed]

 

** Targeting Dak's Arms **

 

Name: Dak†††††† Status: Functional

Head: [Unscathed] Torso: [Unscathed] Arms: [Damaged] Legs: [Unscathed]

 

 

** Targeting Ake's Legs **

 

Name: Ake†††††† Status: Functional

Head: [Unscathed] Torso: [Unscathed] Arms: [Unscathed] Legs: [Damaged]

 

 

** Targeting Dak's Arms **

 

Name: Dak†††††† Status: Functional

Head: [Unscathed] Torso: [Unscathed] Arms: [Gone] Legs: [Unscathed]

 

 

[ ... some rounds in between... ]

 

** Targeting Bek's Legs **

 

Name: Bek†††††† Status: Functional

Head: [Gone] Torso: [Unscathed] Arms: [Unscathed] Legs: [Damaged]

 

 

** Targeting Ake's Legs **

 

Name: Ake†††††† Status: Functional

Head: [Damaged] Torso: [Damaged] Arms: [Gone] Legs: [Gone]

 

 

** Targeting Ake's Torso **

 

Name: Ake†††††† Status: Functional

Head: [Damaged] Torso: [Gone] Arms: [Gone] Legs: [Gone]

 

[ ...note Ake going to Not Functional status... ]

 

 

** Targeting Ake's Head **

 

Name: Ake†††††† Status: Not Functional

Head: [Gone] Torso: [Gone] Arms: [Gone] Legs: [Gone]

 

 

[ ... some morerounds in between... ]

 

 

** Targeting Bek's Torso **

 

Name: Bek†††††† Status: Not Functional

Head: [Gone] Torso: [Gone] Arms: [Gone] Legs: [Gone]

 

 

 

Cel is victorious!

 

Name: Cel†††††† Status: Functional

Head: [Gone] Torso: [Damaged] Arms: [Damaged] Legs: [Damaged]

 

Do you want to quit? Enter Y or N: