: You will build a simplified, one-player version of the classic board game Battleship! In this version of the game, there will be a single ship hidden in a random location on a 5 °ø 5 grid. The player will have 4 guesses at most to try to sink the ship. At each guess, the player names an attacking coordinate, that is (“guessrow”, “guess col”). The game ends in two conditions: (1) the player is out of guesses; (2) the player hits the ship. Examples are given in Figure 1. § The 5 X 5 board is shown every time the player inputs a guess entry. § The ship takes only one entry of the board, and it is randomly given before the player’s guesses. § The player inputs guessing entries in the Python console. § Entries that missed the ship are replaced by “X” on the board. § You must use a loop in your code. § Please submit your code and console screenshots to Blackboard. Code containing syntax error will be graded zero. Hints: 1. Create a variable board and set it equal to an empty list and create a 5 X 5 grid initialized to all ‘O’s and store it in the board. 2. Define two functions, random_row and random_col. Each takes the board as input. 3. Create new variables called guess_row and guess_col and set them to input("Guess Row:") and input("Guess Col:"), respectively. 4. If your guess misses the target, set the entry of the board at (guess_row, guess_col) to “X”. 5. The game should check if guess_row is not in range(5) or guess_col is not in range(5). If that is the case, print out "Oops, that’s not even in the ocean." 6. Thoroughly test your game. Make sure you try a variety of different guesses and look for any errors in the syntax or logic of your program. 7. Add a break under the win condition to end the loop after a win

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

: You will build a simplified, one-player version of the classic board game Battleship! In this version of the game, there will be a single ship hidden in a random location on a 5 °ø 5 grid. The player will have 4 guesses at most to try to sink the ship. At each guess, the player names an attacking coordinate, that is (“guessrow”, “guess col”). The game ends in two conditions: (1) the player is out of guesses; (2) the player hits the ship. Examples are given in Figure 1. § The 5 X 5 board is shown every time the player inputs a guess entry. § The ship takes only one entry of the board, and it is randomly given before the player’s guesses. § The player inputs guessing entries in the Python console. § Entries that missed the ship are replaced by “X” on the board. § You must use a loop in your code. § Please submit your code and console screenshots to Blackboard. Code containing syntax error will be graded zero. Hints: 1. Create a variable board and set it equal to an empty list and create a 5 X 5 grid initialized to all ‘O’s and store it in the board. 2. Define two functions, random_row and random_col. Each takes the board as input. 3. Create new variables called guess_row and guess_col and set them to input("Guess Row:") and input("Guess Col:"), respectively. 4. If your guess misses the target, set the entry of the board at (guess_row, guess_col) to “X”. 5. The game should check if guess_row is not in range(5) or guess_col is not in range(5). If that is the case, print out "Oops, that’s not even in the ocean." 6. Thoroughly test your game. Make sure you try a variety of different guesses and look for any errors in the syntax or logic of your program. 7. Add a break under the win condition to end the loop after a win

Expert Solution
Step 1

Algorithm:

The code implements the game as described in the prompt.

It starts by initializing an empty list board and then using a for loop to create a 5x5 grid initialized to all "O"s.

It defines two functions random_row and random_col that return a random row and column index respectively.

Then, it randomly selects the location of the ship on the board.

The main game logic is implemented in a for loop that goes through up to 4 turns.

In each turn, the player inputs their guess for the row and column, and the game checks if the guess matches the ship's location.

If the guess matches, the player wins and the game ends.

If the guess misses, the game replaces the missed location with an "X" and continues to the next turn.

If the player exhausts all their turns, the game ends with a "Game Over" message.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education