-
Notifications
You must be signed in to change notification settings - Fork 602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution #524
base: master
Are you sure you want to change the base?
Solution #524
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on implementing the Battleship game! 🎉 Your code meets the task requirements and constraints effectively. While there are some areas for improvement, such as adding validation for input coordinates and making the ship configuration more flexible, these are minor and do not impact the core functionality. Keep up the good work, and consider these enhancements for future projects to make your code even more robust and adaptable. Happy coding! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -1,34 +1,150 @@ | |||
class Deck: | |||
def __init__(self, row, column, is_alive=True): | |||
pass | |||
def __init__(self, row: int, column: int, is_alive: bool = True) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding validation for the row
and column
parameters to ensure they are within acceptable ranges (e.g., 0 to 9 for a 10x10 grid). This will prevent invalid deck positions.
start: tuple[int, int], | ||
end: tuple[int, int], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be beneficial to validate the start
and end
coordinates to ensure they form a valid ship (either horizontal or vertical, and within bounds).
# If it is, then it should check if this cell is the last alive | ||
# in the ship or not. | ||
pass | ||
def __init__(self, ships: list[tuple[tuple]]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor for Battleship
assumes a specific format for the ships
parameter. Consider adding validation to ensure the input matches the expected format.
|
||
def _validate_field(self) -> bool: | ||
ships = list(set(self.field.values())) | ||
if len(ships) != 10: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _validate_field
method assumes a fixed number of ships and decks. If you plan to support different configurations, consider making these values configurable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
No description provided.