Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program based on a version of brute force pattern matching for playing a game like Battleship on the computer. The rules of the
Write a program based on a version of brute force pattern matching for playing a game like Battleship on the computer. The rules of the game are as follows:
There are two opponents in the game in this case, a human player and the computer
The game is played on two identical boards times tables of cells on which each opponent places his or her ships, not visible to the opponent.
Each player has three ships, each of which occupies a certain number of cells on the board: a destroyer a twobytwo square of cells a submarine three diagonal cells either from left to right or right to left and a cruiser three consecutive cells either horizontal or vertical
No two ships are over each other.
The game is played by the opponents taking turns "shooting" at each other's ships.
The result of every shot is displayed as either a hit or a miss. In case of a hit, the player gets to go again and keeps playing until they miss.
The goal is to sink all the opponent's ships before the opponent succeeds in doing it first.
To sink a ship, all cells occupied by the ship must be hit.
Your program should start by allowing the player to set all their ships see the game rules and the program will set its own ships randomly following the rules.
The player is asked to indicate a position on the table and if it hits, it will say hit and ask to select another position; if it misses, it will say miss and the program will take a turn and display a random cell, following the rules of the game.
Note: The players should not be allowed to select a repeated cell or one that is not in the table. If they do an appropriate message will appear and they will be asked to select another cell.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started