Skip to content

feat: created battleship#658

Open
AdekWhat1 wants to merge 3 commits intomate-academy:masterfrom
AdekWhat1:develop
Open

feat: created battleship#658
AdekWhat1 wants to merge 3 commits intomate-academy:masterfrom
AdekWhat1:develop

Conversation

@AdekWhat1
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 job on the overall structure and the core logic for the fire method! However, I'm requesting a few changes before this can be approved. There are two critical issues that are blocking the solution: first, the required print_field and _validate_field methods are missing from the Battleship class. Second, there is a bug in the Ship constructor that prevents horizontal ships from being created correctly; a ship is horizontal when self.start_y == self.end_y. Please also address the unused attributes noted in the comments, as this violates a checklist item [CHECKLIST ITEM #4]. Once these issues are resolved, your solution will be ready for approval!


✨ 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 +20 to +21
self.start_x, self.start_y = start
self.end_x, self.end_y = end

Choose a reason for hiding this comment

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

These attributes (start_x, start_y, end_x, end_y) are only used within the __init__ method to create the decks. They are not used anywhere else in the Ship class. This violates checklist item #4: 'Remove unused attributes.' Consider using local variables within __init__ instead of instance attributes.

app/main.py Outdated
# Change the `is_alive` status of the deck
# And update the `is_drowned` value if it's needed
pass
elif self.start_y < self.end_y:

Choose a reason for hiding this comment

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

This condition for identifying a horizontal ship is incorrect. A ship is horizontal if its start and end y-coordinates are the same. This condition should check for equality (self.start_y == self.end_y) to correctly handle horizontal ships.

app/main.py Outdated
Comment on lines +36 to +37
else:
return

Choose a reason for hiding this comment

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

This block violates checklist item #2. An __init__ method should not fail silently by returning. This creates an object in an invalid state (a ship with no decks). Instead, you should raise an exception (e.g., ValueError) for invalid ship coordinates like diagonal ones.

self.is_drowned = True


class Battleship:

Choose a reason for hiding this comment

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

The Battleship class is missing the print_field and _validate_field methods, which are required by the 'Extra tasks' section in the task description. Please implement these methods to add the required printing and validation functionality.

self,
ships: list
) -> None:
self.ships = []

Choose a reason for hiding this comment

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

The self.ships attribute is populated in the __init__ method but is never used afterward. This violates checklist item #4: 'Remove unused attributes.' A local variable within __init__ would be more appropriate for building the ships before populating self.field.

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 implementing the core game logic and fixing the previous bugs! Your solution is very close, but it requires a few changes before it can be approved.

Here are the main points to address:

  1. The _validate_field method is correctly implemented, but it's not being called from the Battleship.__init__ method. Please add a call to self._validate_field() at the end of the constructor to ensure the game board is always valid.
  2. Your validation logic is missing a check for the total number of ships. The rules require exactly 10 ships in total, so please add this check to _validate_field.
  3. In the Ship class, several attributes (start_x, start_y, etc.) are only used inside the __init__ method. These should be converted to local variables to comply with the project checklist [CHECKLIST ITEM #4].

Once these issues are resolved, your solution will be ready!


✨ 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 +20 to +21
self.start_x, self.start_y = start
self.end_x, self.end_y = end

Choose a reason for hiding this comment

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

These attributes (start_x, start_y, end_x, end_y) are only used within the __init__ method to create the decks. They are not used by any other methods in the Ship class. This violates checklist item #4: 'Remove unused attributes.' Consider making them local variables within this method.

Comment on lines +64 to +77
def __init__(
self,
ships: list
) -> None:
self.ships = []
self.field = {}
for start, end in ships:
new_ship = Ship(start, end)
self.ships.append(new_ship)

for ship in self.ships:
for deck in ship.decks:
coord = (deck.row, deck.column)
self.field[coord] = ship

Choose a reason for hiding this comment

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

The _validate_field method is correctly implemented, but it's not being called from within this __init__ method. According to the requirements, you need to call self._validate_field() at the end of this method, after the field has been fully initialized.

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 submission! You've done a great job fixing the issues from the previous review, especially with calling the validation method from the constructor and refactoring the Ship class.

I am approving this solution as an educational override to help you progress, but there is one important validation check still missing. Your _validate_field method doesn't verify that the total number of ships is exactly 10. While you correctly check the counts for each ship size, an invalid field with more than 10 ships could still pass validation.

You can easily fix this by adding a check for the length of the ships list. Keep up the great work, you're very close to a perfect solution!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment on lines +99 to +100
if (lengths.count(4) != 1 or lengths.count(3) != 2
or lengths.count(2) != 3 or lengths.count(1) != 4):

Choose a reason for hiding this comment

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

This validation is still not quite complete. According to the requirements, you need to check that the total number of ships is exactly 10. The current logic only validates the counts of specific ship sizes, which means an invalid field with more than 10 ships could still pass validation.

Please add a check for the total number of ships, for example by checking the length of the lengths list.

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