Yet Another Battleships Python Game (Would love your feedback!)

Heya! I made a 2-player python battleship game! It’s a bit brittle (I don’t do a lot of input validation), so if you try running it make sure you’re using the same capitalization as the requested input!

I struggled a lot with an effective way of using tests, so any comments or thoughts would be great!

How to Use

  • To play the game, run main.py
  • To run tests, run test.py
  • All Classes and their methods are in BattleshipClasses.py

Things to Improve

  • Input validation to make things a bit less brittle. For example, I don’t handle technically valid coordinates, but coordinates that are already occupied.
  • Change direction input to require only the first letter of the direction, instead of the whole word.
  • Refactor the logic around checking which directions the ship can go in, since I’m essentially running the same function 4 times with slightly different param

Repo: tacostorm/python-terminal-battleship: Battleship Game played on a terminal (github.com)

Blog Post: My Journey Learning Python: Battleships | by Jonathan Singh | Apr, 2023 | Medium

Hello! Thank you for your response regarding my project. I appreciate your input, and after careful consideration, I have some thoughts and suggestions to return the favor and offer my assistance to the best of my abilities.

Coordinate Entry: It can be confusing to enter the letter and number of each coordinate individually. One suggestion is to allow the player to enter the full coordinate instead. However, if you prefer to keep them separate, you can improve the experience by allowing the player to enter either the letter or number first. Additionally, you can highlight the available locations in the selected column or row to assist the player. Avoid requiring the player to retype the first character when entering the second and consider automatically displaying the first character before prompting the second. Listing all possible coordinates can also be helpful.

Additional Confirmation Input During Ship Placement: It might be beneficial to incorporate more confirmation options for the player. For example, they could select the order in which they want to place their ships and see the location of a ship before placing another. Although you’ve already implemented the use of cardinal directions, which is a good approach, you could enhance the process by prompting the player to confirm the selected location change the ship’s direction or even choose a completely new starting coordinate. To further improve the experience, you could represent “ghost” positions of each potential location, cycling through each option using a timer. Lastly, remember to make the input case insensitive for coordinates and directions.

Clearing the Screen and Automation: Providing an option for the player to manually clear the screen after a hit may not be necessary. Instead, you can automate this process using a timer module and require the player to focus on analyzing the board during their next turn. It can also create more excitement or tension by quickly indicating the outcome and giving the player time to process their decision’s emotions while observing the opponent’s next move.

Ship Representation and Board Clarity: The choice of ship representations might become confusing, particularly if they are placed near the top and match the same letters used for the grid. As the game progresses, the board could become cluttered with numerous symbols and letters. Additionally, since you are utilizing a “health” system, it would be helpful to inform the players about the number of remaining ships or hits required to win using a scoreboard.

Error Handling and Coordinate Entry: While I’m not sure if there were any issues with GitHub, main.py, or tests.py, I encountered several difficulties when entering coordinates for ship placement. Specifically, entering multiple characters, non-letter characters, or coordinates outside the grid’s range caused problems. Regardless, it became evident that the program lacks error handling. Currently, when an invalid coordinate is entered, the program gets stuck in a loop, and I must restart it. If something is broken in the code, I would suggest using “while” loops to help handle such cases and prompt the player to enter a valid coordinate with assistance.

I hope these clarifications and suggestions are helpful. If you have any further questions, please let me know. Thank you once again for your feedback!