Battleship
Battleship
#include <vector>
#include <cstdlib>
#include <ctime>
int main() {
vector<vector<char>> board(BOARD_SIZE, vector<char>(BOARD_SIZE));
initializeBoard(board);
int attempts = 0;
while (true) {
cout << "Enter your guess (row column): ";
int row, col;
cin >> row >> col;
if (row < 0 || row >= BOARD_SIZE || col < 0 || col >= BOARD_SIZE) {
cout << "Invalid guess. Please enter row and column within the board
range." << endl;
continue;
}
attempts++;
displayBoard(board);
if (allShipsSunk) {
cout << "Congratulations! You sunk all the ships in " << attempts << "
attempts." << endl;
break;
}
}
return 0;
}