Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ program DESCRIPTION The game Battleship consists of a split board where each player places various objects (battle ships) along a 2-dimensional grid outside of

c++ program

DESCRIPTION

The game "Battleship" consists of a split board where each player places various objects (battle ships) along a 2-dimensional grid outside of the view of their opponent. Each player's turn consists of guessing a location on their opponent's board where a hidden ship might reside. If the player guesses a location coinciding with their opponent's ship, their ship is considered "hit" and their opponent confirms verbally by saying "hit," and the player continues to guess locations. If the player guesses a location that is empty on their opponent's board, their opponent confirms verbally by saying "miss," and the player's turn ends.

When an opponent's ship's locations have all been detected ("hit"), the object is considered "sunk," and is confirmed by the opponent by saying "hit and sunk" when the last location of a ship has been determined.

This programming project aims to develop the foundation of a larger Battleship game program by first establishing functions and routines that verify valid game boards for play.

The Ships

In Battleship, there are 5 objects involved in gameplay:

(A)ircraft carrier - length 5

(B)attleship - length 4

(C)ruiser - Length 3

(D)estroyer - Length 2

(S)ubmarine - Length 3

The Board

Boardplay involves a 2-dimensional grid, with lettered rows and numbered columns. Entities on the board are referenced by {number,letter} pairs, such as "A3"

The board consists of 10 rows (A-J) and 10 columns (1-10).

Game Initialization

The game begins with players placing each of the 5 ship objects in distinct positions on the game board, in strictly horizontal or strictly vertical orientation. Ships may not be placed at angles, or dangle off the valid 10x10 grid of the game board.

Your programming task

Your programming task for this project is to read in a board representing an initial game layout. Your program will need to:

Prompt the user for a file containing a valid board. If invalid, print an error message and prompt again.

Upon opening the file, your task is to verify:

All ships are placed on the board.

All ship locations are valid.

All ship lengths are valid.

The board dimensions in the file are valid.

A valid board file consists of comma-separated fields. Each field is either blank or contains a single lower-case letter from the set {a,b,c,d,s}, corresponding to the 5 ship types listed above.

An example of valid board content would be:

,,,,,c,,,a

b,b,b,b,,c,,,a

,,,,,c,,,a

,,,,s,,,,a

,,,,s,,,,a

,,,,s,,,,

,,,,,,,,

,,,,,,,,

,,d,d,,,,,

The following properties are imposed on the input file:

There are no spaces between commas or characters.

All letters are lowercase.

All letters are taken from the set {a,b,c,d,s}.

There are exactly ten rows

There are exactly 9 commas in each row.

Program Output

Your program must output only the following, corresponding to input files with the respective properties:

"Board is valid."

"Board is invalid: " and then:

"Board file could not be read."

"Board has too many rows."

"Board has too few rows."

"Board has too many columns in row ."

"Board has too few columns in row ."

"Board has invalid entries."

"Board has incorrect format on row at column starting at ."

where "" and "" represent their respective locations in the input file.

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 And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 2 Lncs 13427

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124251, 978-3031124259

More Books

Students also viewed these Databases questions

Question

How is a solar cell different from a heliostat?

Answered: 1 week ago

Question

=+derived from the assignment will balance the costs?

Answered: 1 week ago

Question

=+6 Who is the peer of the IA ?

Answered: 1 week ago