Welcome to Day 2 of your Battleship conquest. Yesterday, you built the battlefield and launched random sneak attacks. Today, you get to be the Admiral. That’s right — it’s your turn to decide where your ships go!
But with great power comes great responsibility:
🧠 You'll need to ensure your ship placements are smart, valid, and don't collide with any other vessels. You’re coding both the brains and the battle plan of the fleet.
✅ Prompt the player to place their own ships
✅ Accept and validate coordinate input like A4, J10, etc.
✅ Allow vertical or horizontal orientation
✅ Check that all ships:
Stay within board boundaries
Don’t overlap other ships
✅ Hide ships from the player (This is war, not show-and-tell.)
You must accept coordinates like:
A1, C5, J10
That means:
First character is a letter (A–J) → column
Remaining characters are the row (1–10)
✅ Create a function to Do Conversions:
Convert A1 → (0, 0)
Convert J10 → (9, 9)
Check if the input is in a valid format and on the board
🧠 HINT: Use .upper(), ord(), and isdigit() to help with validation.
Your player is about to call out a shot across the digital sea:
“FIRE TORPEDO AT C7!”
But your computer doesn’t understand "C7" — it needs real numbers like (2, 6) (row 6, column 2). So your job is to build a translator — a function that:
Takes A1 as input
Checks if it’s real and valid
Returns it as a tuple of numbers you can use on your 2D board
Start Simple with an input statement
coord = input("Enter a coordinate (like A5 or J10): ")
Use .strip() and .upper() to clean it up if needed
You need to split the input:
The first character is always the column (A to J)
The rest is the row number (1 to 10)
letter = coord[0]
number_part = coord[1:]
Treat the string like a list!
The first position of the string is [0]
We use a list slice to get the next character to the end! [1:]
Make sure:
The letter is between A and J
The number is between 1 and 10
Nothing weird was typed (like Z25, A-1, or 1A)
❗HINTS:
Use .isalpha() to check if the letter is a letter
Use .isdigit() to make sure the number part is actually a number
Use ord() to convert A to a number (did you know ord('A') is 65?)
Use Try/Except to make your life easy!
If what you want doesn't happen, raise an error and print an error message!
Your board is zero-based. That means:
A1 should become (0, 0)
C5 should become (4, 2)
J10 should become (9, 9)
📏 Think:
We can do this 1 of 2 ways...
FIRST WAY: BIG IF/ELSE STATEMENT
Why? It's really easy, and easy to read!
2nd Way: Use ord( )
ord() is a built-in Python function that turns a letter into its secret number code — also known as its ASCII value.
ord("A") → 65
ord("B") → 66
ord("C") → 67
EXAMPLE:
ord("B) - ord("A) = 1 which is the 2nd position on your board (B Column)
Let the player choose how many ships they want to place (between 1 and 10), then give them the power to manually deploy each one by entering a valid coordinate and choosing a direction.
No random drops this time, Captain. The player is now in charge of their own navy.
Your program needs to ask:
“🛠️ How many ships do you want to place (1–10)?”
🎯 What you need to do:
Use input() to ask the question
Turn the input into a number using int()
Make sure it's between 1 and 5
If it’s not valid, keep asking!
Each ship needs:
A coordinate (like "A5")
A valid location (on the board, and not taken)
Your program should keep asking until the player gives you a proper coordinate. One wrong move and they could be trying to place a ship on land, or worse — on top of another!
Your program needs to ask:
🛠️ “Where would you like to place ship #X? (e.g., A1 to J10)”
You must make sure
The spot must be on the board
It must be a valid coordinate
And it must be empty (See Below)
If all conditions are true you have to SAVE THE SHIP LOCATION IN A LIST OF PLACED SHIPS!!
Now that you’ve validated the coordinate, double-check that it isn’t already occupied. You don’t want two destroyers parked in the same square.
You can use:
if (row, col) in player_ships:
To SAVE the ship:
player_ships.append((row, col))