Question: Make a program for a simple Battleship game (in C). Example execution: This is the skeleton code: #include #include #include struct Ship { char name[32];
Make a program for a simple Battleship game (in C).

Example execution:

This is the skeleton code:
#include
struct Ship { char name[32]; int left; int right; int hit; };
void initialize(struct Ship * ships) { strcpy(ships[0].name, "Carrier"); ships[0].left = 2; ships[0].right = 6; ships[0].hit = 0;
strcpy(ships[0].name, "Submarine"); ships[1].left = 15; ships[1].right = 17; ships[1].hit = 0;
strcpy(ships[0].name, "Destroyer"); ships[2].left = 8; ships[2].right = 9; ships[2].hit = 0; }
int isHit(struct Ship ship, int pos) { // Implement this function }
int isFinished(struct Ship * ships, int n) { // Implement this function }
int main() { struct Ship ships[3]; initialize(ships);
while (1) { int pos = 0; scanf("%d", & pos);
int hit = 0; for (int i = 0; i 0) { printf("hit "); if (isFinished(ships, 3)) { printf("All ships are sunk "); break; } } else { printf("miss "); } } return 0; }
// end of code
I'm not sure what should go in "//Implement this function".
Consider the game in 1 dimension. Complete a program by filling the skeleton code. The field is 20 length with 3 ships, Carrier(size: 5), Submarine(size: 3) and Destroyer(size: 2). Suppose these ships are located as follow: Carrier: from 2 to 6 Submarine: from 15 to 17 : Destroyer: from 8 to 9 $ ./a.out 4 hit 10 miss 15 hit 18 miss 9 hit All ships are sunk
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
