Problem F
Battleship
In this exercise, you will program a computer game: Battleship!
For the sake of simplicity, we will limit ourselves to a
single-player mode with one board. At the start of the game,
The grid’s columns are numbered from
![\includegraphics[width=0.33\textwidth ]{battleship-grid}](/problems/battleship2/file/statement/en/img-0001.png)
The ships are placed either horizontally or vertically on the grid. The ships sizes are as follows:
-
The carrier is the biggest and occupies
tiles. -
The battleship occupies
tiles. -
The destroyer and submarine, both occupy
tiles. -
Finally, the patrol boat that occupies
tiles.
Input
The input starts with the program prompting the user for the
location of each of the five ships with
“Location and orientation of your {ship
type}: ”.
The second part of the input then consists of
In the tests,
In the samples below, the first five lines contain the
placement of the ships. The remaining
Output
The output should start with
-
“Miss.” if the attack missed.
-
“Hit, {ship type}.” if the attack hit a ship.
-
“You have sunk my {ship type}.” if all of the ship’s tiles have now been attacked.
Then finally when all the ships have been sunk, the program should print “The entire fleet has been sunk.” and exit.
Sample Input 1 | Sample Output 1 |
---|---|
C3 vertical A5 horizontal A2 vertical F6 horizontal D7 vertical D5 D3 C3 B3 E3 F3 G3 D1 C2 B2 A2 A5 A6 A7 A8 D7 E8 E7 F6 F7 F8 |
Location and orientation of your carrier: Location and orientation of your battleship: Location and orientation of your destroyer: Location and orientation of your submarine: Location and orientation of your patrol boat: Miss. Hit, carrier. Hit, carrier. Miss. Hit, carrier. Hit, carrier. You have sunk my carrier. Miss. Hit, destroyer. Hit, destroyer. You have sunk my destroyer. Hit, battleship. Hit, battleship. Hit, battleship. You have sunk my battleship. Hit, patrol boat. Miss. You have sunk my patrol boat. Hit, submarine. Hit, submarine. You have sunk my submarine. The entire fleet has been sunk. |