Question
THIS IS FOR C PROGRAMMING: I am working on the folliwng program that plays the game of battleship. I have been able to create the
THIS IS FOR C PROGRAMMING: I am working on the folliwng program that plays the game of battleship. I have been able to create the playerBoard and computerBoard to place my ships, and now need to create the salvos Board for both Player A and Player B.
How do I go about doing that?
I have included the code I have now and what I am trying to do. Thank you so much.
This is what I'm trying to do:
This is my Code:
#include
#include
void initializeBoard(int **playerBoard, int **compBoard)
{
const int rows = 10,
cols = 10;
for (int i = 0; i
{
playerBoard[i] = (int *)malloc(sizeof(int)*cols);
compBoard[i] = (int *)malloc(sizeof(int)*cols);
for (int j = 0; j
{
playerBoard[i][j] = '-';
compBoard[i][j] = '-';
}
}
}
void printBoard()
{
const int rows = 10,
cols = 10;
int **playerBoard = (int **)malloc(sizeof(int *)*rows);
int **compBoard = (int **)malloc(sizeof(int *)*rows);
initializeBoard(playerBoard, compBoard);
{
printf("SHIPS ");
printf(" | ");
for (char c = 'A'; c
{
printf("%c ", c);
printf("| ");
}
printf(" ");
for (int i = 0; i
{
printf("%2d ", i + 1);
printf("|");
for (int j = 0; j
{
printf(" %c ", playerBoard[i][j]);
if (i == 10)
puts(""); //only triggers if i=10, 10x10grid
printf("|");
}
printf(" ");
}
}
puts(" ");
printf(" | ");
for (char c = 'A'; c
{
printf("%c ", c);
printf("| ");
}
printf(" ");
for (int i = 0; i
{
printf("%2d ", i + 1);
printf("|");
for (int j = 0; j
{
printf(" %c ", compBoard[i][j]) + "|";
if (i == 10)
puts("");
printf("|");
}
printf(" ");
}
}
//Each Player's game board should be initialized
/o ships have been placed on either board
int main(void)
{
printBoard();
return 0;
}
SHIPS: SALVOS: SHIPS A|BICIDIEIFIGIHIIJ IAIBICIDIEIFIGIHIIJ IAIBICIDIEIFIGIHIIJStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started