V22.0002 - ASSIGNMENT 6
DEMOLITION DERBY

DUE MONDAY. DEC 10TH, 9:30 AM
ABSOLUTELY NO LATE SUBMISSIONS WILL BE ACCEPTED.

Write a program that simulates a demolition derby of 4 cars, as follows.

Each car must be a structure composed of the following:

    name (array of 4 chars),

    operational status (int), and

    engine, wheel 1, wheel 2, wheel 3, and wheel 4 (these parts in one array of ints)

name is a three-letter string (the 4th char would be the string terminator);

operational status is one of two values- functional or not functional;

the engine is an integer with three possible values:
    GOOD, DAMAGED, BUSTED.

Each wheel (tire) is an integer with two possible values:
    GOOD, BUSTED (printed out as "Flat").

The initial value for operational status is FUNCTIONAL and the initial values for ALL the physical components are GOOD.  As long as a car's engine is not BUSTED, the car is FUNCTIONAL, even if its wheels are all flat.

The 4 cars drive around the field trying to hit each other until only one car is left in a functional state.  As long as a car is functioning, it can attempt hits on another.  In order to simulate this derby, use a random number to pick which car is hit and then use another random number to select which physical component is hit.  Each time a car’s engine is hit that part is downgraded one level until it is gone (i.e. if GOOD then it becomes DAMAGED; if DAMAGED it becomes BUSTED). If a wheel is hit it immediately goes from GOOD to BUSTED (flat).  If a component is BUSTED 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 a particular car’s engine is BUSTED then the car’s operational status is NOT FUNCTIONAL and it is stuck: it cannot hit other cars, but if it still has any good wheels, those can be hit.  If a chosen car has nothing to hit, you must try to target another car that is functional.

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

 

Hints:

1. You MUST use an array of structures to represent the four cars.

2. Within the car structure, you MUST use an array to represent its parts.

3. The car structure should resemble the following (use typedef):
typedef struct CAR
{
   char sName[ NAME_SIZE ] ;
   int iOperationalStatus ;
   /* zeroth element can be the sum of the status */
   /* for parts in rest of array */
   int iCarParts[ PARTS_COUNT + 1 ];
} TCar ;


4. It might be helpful to define constants which map a part to a particular index or subscript in the CarParts array:

#define PARTS_COUNT_INDEX 0
#define PART_ENGINE_INDEX 1
#define PART_WHEEL_ONE_INDEX 2
#define PART_WHEEL_TWO_INDEX 3
#define PART_WHEEL_THREE_INDEX 4
#define PART_WHEEL_FOUR_INDEX 5


5. Note that you can’t just decrement status right away for a possible hit on a target component, because if the component is already BUSTED you can’t hit it.

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

7. Use a getchar() by itself after each collision attempt to pause the derby so you can see what's going on then hit enter to continue.

SUBMISSION INSTRUCTIONS

You must submit an emailed copy of your .c file to the grader.

    DO NOT PRINT SAMPLE RUNS FOR SUBMISSION, JUST THE CODE.

Your email MUST have the following in the Subject line to ensure you are not penalized for missing assignment!

INTROC:YOUR LAST NAME:YOUR FIRST NAME:HW#6

As I have extended the homework to Monday, Dec. 10, the week before the final,

ABSOLUTELY NO LATE SUBMISSIONS WILL BE ACCEPTED.

(The solution will be posted the evening of Dec. 10th to facilitate your studying.)

The grader's email is: aev208@nyu.edu.  Please do NOT ask the grader questions.  Questions should be directed to the list if general, or to me if more specific.

Good luck!
 

Sample run


Name: Avi       Status: Functional
Engine: [Good]
Wheel 1: [Good] Wheel 2: [Good] Wheel 3: [Good] Wheel 4: [Good]

Name: Jos       Status: Functional
Engine: [Good]
Wheel 1: [Good] Wheel 2: [Good] Wheel 3: [Good] Wheel 4: [Good]

Name: Vin       Status: Functional
Engine: [Good]
Wheel 1: [Good] Wheel 2: [Good] Wheel 3: [Good] Wheel 4: [Good]

Name: Nic       Status: Functional
Engine: [Good]
Wheel 1: [Good] Wheel 2: [Good] Wheel 3: [Good] Wheel 4: [Good]

** Going for Car Avi's Wheel 1 **

Name: Avi       Status: Functional
Engine: [Good]
Wheel 1: [Flat] Wheel 2: [Good] Wheel 3: [Good] Wheel 4: [Good]
 

** Going for Car Jos's Wheel 2 **

Name: Jos       Status: Functional
Engine: [Good]
Wheel 1: [Good] Wheel 2: [Flat] Wheel 3: [Good] Wheel 4: [Good]
 

** Going for Car Jos's Engine **

Name: Jos       Status: Functional
Engine: [Damaged]
Wheel 1: [Good] Wheel 2: [Flat] Wheel 3: [Good] Wheel 4: [Good]
 

** Going for Car Jos's Wheel 1 **

Name: Jos       Status: Functional
Engine: [Damaged]
Wheel 1: [Flat] Wheel 2: [Flat] Wheel 3: [Good] Wheel 4: [Good]
 

** Going for Car Avi's Wheel 4 **

Name: Avi       Status: Functional
Engine: [Good]
Wheel 1: [Flat] Wheel 2: [Good] Wheel 3: [Good] Wheel 4: [Flat]
 

** Going for Car Vin's Wheel 4 **

Name: Vin       Status: Functional
Engine: [Good]
Wheel 1: [Good] Wheel 2: [Good] Wheel 3: [Good] Wheel 4: [Flat]
 

** Going for Car Nic's Wheel 1 **

Name: Nic       Status: Functional
Engine: [Good]
Wheel 1: [Flat] Wheel 2: [Good] Wheel 3: [Good] Wheel 4: [Good]
 

** Going for Car Avi's Engine **

Name: Avi       Status: Functional
Engine: [Damaged]
Wheel 1: [Flat] Wheel 2: [Good] Wheel 3: [Good] Wheel 4: [Flat]
 

** Going for Car Avi's Wheel 3 **

Name: Avi       Status: Functional
Engine: [Damaged]
Wheel 1: [Flat] Wheel 2: [Good] Wheel 3: [Flat] Wheel 4: [Flat]
 

** Going for Car Nic's Wheel 3 **

Name: Nic       Status: Functional
Engine: [Good]
Wheel 1: [Flat] Wheel 2: [Good] Wheel 3: [Flat] Wheel 4: [Good]
 

** Going for Car Avi's Engine **

Name: Avi       Status: Not Functional
Engine: [Busted]
Wheel 1: [Flat] Wheel 2: [Good] Wheel 3: [Flat] Wheel 4: [Flat]
 

** Going for Car Jos's Engine **

Name: Jos       Status: Not Functional
Engine: [Busted]
Wheel 1: [Flat] Wheel 2: [Flat] Wheel 3: [Good] Wheel 4: [Good]
 

** Going for Car Vin's Engine **

Name: Vin       Status: Functional
Engine: [Damaged]
Wheel 1: [Good] Wheel 2: [Good] Wheel 3: [Good] Wheel 4: [Flat]
 

** Going for Car Vin's Wheel 2 **

Name: Vin       Status: Functional
Engine: [Damaged]
Wheel 1: [Good] Wheel 2: [Flat] Wheel 3: [Good] Wheel 4: [Flat]
 

** Going for Car Nic's Engine **

Name: Nic       Status: Functional
Engine: [Damaged]
Wheel 1: [Flat] Wheel 2: [Good] Wheel 3: [Flat] Wheel 4: [Good]
 

** Going for Car Nic's Wheel 2 **

Name: Nic       Status: Functional
Engine: [Damaged]
Wheel 1: [Flat] Wheel 2: [Flat] Wheel 3: [Flat] Wheel 4: [Good]
 

** Going for Car Vin's Engine **

Name: Vin       Status: Not Functional
Engine: [Busted]
Wheel 1: [Good] Wheel 2: [Flat] Wheel 3: [Good] Wheel 4: [Flat]
 
 

Nic is victorious!

Name: Nic       Status: Functional
Engine: [Damaged]
Wheel 1: [Flat] Wheel 2: [Flat] Wheel 3: [Flat] Wheel 4: [Good]

Do you want to quit? Enter Y or N:
y
Press any key to continue