Develop and implement a game of Battleship that pits a human player against a computer opponent.


You may work in pairs on this project if you wish. Both people in each pair must email me to confirm that you are working together.

The program should display the following items:

  • The program name
  • The number of boats remaining for both players
  • The number of hits remaining for each of the human's boats. Small extra credit if you limit the display to just boats that are still afloat.
  • The human player's own board (the one on which the player places their boats)
  • The human player's opponent board (the one on which the player tracks their shots on the opponent)

The program should begin by initializing (of course) and then reading the positions of the boats. Use arrow keys to position a boat, press Enter to lock in the boat's position, then arrow keys again to choose a direction and finally Enter to finalize the boat's location. Do not allow boats to hang over the edge of the board, and do not allow boats to overlap other boats.

Once the boats are placed, place the computer boats randomly, obeying the two restrictions given in the previous paragraph.

Choose who starts at random.

For the user's turn, have them choose a cell by coordinates A-J, 0-9. Upper or lower case should be treated the same. Give the user the appropriate result:

  • Miss
  • Hit
  • Hit and sunk (you don't need to tell the user which boat was sunk)

The computer should choose randomly and automatically process its choice.

Do not let either player select the same cell twice.

End the game if the user chooses 'q' (or 'Q') at any time.

If either player's fleet is sunk, end the game with an appropriate message

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.