I am doing a battleship game for my project. I am still trying to make a better algorithm.. This is what I have so far. Here is a code that will pick random coordinates for the computers ship, then draws the board and show where the ship is located...
Assuming that I had ten ships (1 ship per index) How will I generate ten coordinates and make the program remember that this index has already a ship so it won't generate the same coordinates??
int getcoord ();
void main()
{
int x,y ;
srand((int)time(NULL));
clrscr ();
x=rand()%10;
y=rand()%9;
getcoord (x,y);
getch ();
}
getcoord (x,y) {
int array[10][10]={0},i,j;
array[x][y]=1;
for (j=0;j<10;j++) {
for ( i=0;i<10;i++) {
printf (" %d", array[j][i]);
}
printf ("\n\n");
}
}