Question: Time it took Matthew Coding: 2 hours and 2 3 minutes Debugging: 1 0 minutes Files to submit A zipfile named battleship.zip that contains A
Time it took Matthew
Coding: hours and minutes
Debugging: minutes
Files to submit
A zipfile named battleship.zip that contains
A file named main.py that when run plays a game of battleship
A python package named battleship that contains the rest of your solution
Reminder, a python package is simply a folder with a file named initpy in it
Problem
You will be implementing the game of BattleShip. The game starts with each player secretly placing their ships on their board. A ship can be placed either horizontally or vertically on their board. Once the players have finished placing their ships, they take turns guessing locations on their opponent's board to fire. Their opponent announces whether the shot hits or misses their ship and if it is the final hit on their ship, the fact that that shot destroyed their ship. You can play a version of BattleShip here and I recommend that you do so if you havent played the game before.
New Requirements
Your solution must have at least classes and these classes must be used MEANINGFULLY in your solution
Your solution must consist of at least python files aside from main.py and these files must be in a python package called battleship
Reminder, a python package is simply a folder with a file named initpy in it
General Requirement
There must be a docstring at the top of your program describing what it does
Each function in your program
Must have a doc string describing what it does
Must have its parameters and return value type hinted
Your program must have at least user defined functions
Restrictions
No global variables may be used
You may not have any code outside of functions aside from the call to your "main" function and import statements
Input
Path to Game Configuration: a file path to the game configuration file
This WILL always be valid
Firing Location: a pair of integers specifying a location on the opponent's board that has not already been fired at
This will NOT always be valid
Configuration File
A configuration file specifies
The size of the board
The number of ships to be placed on the board
The character used to represent each ship
The size of each ship
The content of a configuration file will always be valid.
Each configuration file is structured as
Number of rows on the board
Number of columns on the board
Number of ships to be placed
ShipCharacter ShipSize
ShipCharacter ShipSize
Here is what an example configuration file would look like for the traditional game of Battleship that is played on X board with a Carrier that is long, a Battleship that is long, a Destroyer that is long, a Submarine that is long, and a Patrol Boat that is long
C
B
D
S
P
Here are some sample configuration files: programmingpromptsFinalbattleshipsampleconfigurationfiles.zip
Setting Up The Game
First ask for the location for the configuration file and read it in
Then for each player in the game
Ask for their name
Then for each player in the game
Ask how they want to place their ships
Ships should be placed on the board in ASCII order from smallest to largest based on the character used to represent the ship.
To place each ship
Display the board to the player
Ask the player if they want to the place the ship horizontally or vertically
Any prefix of the word horizontally should be taken to mean horizontal and any prefix of the word vertically should be taken to mean vertically
Case does not matter for the prefix entered
As an example h ho hOR, HorI, all mean horizontally while V ve veR, vERt, all mean vertically
If the user enters in invalid input you should continue to ask them for valid input until valid input is entered
Ask the player for the starting coordinate for the ship
If the ship was placed horizontally this is the leftmost coordinate of the ship
If the ship was placed vertically this is the topmost coordinate of the ship
The ship's placement is valid if
It is on the board
The ship would not go off the end of the board
It does not overlap with any other ship that has already been placed
If the ship's placement is valid, place it there and move on to the next ship. If it is invalid, go back to step
Getting A User's Move
The user's firing location should be entered in the form row column
Example:
If an invalid location is chosen the user should be asked for a valid location until they enter one
A location is valid if
It is made of two integers
The location specified is on the board
The location specified has not already been fired at by this player
Correctly Zipping Your Submission
When you zip your submission it is important to zip the files requested and not the folder that contains the file. The following gif shows you what you should be doing
Examples
The example was quite long, so you will have to download it by clicking programmingpromptsFinalbattleshipsamplegameplay.
please help asap with a detailed solution, should match the format of the example output.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
