Game Objectives
In the Battleship game, your goal is to sink all five ships of the opponent (Carrier, Battleship, Cruiser, Submarine, Destroyer), while protecting your own ship from being sunk by the opponent.
Game Process
Initial Layout:
Each player (including players and AI) has 5 ships, namely Carrier (5 grids), Battleship (4 grids), Cruiser (3 grids), Submarine (3 grids), Destroyer (2 grids).
Players need to place their ships horizontally or vertically in a 10x10 grid. Each ship cannot overlap and must be placed completely within the grid.
Initially, both sides can only see their own grids and ship layouts, but not the opponent's.
Attack Phase:
The game takes turns, and each round the current player chooses the attack position (by entering coordinates, such as A1, B4, etc.).
After the player attacks, the system will feedback the attack result:
"Miss" means no ship was hit.
"Hit" means that a ship of the opponent was hit, but the ship was not completely sunk.
If the attack results in all parts of a ship being hit, the system will display that the ship has been sunk and update the scores of both parties.
Recording scores:
Whenever a ship is completely sunk, the player who sank the ship gets 1 point.
At the end of the game, the player with the higher score wins; if the scores are the same, it is a tie.
End of the game:
When all ships of one side are sunk, the game ends and the other side wins.
If both sides end their rounds at the same time and neither side sinks all ships of the other side, the game continues until the winner is determined.
Special rules
AI opponents: In this game, AI will play as your opponent. AI will try to optimize its defense strategy based on the player's attack behavior and try to sink the player's ship.
Repeated attacks: Players cannot attack the same location in the same round, but can re-attack in subsequent rounds.
Invalid input: If the input coordinate format is incorrect (such as coordinates that do not start with letters, coordinates that exceed the grid range, etc.), the system will prompt invalid input and require re-entry.
Instructions
Enter coordinates: Use the keyboard to enter the coordinates you want to attack (such as A1, C5, etc.), and press Enter to confirm.
View results: The system will display the results of your attack (Miss, Hit, or Ship Sunk) and update the grids and scores of both parties.
Continue the game: If your attack does not end the game, it is the AI's turn to attack, and the game continues until the winner is determined.
Please follow the instructions above and enjoy the fun of the game!