#include using namespace std; const int rows=10; const int columns=10; int computer_board1[rows][columns]; int computer_board2[rows][columns]; int player_board[rows][columns]; int x,y; void setboard()...


#include
using namespace std;
const int rows=10;
const int columns=10;
int computer_board1[rows][columns];
int computer_board2[rows][columns];
int player_board[rows][columns];
int x,y;
void setboard()
{
for(int i=0;i<>
{
for(int j=0;j<>
{
computer_board1[i][j]=0;
player_board[i][j]=0;
}
}
}
void display_computer_board1()
{
cout<"computer's><>
cout<" 0="" 1="" 2="" 3="" 4="" 5="" 6="" 7="" 8="" 9=""><>
for(int i=0;i<>
{
for(int j=0;j<>
{
if(j==0)
{
cout<>
cout<><">


}
cout<>
}
cout<>
}
void display_player_board()
{
cout<"your><>
cout<" 0="" 1="" 2="" 3="" 4="" 5="" 6="" 7="" 8="" 9=""><>
for(int i=0;i<>
{
for(int j=0;j<>
{
if(j==0)
{
cout<>
cout<><">


}




cout<>
}


}
void place_player_ships()
{
for(int i=1;i<>
{
cout<"horizontal>
cin>>x;
cout<"vertical>
cin>>y;
if(x>=10||y>=10)
{
cout<"invalid component=""><>
return ;
}
player_board[x][y]=1;
display_computer_board1();
display_player_board();
}
}
void display_computer_board2()
{
cout<"computer's><>
cout<" 0="" 1="" 2="" 3="" 4="" 5="" 6="" 7="" 8="" 9=""><>
for(int i=0;i<>
{
for(int j=0;j<>
{
if(j==0)
{
cout<>
cout<><">


}
cout<>
}
}
void place_computer_ships()
{
for(int i=1;i<>
{
x=rand()%rows;
y=rand()%columns;
computer_board1[x][y]=1;
}
}
void guess_computer_ships()
{
int a,b;
cout<"horizontal>
cin>>a;
cout<"vertical>
cin>>b;
place_computer_ships();
if(computer_board1[a][b]==1)
{
cout<"you><>
computer_board2[a][b]=1;
display_computer_board2();
display_player_board();
}
if(computer_board1[a][b]!=1)
{
cout<"you><>
computer_board2[a][b]=2;
display_computer_board2();
display_player_board();
}
}
void guess_player_ships()
{
int a,b;
int turn=0;
if(turn%2==0)
{
for(turn;turn<>
{
a=rand()%rows;
b=rand()%columns;
}
if(player_board[a][b]==1)
{
cout<"computer><>
player_board[a][b]=2;
display_computer_board2();
display_player_board();


}


else if(player_board[a][b]!=1)
{
cout<"computer><>
display_computer_board2();
display_player_board();
}
}


}
bool check_winner()
{
int s=0;
for(int i=0;i<>
{
for(int j=0;j<>
{
if(computer_board2[i][j]==1)
{
s++;
if(s==15)
{
cout<"you won="" the=""><>
return true;
}
}
}
}
}


int main()
{
int gametype;
cout<><>
cout<"are you=""><>
setboard();
display_computer_board1();
cout<><>
cout<"there are="" 15="" ships="" in="" this="" game:=""><>
//cout<"1.carrier 5\n2.battleship="" 4\n3.cruiser="" 3\n4.submarine="">
cout<"you have="" to="" sink="" all="" of="" the=""><>
cout<"computer's board="" will="" show="" 1="" when="" you="" hit="" and="" 2="" when="" you=""><>
cout<"your board="" will="" show="" 1="" where="" you="" place="" your="" ship="" and="" 2="" when="" computer="" hits="" your=""><>
display_computer_board1();
display_player_board();
cout<>
cout<"now you="" have="" to="" place="" your="" 15="" ships="" anywhere="" on="" your="" board="" by="" adding="" horizontal="" and="" vertical=""><>
place_player_ships();
cout<"you ships="" are="" placed=""><>
cout<"let's start="" the=""><>
cout<"add horizontal="" and="" vertical="" components="" to="" guess="" the="" ships="" on="" computer's=""><>
int turn=1;
for(int i=1;i<>
{
if(turn%2!=0)
{
cout<"your><>
guess_computer_ships();


}
if(turn%2==0)


{
cout<"computer's><>
guess_player_ships();


}
turn++;
}




}


Can anyone tell me how to decide the winner and break the loop.


Thank you.

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here