Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great work on the overall structure and for implementing the extra tasks! Your code is well-organized and clear.
However, changes are needed due to a critical logic issue in the Ship class constructor in app/main.py. The current nested loop creates a rectangular area of decks for a ship instead of a single straight line. For a ship to be valid in Battleship, it must be either horizontal or vertical.
To resolve this, please modify the Ship.__init__ method. You should first add a check to ensure that either the row or column coordinates of the start and end points are the same. Then, you can use a single loop to iterate along the other axis to create the decks in a straight line. Once this is fixed, your solution will be in excellent shape!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
app/main.py
Outdated
| for r_var in range(min(r1, r2), max(r1, r2) + 1): | ||
| for c_var in range(min(c1, c2), max(c1, c2) + 1): | ||
| self.decks.append(Deck(r_var, c_var)) |
There was a problem hiding this comment.
This nested loop logic for creating ship decks is incorrect. For a ship defined by its endpoints, such as ((0, 0), (1, 1)), this code would create a 2x2 square of decks rather than a straight line. Battleship ships must be either horizontal or vertical. You should add a check to ensure that either the row or column coordinates of the start and end points are the same, and then iterate only along the other axis to create the decks.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on this iteration! You've successfully addressed all the critical issues from the previous review, especially the logic for creating ships. The implementation now correctly ensures they are always horizontal or vertical. Your solution meets all the task requirements, including the extra validation and printing tasks. The code is clean and well-structured, so I am happy to approve your work. Great job!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.