Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The game of battleship is played on two 10 by 10 grids, one for each player. Each player of will lay 5 distinct ships on

The game of battleship is played on two 10 by 10 grids, one for each player. Each player of will lay 5 distinct ships on their grid. A battleship grid can be specified as 10 by 10 matrix such that position (x,y) corresponds to an empty square or a part of a ship. Upper case letters will denote a ship and each ship will have a defined length. C is a Carrier and has length 5 B is a Battleship and has length 4 K is a Cruiser and has length 3 S is a Submarine and has length 3 D is a Destroyer and has length 2 -: empty square The upper left, upper right, lower left and lower right corners of the board have co-ordinates (0,0), (0,9), (9,0), and (9,9), respectively, on the 2-D integer plane. For a list of rules and moves see the Wikipedia page. Write and document a c++ program battleship.cpp Your program should randomly place the ships for both you and the computer player. Your program should print out your board and a board that shows all the guesses that you made so far. You should ask the user to pick a position. Example of the starting state and after the first round. ABCDEFGHIJ ABCDEFGHIJ

0|-------KKK ----------

1|------SSS- ----------

2|---------- ----------

3|---------- ----------

4|-----CCCCC ----------

5|---------- ----------

6|---------- ----------

7|-D-------- ----------

8|-D--BBBB-- ----------

9|---------- ----------

Pick a Position 4 D You Hit They guessed 5 H They Miss

ABCDEFGHIJ ABCDEFGHIJ 0|-------KKK ---------- 1|------SSS- ---------- 2|---------- ---------- 3|---------- ---------- 4|-----CCCCC ---H------ 5|-------X-- ---------- 6|---------- ---------- 7|-D-------- ---------- 8|-D--BBBB-- ---------- 9|---------- ---------- A miss should place a X on the game board and a hit will place a H. You should give the user a choice at the start to run a random game and if the user enters a -1 as the x position the rest of the game should be random. If the user makes a bad guess the program should make a random guess for you. If the user or the computer guesses a position that they already guessed, they wasted their turn. The program AI should just make a random guess on its turn. You and the computer should take turns until you or the computer sink all their opponents ships. At that point your program should print out if you won or loss. Example of the end of game message They Hit They sunk your Carrier You Loss ABCDEFGHIJ ABCDEFGHIJ 0|XXXXXXXHHH XXXXXXHHXX 1|XXXXXXHHHX XX-X-XXXXX 2|XXXXXXXXX- X-XHXXBX-X 3|XXXXXXXXXX XXXHXXHXXX 4|XXXXXHHHHH XXXHXXHXX- 5|XXXXXX-XXX XXXCXXHXXX 6|XXXXXXXXXX -XXHXXXXXX 7|XHXXX-XXXX XXXHXXXXXS 8|XHXXHHHH-X XXXHXXXXXH 9|--XX-XXXXX XXXCXXXXXS

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

ISBN: 0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago