So far you’ve built the board, deployed your fleet, and given players the power to place their own ships. Now it’s time for action — no more drifting in calm waters. Welcome to the part of the game where the player gets to fire their first shot. 🎯💥
But wait — you can’t hit anything if there’s nothing to shoot at. That’s why in this round, the computer will secretly place 5 single-tile enemy ships, hidden deep beneath the waves of your board.
Your mission? Sink them before they sink you.
💻 Randomly place 5 hidden computer ships on the board
🎯 Let the player enter a coordinate like A3 or J7
🧠 Check if the coordinate hits a ship or not
🧾 Update the board:
If a ship is hit ➝ place "S"
If it’s a miss ➝ place "-"
There are 5 ships
Each one is 1 square big
They must be placed in random locations
No overlapping ships allowed!
Use the random module → random.randint(0, 9)
Use a loop to try placing a new ship
Check that the spot isn’t already taken
Ask for input:
guess = input("🎯 Enter a location to fire (e.g., A3): ")
✅ Use the same coordinate validation and conversion function you wrote in Part I and II to:
Clean the input
Convert to (row, col)
Reject bad formats
If the input is invalid? Tell them and let them try again!
🚢 If It’s a Hit:
if (row, col) in computer_ships:
print("🔥 DIRECT HIT! You found a ship!")
board[row][col] = "S"
🌊 If It’s a Miss:
else:
print("💨 Splash! Just open water...")
board[row][col] = "-"
Set max_turns = 7
Track how many times the user guesses
Track how many ships they've hit (hit_count)
End the loop when:
The user reaches 7 guesses OR the user hits 3 ships
Give more turns for each hit
You’ve survived your first real engagement. Whether you emerged a legend or limped back to port, you now understand the tools of the tactical coding trade.
Next? You’ll be writing game loops, adding scoreboards, and making the full game run from start to finish.
The sea won’t know what hit it.