Skip to content

Solution#666

Open
AndrewGalynin wants to merge 2 commits intomate-academy:masterfrom
AndrewGalynin:develop
Open

Solution#666
AndrewGalynin wants to merge 2 commits intomate-academy:masterfrom
AndrewGalynin:develop

Conversation

@AndrewGalynin
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

app/main.py Outdated
Comment on lines +29 to +31
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))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants