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 (“guess row”, “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 × 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 missed the ship are replaced by “X” in the board. You must use loop in your code. Please submit your code and console screenshots to bartleby. Code contain- ing syntax error will be graded zero.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
  1. 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 (“guess row”, “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 × 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 missed the ship are replaced by “X” in the board.

    • You must use loop in your code.

    • Please submit your code and console screenshots to bartleby. Code contain- ing syntax error will be graded zero.

Hints:

1

  1. Create a variable board and set it equal to an empty list and create a 5 × 5 grid initialized to all ‘O’s and store it in 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:")andinput("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 notinrange(5).Ifthatisthecase,printout"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.

Game start!
Game start!
Here is the 5x5 game board.
0 00 0 0
0 00 0 0
0 00 0 0
0 00 0 0
0 00 0 0
The target ship is located at: (4, 3)
Here is the 5x5 game board.
0 00 0 0
0 00 0 0
0 00 0 0
0 0 0 0 0
0 00 0 0
The target ship is located at: (2, 0)
Turn 1
Turn 1
Guess Row: 1
Guess Row: 2
Guess Col: 2
Guess Col: 0
You missed my battleship!
Here is the 5x5 game board.
0 00 0 0
Congratulations! You sank my battleship!
оохоо
0 0 0 0 0
0 00 0 0
0 00 0 0
Turn 2
Guess Row: 2
Guess Col: 3
You missed my battleship!
Here is the 5x5 game board.
0 00 0 0
0 0x ο
0 0 0 x o
0 00 0 0
0 00 0 0
Turn 3
Guess Row: 22
Guess Col: 2
Oops, that's not even in the ocean.
Here is the 5x5 game board.
0 00 0 0
оохоо
ооохо
0 00 0 0
0 0 0 0 0
Turn 4
Guess Row: 3
Guess Col: 1
You missed my battleship!
Game Over
Here is the 5x5 game board.
0 00 0 0
оохоо
0 0 0 X O
O x 0 0 0
ооооо
(b) An example of the player wins the game.
(a) An example of the player loses the game.
Figure 1: Question 1 examples.
Transcribed Image Text:Game start! Game start! Here is the 5x5 game board. 0 00 0 0 0 00 0 0 0 00 0 0 0 00 0 0 0 00 0 0 The target ship is located at: (4, 3) Here is the 5x5 game board. 0 00 0 0 0 00 0 0 0 00 0 0 0 0 0 0 0 0 00 0 0 The target ship is located at: (2, 0) Turn 1 Turn 1 Guess Row: 1 Guess Row: 2 Guess Col: 2 Guess Col: 0 You missed my battleship! Here is the 5x5 game board. 0 00 0 0 Congratulations! You sank my battleship! оохоо 0 0 0 0 0 0 00 0 0 0 00 0 0 Turn 2 Guess Row: 2 Guess Col: 3 You missed my battleship! Here is the 5x5 game board. 0 00 0 0 0 0x ο 0 0 0 x o 0 00 0 0 0 00 0 0 Turn 3 Guess Row: 22 Guess Col: 2 Oops, that's not even in the ocean. Here is the 5x5 game board. 0 00 0 0 оохоо ооохо 0 00 0 0 0 0 0 0 0 Turn 4 Guess Row: 3 Guess Col: 1 You missed my battleship! Game Over Here is the 5x5 game board. 0 00 0 0 оохоо 0 0 0 X O O x 0 0 0 ооооо (b) An example of the player wins the game. (a) An example of the player loses the game. Figure 1: Question 1 examples.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY