Question: (C) Battleship game in two dimensions. Example: Original code (one dimension game); #include #include #include struct Ship { char name[32]; int left; int right; int
(C) Battleship game in two dimensions.

Example:
![#include #include #include struct Ship { char name[32]; int left; int right;](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f501c4cb1bf_80466f501c4699e3.jpg)
Original code (one dimension game);
#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) { if(pos>=ship.left && pos
int isFinished(struct Ship * ships, int n) { int cnt=0; for(int i=0;i 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
