Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Battleship Matlab. These are the instructions : The Game Board: The board is of fixed, square size 9 x 9. Each square of the board

Battleship Matlab. These are the instructions : The Game Board: The board is of fixed, square size 9 x 9. Each square of the board is called a cell. Four (4) ships are placed at various locations on the board. Each ship occupies a number of adjacent cells on the board, arranged either horizontally or vertically. Each ship has a different size (number of cells), which is defined by its type: battleship = 4, submarine = 3, cruiser = 2, destroyer = 1. The ships cannot overlap (i.e., any given square/cell on the board can be occupied by at most one ship). To place the ships on the board, ask the user to input a starting location/cell for each ship. Using that starting location, and taking into consideration the length of the ship and the constraints of the board, your program should decide (at random) whether to place the ship horizontally or vertically, and place the ship accordingly on the board. Note: if your program evaluates the scenario and comes to the conclusion that the ship cannot be placed on the board at the given starting location, the program should ask the user for a new starting location. How the game is played: Your program should repeatedly generate random locations on the board (row, column), which will become the computers guesses. This is an automatic operation, no user input is allowed for the guesses. If the computer guesses a location occupied by a ship, the program should indicate a ship has been hit. Otherwise, the location should be marked as a miss. A ship is sunk when the computer fired (guessed) on ALL the cells occupied by that ship. Difficulty levels: At the beginning of the game, ask the user to choose between the following difficulty levels: Easy-as-Pie, Medium-Sauce and Watery-Death (you could implement a menu, but its not mandatory). To make the game more interesting, the computer will have a limited number of missiles to sink all of the ships, according to the difficulty level: A. Easy-as-Pie: the computer has 29 missiles available, and every 7 guesses should automatically be a hit. B. Medium-Sauce: the computer has 39 missiles available, and every 6 guesses should automatically be a hit. C. Watery-Death: the computer has 49 missiles available, and every 5 guesses should automatically be a hit. Until when? The game ends when: 1. The computer has run out of missiles. If the computer has run out of missiles, record a win for you (the user), but give the computer the choice to play again on the same board setup (do NOT re-initialize the board). 2. The computer has sunk all your ships. At the end of the game, when the last location of the last ship is discovered, record a win for the computer. A congratulatory message should include the number of moves the computer took to solve the board. P/S: can you please explain to me how to do this and i am thinking of making a figure for the game board and everytime the computer hits the user's battleship the figure will change colour to indicate that it has been hit.

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

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

What must a creditor do to become a secured party?

Answered: 1 week ago

Question

When should the last word in a title be capitalized?

Answered: 1 week ago